@@ -32,6 +32,7 @@ class DumpCmsDataService
3232 private \Magento \Catalog \Model \CategoryList $ categoryList ;
3333 private \Magento \Store \Model \StoreManagerInterface $ storeManager ;
3434 private array $ blockIdentifiers = [];
35+ private array $ blocksMapping = [];
3536
3637 public function __construct (
3738 \Magento \Cms \Api \PageRepositoryInterface $ pageRepository ,
@@ -80,6 +81,28 @@ private function write(WriteInterface $writeDirectory, string $filePath, string
8081 $ stream ->close ();
8182 }
8283
84+ private function replaceBlockIds (string $ content ): string
85+ {
86+ preg_match_all ('/block_id=\"([0-9]+)\"/ ' , $ content , $ blockIds );
87+ if (isset ($ blockIds [1 ])) {
88+ $ searchCriteria = $ this ->criteriaBuilder ;
89+ $ searchCriteria ->addFilter ('block_id ' , $ blockIds [1 ], 'in ' );
90+ $ blocksList = $ this ->blockRepository ->getList ($ searchCriteria ->create ());
91+ $ blocks = $ blocksList ->getItems ();
92+ foreach ($ blocks as $ block ) {
93+ if (!isset ($ this ->blocksMapping [$ block ->getId ()])) {
94+ $ this ->blocksMapping [$ block ->getId ()] = $ block ->getIdentifier ();
95+ }
96+ }
97+ foreach ($ blockIds [1 ] as $ blockId ) {
98+ $ identifier = $ this ->blocksMapping [$ blockId ];
99+ $ content = str_replace ("block_id= \"$ blockId \"" , "block_id= \"$ identifier \"" , $ content );
100+ }
101+ }
102+
103+ return $ content ;
104+ }
105+
83106 private function getStoreCodes ($ stores ): array
84107 {
85108 $ storeCodes = [];
@@ -117,9 +140,11 @@ private function dumpPages(string $path, WriteInterface $varDirectory, ?array $i
117140 if (strpos ($ identifier , '.html ' ) !== false ) {
118141 $ identifier = str_replace ('.html ' , '_html ' , $ identifier );
119142 }
143+
120144 $ storeCodes = $ this ->getStoreCodes ($ page ->getStores ());
121145 $ htmlPath = $ path . $ identifier . '| ' . implode ('| ' , $ storeCodes ) . '.html ' ;
122- $ this ->write ($ varDirectory , $ htmlPath , $ page ->getContent ());
146+ $ pageContent = $ this ->replaceBlockIds ($ page ->getContent ());
147+ $ this ->write ($ varDirectory , $ htmlPath , $ pageContent );
123148 $ jsonPath = $ path . $ identifier . '| ' . implode ('| ' , $ storeCodes ) . '.json ' ;
124149 $ jsonContent = [
125150 'title ' => $ page ->getTitle (),
0 commit comments