Skip to content

Commit

Permalink
Remove ADODB and upgrades <= 3.2.x (pkp#9734)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher authored Feb 16, 2024
1 parent 9384b74 commit 3e5d39b
Show file tree
Hide file tree
Showing 26 changed files with 1 addition and 10,094 deletions.
257 changes: 0 additions & 257 deletions classes/install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,23 @@

use adoSchema;
use APP\core\Application;
use APP\facades\Repo;
use APP\file\LibraryFileManager;
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use PKP\cache\CacheManager;
use PKP\config\Config;
use PKP\context\Context;
use PKP\context\LibraryFile;
use PKP\core\Core;
use PKP\core\PKPApplication;
use PKP\core\PKPContainer;
use PKP\db\DAORegistry;
use PKP\db\DAOResultFactory;
use PKP\db\DBDataXMLParser;
use PKP\db\XMLDAO;
use PKP\facades\Locale;
use PKP\file\FileManager;
use PKP\filter\FilterHelper;
use PKP\navigationMenu\NavigationMenuDAO;
use PKP\notification\PKPNotification;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\security\Role;
use PKP\site\SiteDAO;
use PKP\site\Version;
use PKP\site\VersionCheck;
Expand Down Expand Up @@ -1015,256 +1008,6 @@ public function checkPhpVersion()
$this->setError(self::INSTALLER_ERROR_GENERAL, 'installer.unsupportedPhpError');
return false;
}

/**
* Migrate site locale settings to a serialized array in the database
*/
public function migrateSiteLocales()
{
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */

$result = $siteDao->retrieve('SELECT installed_locales, supported_locales FROM site');

$set = $params = [];
$row = (array) $result->current();
$type = 'array';
foreach ($row as $column => $value) {
if (!empty($value)) {
$set[] = $column . ' = ?';
$params[] = $siteDao->convertToDB(explode(':', $value), $type);
}
}
$siteDao->update('UPDATE site SET ' . join(',', $set), $params);

return true;
}

/**
* Migrate active sidebar blocks from plugin_settings to journal_settings
*
* @return bool
*/
public function migrateSidebarBlocks()
{
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
$site = $siteDao->getSite();

$plugins = PluginRegistry::loadCategory('blocks');
if (empty($plugins)) {
return true;
}

// Sanitize plugin names for use in sql IN().
$sanitizedPluginNames = array_map(function ($name) {
return "'" . preg_replace('/[^A-Za-z0-9]/', '', $name) . "'";
}, array_keys($plugins));

$pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /** @var \PKP\plugins\PluginSettingsDAO $pluginSettingsDao */
$result = $pluginSettingsDao->retrieve(
'SELECT plugin_name, context_id, setting_value FROM plugin_settings WHERE plugin_name IN (' . join(',', $sanitizedPluginNames) . ') AND setting_name=\'context\';'
);

$sidebarSettings = [];
foreach ($result as $row) {
if ($row->setting_value != 1) {
continue;
} // BLOCK_CONTEXT_SIDEBAR

$seq = $pluginSettingsDao->getSetting($row->context_id, $row->plugin_name, 'seq');
if (!isset($sidebarSettings[$row->context_id])) {
$sidebarSettings[$row->context_id] = [];
}
$sidebarSettings[$row->context_id][(int) $seq] = $row->plugin_name;
}

foreach ($sidebarSettings as $contextId => $contextSetting) {
// Order by sequence
ksort($contextSetting);
$contextSetting = array_values($contextSetting);
if ($contextId) {
$contextDao = Application::getContextDAO();
$context = $contextDao->getById($contextId);
$context->setData('sidebar', $contextSetting);
$contextDao->updateObject($context);
} else {
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
$site = $siteDao->getSite();
$site->setData('sidebar', $contextSetting);
$siteDao->updateObject($site);
}
}

$pluginSettingsDao->update('DELETE FROM plugin_settings WHERE plugin_name IN (' . join(',', $sanitizedPluginNames) . ') AND (setting_name=\'context\' OR setting_name=\'seq\');');

return true;
}

/**
* Migrate the metadata settings in the database to use a single row with one
* of the new constants
*/
public function migrateMetadataSettings()
{
$contextDao = Application::getContextDao();

$metadataSettings = [
'coverage',
'rights',
'source',
'subjects',
'type',
'disciplines',
'keywords',
'agencies',
'citations',
];

$result = $contextDao->retrieve('SELECT ' . $contextDao->primaryKeyColumn . ' from ' . $contextDao->tableName);
$contextIds = [];
foreach ($result as $row) {
$row = (array) $row;
$contextIds[] = $row[$contextDao->primaryKeyColumn];
}

foreach ($metadataSettings as $metadataSetting) {
foreach ($contextIds as $contextId) {
$result = $contextDao->retrieve(
'SELECT *
FROM ' . $contextDao->settingsTableName . '
WHERE
' . $contextDao->primaryKeyColumn . ' = ?
AND (
setting_name = ?
OR setting_name = ?
OR setting_name = ?
)
',
[
$contextId,
$metadataSetting . 'EnabledWorkflow',
$metadataSetting . 'EnabledSubmission',
$metadataSetting . 'Required',
]
);
$value = Context::METADATA_DISABLE;
foreach ($result as $row) {
if ($row->setting_name === $metadataSetting . 'Required' && $row->setting_value) {
$value = Context::METADATA_REQUIRE;
} elseif ($row->setting_name === $metadataSetting . 'EnabledSubmission' && $row->setting_value && $value !== Context::METADATA_REQUIRE) {
$value = Context::METADATA_REQUEST;
} elseif ($row->setting_name === $metadataSetting . 'EnabledWorkflow' && $row->setting_value && $value !== Context::METADATA_REQUEST && $value !== Context::METADATA_REQUIRE) {
$value = Context::METADATA_ENABLE;
}
}

if ($value !== Context::METADATA_DISABLE) {
$contextDao->update(
'INSERT INTO ' . $contextDao->settingsTableName . ' (
' . $contextDao->primaryKeyColumn . ',
locale,
setting_name,
setting_value
) VALUES (?, ?, ?, ?)',
[
$contextId,
'',
$metadataSetting,
$value,
]
);
}

$contextDao->update(
'DELETE FROM ' . $contextDao->settingsTableName . ' WHERE
' . $contextDao->primaryKeyColumn . ' = ?
AND (
setting_name = ?
OR setting_name = ?
OR setting_name = ?
)
',
[
$contextId,
$metadataSetting . 'EnabledWorkflow',
$metadataSetting . 'EnabledSubmission',
$metadataSetting . 'Required',
]
);
}
}

return true;
}

/**
* Set the notification settings for journal managers and subeditors so
* that they are opted out of the monthly stats email.
*/
public function setStatsEmailSettings()
{
$roleIds = [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR];

$notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO'); /** @var \PKP\notification\NotificationSubscriptionSettingsDAO $notificationSubscriptionSettingsDao */
for ($contexts = Application::get()->getContextDAO()->getAll(true); $context = $contexts->next();) {
$users = Repo::user()->getCollector()
->filterByContextIds([$context->getId()])
->filterByRoleIds($roleIds)
->getMany();

foreach ($users as $user) {
$notificationSubscriptionSettingsDao->update(
'INSERT INTO notification_subscription_settings
(setting_name, setting_value, user_id, context, setting_type)
VALUES
(?, ?, ?, ?, ?)',
[
'blocked_emailed_notification',
PKPNotification::NOTIFICATION_TYPE_EDITORIAL_REPORT,
$user->getId(),
$context->getId(),
'int'
]
);
}
}

return true;
}

/**
* Fix library files, which were mistakenly named server-side using source filenames.
* See https://github.com/pkp/pkp-lib/issues/5471
*
* @return bool
*/
public function fixLibraryFiles()
{
// Fetch all library files (no method currently in LibraryFileDAO for this)
$libraryFileDao = DAORegistry::getDAO('LibraryFileDAO'); /** @var \PKP\context\LibraryFileDAO $libraryFileDao */
$result = $libraryFileDao->retrieve('SELECT * FROM library_files');
/** @var DAOResultFactory<LibraryFile> */
$libraryFiles = new DAOResultFactory($result, $libraryFileDao, '_fromRow', ['id']);
$wrongFiles = [];
while ($libraryFile = $libraryFiles->next()) {
$libraryFileManager = new LibraryFileManager($libraryFile->getContextId());
$wrongFilePath = $libraryFileManager->getBasePath() . $libraryFile->getOriginalFileName();
$rightFilePath = $libraryFile->getFilePath();

if (isset($wrongFiles[$wrongFilePath])) {
error_log('A potential collision was found between library files ' . $libraryFile->getId() . ' and ' . $wrongFiles[$wrongFilePath]->getId() . '. Please review the database entries and ensure that the associated files are correct.');
} else {
$wrongFiles[$wrongFilePath] = $libraryFile;
}

// For all files for which the "wrong" filename exists and the "right" filename doesn't,
// copy the "wrong" file over to the "right" one. This will leave the "wrong" file in
// place, and won't disambiguate cases for which files were clobbered.
if (file_exists($wrongFilePath) && !file_exists($rightFilePath)) {
$libraryFileManager->copyFile($wrongFilePath, $rightFilePath);
}
}
return true;
}
}

if (!PKP_STRICT_MODE) {
Expand Down
10 changes: 0 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"require": {
"adodb/adodb-php": "v5.20.18",
"components/jquery": "^3.5",
"components/jqueryui": "1.*",
"composer/semver": "^3.3",
Expand Down Expand Up @@ -59,15 +58,6 @@
"isoFileCheck": [
"PKP\\dev\\ComposerScript::isoFileCheck" ]
},
"extra": {
"patches": {
"adodb/adodb-php": {
"Apply PKP ADODB patches": "lib/adodb.diff",
"Apply PKP ADODB PHP8.1 patches": "lib/adodb-php8.1.diff",
"Apply PKP ADODB patches for error handling": "lib/adodb-datadict-errors.diff"
}
}
},
"autoload": {
"psr-4": {
"PKP\\controllers\\": "controllers/",
Expand Down
60 changes: 1 addition & 59 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion dtd/install.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Example:
*
* <install version="2.0.0.0">
* <schema file="ojs_schema.xml"/>
* <data file="data/common_data.xml"/>
* <data file="data/locale/{$locale}/locale_data.xml"/>
* </install>
Expand Down
Loading

0 comments on commit 3e5d39b

Please sign in to comment.