|
17 | 17 |
|
18 | 18 | namespace RocketWeb\CmsImportExport\Model\Service; |
19 | 19 |
|
| 20 | +use Magento\Cms\Api\Data\BlockInterface; |
| 21 | +use Magento\Cms\Api\Data\PageInterface; |
20 | 22 | use Magento\Framework\App\Filesystem\DirectoryList; |
21 | 23 |
|
22 | 24 | class ImportCmsDataService |
@@ -53,7 +55,7 @@ public function __construct( |
53 | 55 | $this->storeRepository = $storeRepository; |
54 | 56 | } |
55 | 57 |
|
56 | | - public function execute(array $types, ?array $identifiers, bool $importAll, ?string $storeCode) |
| 58 | + public function execute(array $types, ?array $identifiers, bool $importAll, ?string $storeCode = null) |
57 | 59 | { |
58 | 60 | $workingDirPath = 'sync_cms_data'; |
59 | 61 |
|
@@ -116,6 +118,12 @@ private function importBlocks(string $dirPath, ?array $identifiers, ?string $sto |
116 | 118 | } |
117 | 119 | if ($storeCode !== null && ($this->getStoreCode($filePath) !== $storeCode)) { |
118 | 120 | // Skip identifiers not assigned to specific store when storeCode parameter is set |
| 121 | + echo sprintf( |
| 122 | + 'Skipping identifier %s because requested update only for store %s %s', |
| 123 | + $identifier, |
| 124 | + $storeCode, |
| 125 | + PHP_EOL |
| 126 | + ); |
119 | 127 | continue; |
120 | 128 | } |
121 | 129 |
|
@@ -173,6 +181,12 @@ private function importPages(string $dirPath, ?array $identifiers, ?string $stor |
173 | 181 |
|
174 | 182 | if ($storeCode !== null && ($this->getStoreCode($filePath) !== $storeCode)) { |
175 | 183 | // Skip identifiers not assigned to specific store when storeCode parameter is set |
| 184 | + echo sprintf( |
| 185 | + 'Skipping identifier %s because requested update only for store %s %s', |
| 186 | + $identifier, |
| 187 | + $storeCode, |
| 188 | + PHP_EOL |
| 189 | + ); |
176 | 190 | continue; |
177 | 191 | } |
178 | 192 |
|
@@ -212,13 +226,23 @@ private function importPages(string $dirPath, ?array $identifiers, ?string $stor |
212 | 226 | } |
213 | 227 | } |
214 | 228 |
|
| 229 | + /** |
| 230 | + * We are validating here is store association is correct |
| 231 | + * string $filePath - HTML filename, may contain either store code or _all_ |
| 232 | + * BlockInterface | PageInterface $entity - either block or page if already exists |
| 233 | + * array $storeIds - array of stores to associate from JSON file |
| 234 | + * string $entityType - either "block" or "page", for accurate messaging |
| 235 | + * |
| 236 | + * We load store by store code specified in $filePath |
| 237 | + * Further we validate it against the data we have in JSON and if currently existing block/page |
| 238 | + */ |
215 | 239 | private function validateStoreAssociation( |
216 | 240 | string $filePath, |
217 | | - mixed $entity, |
| 241 | + BlockInterface | PageInterface $entity, |
218 | 242 | array $storeIds, |
219 | 243 | string $entityType |
220 | 244 | ) : void { |
221 | | - $exceptionMessage = sprintf('%s with path %s has incosistent store data', $entityType, $filePath); |
| 245 | + $exceptionMessage = sprintf('%s with path %s has inconsistent store data', $entityType, $filePath); |
222 | 246 | if (count($storeIds) > 1) { |
223 | 247 | throw new \LogicException($exceptionMessage); |
224 | 248 | } |
|
0 commit comments