Skip to content

Commit

Permalink
Fix issues with upd-2.0.18-to-2.3.0 step
Browse files Browse the repository at this point in the history
MySQL changes removing the 'IGNORE' options on INSERT statements
in versions 5.7 and above caused upgrade of block_module_link
table to fail.
  • Loading branch information
geekwright committed Nov 10, 2023
1 parent 4f44e2c commit b0623fe
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions upgrade/upd-2.0.18-to-2.3.0/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

use Xmf\Database\Tables;

/**
* Upgrader from 2.0.18 to 2.3.0
*
Expand Down Expand Up @@ -67,7 +69,8 @@ public function check_cache()
return false;
}

return $GLOBALS['xoopsDB']->getRowsNum($result) > 0;
$temp = $GLOBALS['xoopsDB']->getRowsNum($result) > 0;
return $temp;

/*
$sql = "SELECT COUNT(*) FROM `" . $GLOBALS['xoopsDB']->prefix('cache_model') . "`";
Expand Down Expand Up @@ -106,29 +109,38 @@ public function check_bmlink()
*/
public function apply_bmlink()
{
$sql = 'SHOW KEYS FROM `' . $GLOBALS['xoopsDB']->prefix('block_module_link') . '`';
$result = $GLOBALS['xoopsDB']->queryF($sql);
if (!$GLOBALS['xoopsDB']->isResultSet($result)) {
return false;
$tableName = 'block_module_link';
$tableNameOld = $tableName . '_old';

$tables = new Tables();

$tables->useTable($tableName);
$tables->renameTable($tableName, $tableNameOld);
$result = $tables->executeQueue(true);
if (true!==$result) {
throw new \RuntimeException(
__METHOD__ . ' failed.', E_USER_ERROR
);
}
$keys_drop = array();
$primary_add = true;
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
if ($row['Key_name'] === 'PRIMARY') {
$primary_add = false;
}
if (in_array($row['Key_name'], array('block_id', 'module_id'))) {
$keys_drop[] = $row['Key_name'];
}
}
foreach ($keys_drop as $drop) {
$sql = 'ALTER TABLE `' . $GLOBALS['xoopsDB']->prefix('block_module_link') . "` DROP KEY `{$drop}`";
$GLOBALS['xoopsDB']->queryF($sql);
$tables->resetQueue();
$tables->addTable($tableName);
$tables->addColumn($tableName, 'block_id', 'int');
$tables->addColumn($tableName, 'module_id', 'int');
$tables->addPrimaryKey($tableName, 'block_id, module_id');
$result = $tables->executeQueue(true);
if (true!==$result) {
throw new \RuntimeException(
__METHOD__ . ' failed.', E_USER_ERROR
);
}
if ($primary_add) {
$sql = 'ALTER IGNORE TABLE `' . $GLOBALS['xoopsDB']->prefix('block_module_link') . '` ADD PRIMARY KEY (`block_id`, `module_id`)';

return $GLOBALS['xoopsDB']->queryF($sql);
$prefixedName = $GLOBALS['xoopsDB']->prefix('block_module_link');
$sql = 'INSERT INTO `' . $prefixedName . '` (`block_id`, `module_id`) ' .
'SELECT DISTINCT `block_id`, `module_id` FROM `' . $prefixedName . '_old`';
$result = $GLOBALS['xoopsDB']->queryF($sql);
if (true!==$result) {
throw new \RuntimeException(
__METHOD__ . ' failed.', E_USER_ERROR
);
}

return true;
Expand Down

0 comments on commit b0623fe

Please sign in to comment.