Skip to content

Commit

Permalink
Merge pull request #94 from OXIDprojects/keywan-ghadami-oxid-patch-2
Browse files Browse the repository at this point in the history
less invasive method of fixing the module blocks
  • Loading branch information
keywan-ghadami-oxid authored Jun 25, 2019
2 parents 8d01624 + 6abcde4 commit 0434f2f
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions Core/ModuleStateFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,13 @@ protected function _addExtensions(\OxidEsales\Eshop\Core\Module\Module $module)
}
}



/**
* Add module templates to database.
*
* @deprecated please use setTemplateBlocks this method will be removed because
* the combination of deleting and adding does unnessery writes and so it does not scale
* also it's more likely to get race conditions (in the moment the blocks are deleted)
* this method sets template blocks with less conflicting writes as possible
* to reduce race conditions (in the moment the blocks are deleted)
* it will only report major changes even if id may be changed to ensure consistency of the data
*
*
* @param array $moduleBlocks Module blocks array
* @param string $moduleId Module id
Expand All @@ -586,16 +585,41 @@ protected function _addTemplateBlocks($moduleBlocks, $moduleId)
$moduleBlocks = array();
}
$shopId = Registry::getConfig()->getShopId();
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
$knownBlocks = ['dummy']; // Start with a dummy value to prevent having an empty list in the NOT IN statement.
$rowsEffected = 0;
$select_sql = "SELECT `OXID`, `OXTHEME` as `theme`, `OXTEMPLATE` as `template`, `OXBLOCKNAME` as `block`, `OXPOS` as `position`, `OXFILE` as `file`
FROM `oxtplblocks`
WHERE `OXMODULE` = ? AND `OXSHOPID` = ?";
$existingBlocks = $db->getAll($select_sql,[$moduleId,$shopId]);

foreach ($existingBlocks as $block) {
$id = $block['OXID'];
$block['position'] = (int) $block['position'];

unset($block['OXID']);
ksort($block);
$str1 = $moduleId . json_encode($block) . $shopId;
$wellGeneratedId = md5($str1);
if ($id !== $wellGeneratedId) {
$sql = "UPDATE IGNORE `oxtplblocks` SET OXID = ? WHERE OXID = ?";
$this->output->debug("$sql, $wellGeneratedId, $id");
$db->execute($sql, [$wellGeneratedId, $id]);
}
}


foreach ($moduleBlocks as $moduleBlock) {
$blockId = md5($moduleId . json_encode($moduleBlock) . $shopId);
$moduleBlock['theme'] = $moduleBlock['theme'] ?? '';
$moduleBlock['position'] = $position = isset($moduleBlock['position']) && is_numeric($moduleBlock['position']) ?
(int) $moduleBlock['position'] : 1;
ksort($moduleBlock);

$str = $moduleId . json_encode($moduleBlock) . $shopId;
$blockId = md5($str);
$knownBlocks[] = $blockId;

$template = $moduleBlock["template"];
$position = isset($moduleBlock['position']) && is_numeric($moduleBlock['position']) ?
intval($moduleBlock['position']) : 1;

$block = $moduleBlock["block"];
$filePath = $moduleBlock["file"];
Expand Down Expand Up @@ -638,7 +662,7 @@ protected function _addTemplateBlocks($moduleBlocks, $moduleId)
$this->output->info("fixed template blocks for module " . $moduleId);
}
}

/**
* @param Module $module
* @param $aModulesDefault
Expand Down

0 comments on commit 0434f2f

Please sign in to comment.