|
3 | 3 | namespace SolutionForest\InspireCms\Exports\Exporters; |
4 | 4 |
|
5 | 5 | use Illuminate\Database\Eloquent\Model; |
6 | | -use Illuminate\Support\Str; |
7 | 6 | use SolutionForest\InspireCms\Exports\ExportResult; |
8 | 7 | use SolutionForest\InspireCms\Helpers\FileHelper; |
9 | | -use SolutionForest\InspireCms\Helpers\TemplateHelper; |
10 | | -use SolutionForest\InspireCms\ImportData\Entities as ImportDataEntities; |
11 | | -use SolutionForest\InspireCms\Models\Contracts\Content; |
12 | | -use SolutionForest\InspireCms\Models\Contracts\DocumentType; |
13 | 8 | use SolutionForest\InspireCms\Models\Contracts\Export; |
14 | | -use SolutionForest\InspireCms\Models\Contracts\FieldGroup; |
15 | | -use SolutionForest\InspireCms\Models\Contracts\Template; |
16 | 9 |
|
17 | 10 | abstract class BaseExporter |
18 | 11 | { |
@@ -103,70 +96,6 @@ protected function ensureTempFolderForExport(string $folderPrefix, array $subFol |
103 | 96 | return array_merge([$folderName], $tmpFolderData); |
104 | 97 | } |
105 | 98 |
|
106 | | - /** |
107 | | - * @return string | array |
108 | | - */ |
109 | | - protected function generateImportFileName(Model $record) |
110 | | - { |
111 | | - switch (true) { |
112 | | - |
113 | | - case $record instanceof DocumentType: |
114 | | - case $record instanceof Content: |
115 | | - return $record->slug . '.json'; |
116 | | - |
117 | | - case $record instanceof FieldGroup: |
118 | | - return Str::replace('_', '-', $record->name) . '.json'; |
119 | | - |
120 | | - case $record instanceof Template: |
121 | | - if (is_array($record->content)) { |
122 | | - $themes = array_keys($record->content); |
123 | | - } else { |
124 | | - $themes = [inspirecms_templates()->getCurrentTheme()]; |
125 | | - } |
126 | | - |
127 | | - return collect($themes) |
128 | | - ->filter() |
129 | | - ->unique() |
130 | | - ->mapWithKeys(fn ($theme) => [$theme => $record->slug . '/' . TemplateHelper::ensureViewFileNameForTemplate($theme)]) |
131 | | - ->toArray(); |
132 | | - } |
133 | | - |
134 | | - return $record->getKey() . '.json'; |
135 | | - } |
136 | | - |
137 | | - /** |
138 | | - * @return array|bool|string |
139 | | - */ |
140 | | - protected function prepareImportContentFromModel(Model $record) |
141 | | - { |
142 | | - switch (true) { |
143 | | - |
144 | | - case $record instanceof DocumentType: |
145 | | - $array = ImportDataEntities\DocumentType::fromRecord($record)->toExportArray(); |
146 | | - |
147 | | - return json_encode($array, JSON_PRETTY_PRINT); |
148 | | - |
149 | | - case $record instanceof FieldGroup: |
150 | | - $array = ImportDataEntities\FieldGroup::fromRecord($record)->toExportArray(); |
151 | | - |
152 | | - return json_encode($array, JSON_PRETTY_PRINT); |
153 | | - |
154 | | - // case $record instanceof Template: |
155 | | - // $themeContent = $record->content; |
156 | | - // if (! is_array($themeContent)) { |
157 | | - // $themeContent = [inspirecms_templates()->getCurrentTheme() => $themeContent]; |
158 | | - // } |
159 | | - // return $themeContent; |
160 | | - |
161 | | - case $record instanceof Content: |
162 | | - $array = ImportDataEntities\Content::fromRecord($record)->toExportArray(); |
163 | | - |
164 | | - return json_encode($array, JSON_PRETTY_PRINT); |
165 | | - } |
166 | | - |
167 | | - return ''; |
168 | | - } |
169 | | - |
170 | 99 | protected static function isProcessCompleted(int $currentPage, int $totalPages, array $processingData) |
171 | 100 | { |
172 | 101 | return $currentPage >= $totalPages; |
@@ -195,45 +124,4 @@ protected function handleExportCompletion(string $folderName, $processingErrors) |
195 | 124 |
|
196 | 125 | return ExportResult::completed($zippedFile, $completedMessage); |
197 | 126 | } |
198 | | - |
199 | | - protected function processRecordForImportUsed(Model $record, $fs, ?string $dir, array &$errors) |
200 | | - { |
201 | | - try { |
202 | | - |
203 | | - $filename = $this->generateImportFileName($record); |
204 | | - |
205 | | - if ($record instanceof Template && is_array($filename)) { |
206 | | - |
207 | | - foreach ($filename as $theme => $templateFilePath) { |
208 | | - |
209 | | - $templateContent = $record->getContent($theme); |
210 | | - |
211 | | - $path = $dir . '/' . trim($templateFilePath, '/'); |
212 | | - |
213 | | - $fs->put($path, $templateContent); |
214 | | - } |
215 | | - |
216 | | - } elseif (! is_string($filename)) { |
217 | | - $errors[] = [ |
218 | | - 'record' => $record->getKey(), |
219 | | - 'model' => get_class($record), |
220 | | - 'message' => 'Invalid filename', |
221 | | - ]; |
222 | | - } else { |
223 | | - |
224 | | - $content = $this->prepareImportContentFromModel($record); |
225 | | - |
226 | | - $path = $dir . '/' . $filename; |
227 | | - $fs->put($path, $content); |
228 | | - |
229 | | - } |
230 | | - |
231 | | - } catch (\Throwable $th) { |
232 | | - $errors[] = [ |
233 | | - 'record' => $record->getKey(), |
234 | | - 'model' => get_class($record), |
235 | | - 'message' => $th->getMessage(), |
236 | | - ]; |
237 | | - } |
238 | | - } |
239 | 127 | } |
0 commit comments