Skip to content

Commit

Permalink
pkp/pkp-lib#5523: fix settings array usage and calling hook for upgra…
Browse files Browse the repository at this point in the history
…de data change
  • Loading branch information
ctgraham committed Mar 2, 2020
1 parent 1a15d95 commit b0e7c2e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions CustomBlockManagerPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function register($category, $path, $mainContextId = null) {
// permit administration of custom block plugins.
HookRegistry::register('LoadComponentHandler', array($this, 'setupGridHandler'));
}
HookRegistry::register('Installer::postInstall', array($this, 'upgradeData'));
return true;
}
return false;
Expand Down Expand Up @@ -171,14 +170,15 @@ function isSitePlugin() {
}

/**
* We will need to modify data in certain upgrades
* We will need to modify data in certain upgrades.
*
* @param $hookName string
* @param $args array
* @return boolean
*/
function upgradeData($hookName, $args) {
// There is no opportunity to hook the upgrade event before the new version is written to the versions table
function installFilters($hookName, $args) {
// There is no opportunity to hook the upgrade event before the new version is written to the versions table.
// The only function automatically called in installPluginVersion::execute() is installFilters(), so we hijack this.
// So, we need to look at the immediately preceeding version, and (re)apply fixes based on guesswork.
$versionDao = DAORegistry::getDAO('VersionDAO');
$contextDao = Application::getContextDAO();
Expand All @@ -195,23 +195,24 @@ function upgradeData($hookName, $args) {
foreach ($blocks as $block) {
// Update plugin_settings, if settings are stored directly as the block name
$settings = $pluginSettingsDao->getPluginSettings($context->getId(), $block);
foreach ($settings as $setting) {
switch ($setting['setting_name']) {
foreach ($settings as $setting_name => $setting_value) {
switch ($setting_name) {
case 'context':
// No constant name (!?!), per https://github.com/pkp/pkp-lib/commit/a76bac72ed068a1d1866398d20cdf28c4977249f#diff-70caff5ef9a513397af1833a3e2a3c7c
$setting['setting_value'] = 1; // BLOCK_CONTEXT_SIDEBAR
$setting_value = 1; // BLOCK_CONTEXT_SIDEBAR
case 'blockContent':
case 'enabled':
$pluginSettingsDao->deleteSetting($context->getId(), $block, $setting['setting_name']);
$pluginSettingsDao->updateSetting($context->getId(), $this->getChildName($block), $setting['setting_name'], $setting['setting_value'], $setting['setting_type']);
case 'seq':
$pluginSettingsDao->deleteSetting($context->getId(), $block, $setting_name);
$pluginSettingsDao->updateSetting($context->getId(), $this->getChildName($block), $setting_name, $setting_value);
break;
default:
error_log('found a setting "'.$setting['setting_name'].'", colliding with custom block "'.$block.'"');
error_log('found a setting "'.$setting_name.'", colliding with custom block "'.$block.'"');
}
}
}
}
}
return false;
return parent::installFilters($hookName, $args);
}
}

0 comments on commit b0e7c2e

Please sign in to comment.