Skip to content

Commit 1c05ce4

Browse files
committed
bugfix: export sample import data
1 parent 2d38a52 commit 1c05ce4

14 files changed

Lines changed: 842 additions & 231 deletions

config/inspirecms.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
'exports' => [
138138
'disk' => 'local',
139139
'exporters' => [
140+
\SolutionForest\InspireCms\Exports\Exporters\ImportUsedExporter::class,
140141
\SolutionForest\InspireCms\Exports\Exporters\DocumentTypeExporter::class,
141142
\SolutionForest\InspireCms\Exports\Exporters\FieldGroupExporter::class,
142143
\SolutionForest\InspireCms\Exports\Exporters\TemplateExporter::class,

src/Exports/Exporters/BaseExporter.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ protected static function isProcessCompleted(int $currentPage, int $totalPages,
101101
return $currentPage >= $totalPages;
102102
}
103103

104-
protected static function buildProcessingData(int $currentPage, int $perPage, array $errors, string $folderName)
105-
{
106-
return [
107-
'page' => $currentPage + 1,
108-
'perPage' => $perPage,
109-
'errors' => $errors,
110-
'folderName' => $folderName,
111-
];
112-
}
113-
114104
protected function handleExportCompletion(string $folderName, $processingErrors)
115105
{
116106
$zippedFile = $this->zipTempFolder($folderName);

src/Exports/Exporters/BaseImportUsedDataExporter.php

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Support\Str;
7+
use SolutionForest\InspireCms\Helpers\ImportDataHelper;
78
use SolutionForest\InspireCms\Helpers\TemplateHelper;
89
use SolutionForest\InspireCms\ImportData\Entities as ImportDataEntities;
910
use SolutionForest\InspireCms\Models\Contracts\Content;
1011
use SolutionForest\InspireCms\Models\Contracts\DocumentType;
1112
use SolutionForest\InspireCms\Models\Contracts\FieldGroup;
13+
use SolutionForest\InspireCms\Models\Contracts\Navigation;
1214
use SolutionForest\InspireCms\Models\Contracts\Template;
1315

1416
abstract class BaseImportUsedDataExporter extends BaseExporter
@@ -52,12 +54,12 @@ protected function prepareImportContentFromModel(Model $record)
5254
switch (true) {
5355

5456
case $record instanceof DocumentType:
55-
$array = ImportDataEntities\DocumentType::fromRecord($record)->toExportArray();
57+
$array = ImportDataEntities\DocumentType::fromRecord($record)->toArray();
5658

5759
return json_encode($array, JSON_PRETTY_PRINT);
5860

5961
case $record instanceof FieldGroup:
60-
$array = ImportDataEntities\FieldGroup::fromRecord($record)->toExportArray();
62+
$array = ImportDataEntities\FieldGroup::fromRecord($record)->toArray();
6163

6264
return json_encode($array, JSON_PRETTY_PRINT);
6365

@@ -69,12 +71,18 @@ protected function prepareImportContentFromModel(Model $record)
6971
// return $themeContent;
7072

7173
case $record instanceof Content:
72-
$array = ImportDataEntities\Content::fromRecord($record)->toExportArray();
74+
$array = ImportDataEntities\Content::fromRecord($record)->toArray();
75+
76+
return json_encode($array, JSON_PRETTY_PRINT);
77+
78+
case $record instanceof Navigation:
79+
80+
$array = ImportDataEntities\Navigation::fromRecord($record)->toArray();
7381

7482
return json_encode($array, JSON_PRETTY_PRINT);
7583
}
7684

77-
return '';
85+
return '{}';
7886
}
7987

8088
protected function processRecordForImportUsed(Model $record, $fs, ?string $dir, array &$errors)
@@ -117,4 +125,45 @@ protected function processRecordForImportUsed(Model $record, $fs, ?string $dir,
117125
];
118126
}
119127
}
128+
129+
/**
130+
* @param \Illuminate\Database\Eloquent\Builder $query
131+
* @param string $type
132+
* @return \Illuminate\Database\Eloquent\Builder
133+
*/
134+
protected function buildExportingQueryForImportUsed($query, $type)
135+
{
136+
switch ($type) {
137+
case ImportDataHelper::FOLDER_IDENTIFIER_DOCUMENTTYPE:
138+
return $query->with([
139+
'fieldGroups',
140+
'templates',
141+
'allowedDocumentTypes',
142+
'content',
143+
]);
144+
case ImportDataHelper::FOLDER_IDENTIFIER_FIELDGROUP:
145+
return $query->with([
146+
'fields',
147+
]);
148+
case ImportDataHelper::FOLDER_IDENTIFIER_CONTENT:
149+
return $query->with([
150+
'parent.path',
151+
'sitemap',
152+
'webSetting',
153+
'documentType',
154+
]);
155+
}
156+
157+
return $query;
158+
}
159+
160+
protected static function buildProcessingDataForImportUsed(int $currentPage, int $perPage, array $errors, string $folderName)
161+
{
162+
return [
163+
'page' => $currentPage + 1,
164+
'perPage' => $perPage,
165+
'errors' => $errors,
166+
'folderName' => $folderName,
167+
];
168+
}
120169
}

src/Exports/Exporters/DocumentTypeExporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function export()
106106
}
107107

108108
return ExportResult::paused(
109-
$this->buildProcessingData($page, $perPage, $processingErrors, $folderName),
109+
$this->buildProcessingDataForImportUsed($page, $perPage, $processingErrors, $folderName),
110110
);
111111
}
112112

src/Exports/Exporters/FieldGroupExporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function export()
5757
}
5858

5959
return ExportResult::paused(
60-
$this->buildProcessingData($page, $perPage, $processingErrors, $folderName),
60+
$this->buildProcessingDataForImportUsed($page, $perPage, $processingErrors, $folderName),
6161
);
6262
}
6363

0 commit comments

Comments
 (0)