@@ -568,14 +568,13 @@ protected function _addExtensions(\OxidEsales\Eshop\Core\Module\Module $module)
568
568
}
569
569
}
570
570
571
-
572
-
573
571
/**
574
572
* Add module templates to database.
575
573
*
576
- * @deprecated please use setTemplateBlocks this method will be removed because
577
- * the combination of deleting and adding does unnessery writes and so it does not scale
578
- * also it's more likely to get race conditions (in the moment the blocks are deleted)
574
+ * this method sets template blocks with less conflicting writes as possible
575
+ * to reduce race conditions (in the moment the blocks are deleted)
576
+ * it will only report major changes even if id may be changed to ensure consistency of the data
577
+ *
579
578
*
580
579
* @param array $moduleBlocks Module blocks array
581
580
* @param string $moduleId Module id
@@ -586,16 +585,41 @@ protected function _addTemplateBlocks($moduleBlocks, $moduleId)
586
585
$ moduleBlocks = array ();
587
586
}
588
587
$ shopId = Registry::getConfig ()->getShopId ();
589
- $ db = \OxidEsales \Eshop \Core \DatabaseProvider::getDb ();
588
+ $ db = \OxidEsales \Eshop \Core \DatabaseProvider::getDb (\ OxidEsales \ Eshop \ Core \DatabaseProvider:: FETCH_MODE_ASSOC );
590
589
$ knownBlocks = ['dummy ' ]; // Start with a dummy value to prevent having an empty list in the NOT IN statement.
591
590
$ rowsEffected = 0 ;
591
+ $ select_sql = "SELECT `OXID`, `OXTHEME` as `theme`, `OXTEMPLATE` as `template`, `OXBLOCKNAME` as `block`, `OXPOS` as `position`, `OXFILE` as `file`
592
+ FROM `oxtplblocks`
593
+ WHERE `OXMODULE` = ? AND `OXSHOPID` = ? " ;
594
+ $ existingBlocks = $ db ->getAll ($ select_sql ,[$ moduleId ,$ shopId ]);
595
+
596
+ foreach ($ existingBlocks as $ block ) {
597
+ $ id = $ block ['OXID ' ];
598
+ $ block ['position ' ] = (int ) $ block ['position ' ];
599
+
600
+ unset($ block ['OXID ' ]);
601
+ ksort ($ block );
602
+ $ str1 = $ moduleId . json_encode ($ block ) . $ shopId ;
603
+ $ wellGeneratedId = md5 ($ str1 );
604
+ if ($ id !== $ wellGeneratedId ) {
605
+ $ sql = "UPDATE IGNORE `oxtplblocks` SET OXID = ? WHERE OXID = ? " ;
606
+ $ this ->output ->debug ("$ sql, $ wellGeneratedId, $ id " );
607
+ $ db ->execute ($ sql , [$ wellGeneratedId , $ id ]);
608
+ }
609
+ }
610
+
611
+
592
612
foreach ($ moduleBlocks as $ moduleBlock ) {
593
- $ blockId = md5 ($ moduleId . json_encode ($ moduleBlock ) . $ shopId );
613
+ $ moduleBlock ['theme ' ] = $ moduleBlock ['theme ' ] ?? '' ;
614
+ $ moduleBlock ['position ' ] = $ position = isset ($ moduleBlock ['position ' ]) && is_numeric ($ moduleBlock ['position ' ]) ?
615
+ (int ) $ moduleBlock ['position ' ] : 1 ;
616
+ ksort ($ moduleBlock );
617
+
618
+ $ str = $ moduleId . json_encode ($ moduleBlock ) . $ shopId ;
619
+ $ blockId = md5 ($ str );
594
620
$ knownBlocks [] = $ blockId ;
595
621
596
622
$ template = $ moduleBlock ["template " ];
597
- $ position = isset ($ moduleBlock ['position ' ]) && is_numeric ($ moduleBlock ['position ' ]) ?
598
- intval ($ moduleBlock ['position ' ]) : 1 ;
599
623
600
624
$ block = $ moduleBlock ["block " ];
601
625
$ filePath = $ moduleBlock ["file " ];
@@ -638,7 +662,7 @@ protected function _addTemplateBlocks($moduleBlocks, $moduleId)
638
662
$ this ->output ->info ("fixed template blocks for module " . $ moduleId );
639
663
}
640
664
}
641
-
665
+
642
666
/**
643
667
* @param Module $module
644
668
* @param $aModulesDefault
0 commit comments