Skip to content

Commit f03ac50

Browse files
authored
Fix looping issues in imports (#436)
* Fix looping issues in imports * wrong method * same
1 parent e0f6a14 commit f03ac50

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/Commands/ImportCollections.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,19 @@ private function usingDefaultRepositories(Closure $callback): void
7878

7979
private function importCollections(): void
8080
{
81-
$this->withProgressBar(CollectionFacade::all(), function ($collection) {
82-
if ($this->shouldImportCollections()) {
81+
$importCollections = $this->shouldImportCollections();
82+
$importCollectionTrees = $this->shouldImportCollectionTrees();
83+
84+
$this->withProgressBar(CollectionFacade::all(), function ($collection) use ($importCollections, $importCollectionTrees) {
85+
if ($importCollections) {
8386
$lastModified = $collection->fileLastModified();
8487

8588
EloquentCollection::makeModelFromContract($collection)
8689
->fill(['created_at' => $lastModified, 'updated_at' => $lastModified])
8790
->save();
8891
}
8992

90-
if ($this->shouldImportCollectionTrees() && $structure = $collection->structure()) {
93+
if ($importCollectionTrees && $structure = $collection->structure()) {
9194
$structure->trees()->each(function ($tree) {
9295
$lastModified = $tree->fileLastModified();
9396

src/Commands/ImportGlobals.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,19 @@ private function useDefaultRepositories(): void
6060

6161
private function importGlobals(): void
6262
{
63-
$this->withProgressBar(GlobalSetFacade::all(), function ($set) {
64-
if ($this->shouldImportGlobalSets()) {
63+
$importGlobals = $this->shouldImportGlobalSets();
64+
$importVariables = $this->shouldImportGlobalVariables();
65+
66+
$this->withProgressBar(GlobalSetFacade::all(), function ($set) use ($importGlobals, $importVariables) {
67+
if ($importGlobals) {
6568
$lastModified = $set->fileLastModified();
6669

6770
GlobalSet::makeModelFromContract($set)
6871
->fill(['created_at' => $lastModified, 'updated_at' => $lastModified])
6972
->save();
7073
}
7174

72-
if ($this->shouldImportGlobalVariables()) {
75+
if ($importVariables) {
7376
$set->localizations()->each(function ($locale) {
7477
Variables::makeModelFromContract($locale)->save();
7578
});

src/Commands/ImportNavs.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ private function useDefaultRepositories(): void
6161

6262
private function importNavs(): void
6363
{
64-
$this->withProgressBar(NavFacade::all(), function ($nav) {
65-
if ($this->shouldImportNavigations()) {
64+
$importNavs = $this->shouldImportNavigations();
65+
$importTrees = $this->shouldImportNavigationTrees();
66+
67+
$this->withProgressBar(NavFacade::all(), function ($nav) use ($importNavs, $importTrees) {
68+
if ($importNavs) {
6669
$lastModified = $nav->fileLastModified();
6770

6871
EloquentNav::makeModelFromContract($nav)
6972
->fill(['created_at' => $lastModified, 'updated_at' => $lastModified])
7073
->save();
7174
}
7275

73-
if ($this->shouldImportNavigationTrees()) {
76+
if ($importTrees) {
7477
$nav->trees()->each(function ($tree) {
7578
$lastModified = $tree->fileLastModified();
7679

0 commit comments

Comments
 (0)