Skip to content

Commit e767da6

Browse files
committed
IP-314 Expand the CMS import / export module to cover store blocks/pages
1 parent e77bc6b commit e767da6

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Model/Service/ImportCmsDataService.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace RocketWeb\CmsImportExport\Model\Service;
1919

20+
use Magento\Cms\Api\Data\BlockInterface;
21+
use Magento\Cms\Api\Data\PageInterface;
2022
use Magento\Framework\App\Filesystem\DirectoryList;
2123

2224
class ImportCmsDataService
@@ -53,7 +55,7 @@ public function __construct(
5355
$this->storeRepository = $storeRepository;
5456
}
5557

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)
5759
{
5860
$workingDirPath = 'sync_cms_data';
5961

@@ -116,6 +118,12 @@ private function importBlocks(string $dirPath, ?array $identifiers, ?string $sto
116118
}
117119
if ($storeCode !== null && ($this->getStoreCode($filePath) !== $storeCode)) {
118120
// 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+
);
119127
continue;
120128
}
121129

@@ -173,6 +181,12 @@ private function importPages(string $dirPath, ?array $identifiers, ?string $stor
173181

174182
if ($storeCode !== null && ($this->getStoreCode($filePath) !== $storeCode)) {
175183
// 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+
);
176190
continue;
177191
}
178192

@@ -212,13 +226,23 @@ private function importPages(string $dirPath, ?array $identifiers, ?string $stor
212226
}
213227
}
214228

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+
*/
215239
private function validateStoreAssociation(
216240
string $filePath,
217-
mixed $entity,
241+
BlockInterface | PageInterface $entity,
218242
array $storeIds,
219243
string $entityType
220244
) : 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);
222246
if (count($storeIds) > 1) {
223247
throw new \LogicException($exceptionMessage);
224248
}

0 commit comments

Comments
 (0)