18 define(
'INSTALLER_DATA_DIR',
'dbscripts/xml');
21 define(
'INSTALLER_ERROR_GENERAL', 1);
22 define(
'INSTALLER_ERROR_DB', 2);
25 define(
'INSTALLER_DEFAULT_LOCALE',
'en_US');
27 import(
'lib.pkp.classes.db.DBDataXMLParser');
28 import(
'lib.pkp.classes.site.Version');
29 import(
'lib.pkp.classes.site.VersionDAO');
30 import(
'lib.pkp.classes.config.ConfigParser');
32 require_once
'./lib/pkp/lib/vendor/adodb/adodb-php/adodb-xmlschema.inc.php';
107 $this->actions = array();
108 $this->sql = array();
109 $this->notes = array();
118 die (
'ABSTRACT CLASS');
133 $this->
log(
'pre-install');
134 if (!isset($this->dbconn)) {
137 $this->dbconn = $conn->getDBConn();
139 if (!$conn->isConnected()) {
140 $this->
setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
145 if (!isset($this->currentVersion)) {
148 $this->currentVersion = $versionDao->getCurrentVersion();
151 if (!isset($this->locale)) {
155 if (!isset($this->installedLocales)) {
159 if (!isset($this->dataXMLParser)) {
161 $this->dataXMLParser->setDBConn($this->dbconn);
204 $this->
log(
'post-install');
215 function log($message) {
216 if (isset($this->logger)) {
217 call_user_func(array($this->logger,
'log'), $message);
232 $this->
log(sprintf(
'load: %s', $this->descriptor));
234 $installPath = $this->isPlugin ? $this->descriptor : INSTALLER_DATA_DIR . DIRECTORY_SEPARATOR .
$this->descriptor;
235 $installTree = $xmlParser->parse($installPath);
238 $this->
setError(INSTALLER_ERROR_GENERAL,
'installer.installFileError');
242 $versionString = $installTree->getAttribute(
'version');
243 if (isset($versionString)) {
263 $this->
log(sprintf(
'version: %s', $this->newVersion->getVersionString(
false)));
264 foreach ($this->actions as $action) {
281 if ($this->newVersion->compare($this->currentVersion) > 0) {
283 if (!$versionDao->insertVersion($this->newVersion)) {
304 foreach ($installTree->getChildren() as $node) {
305 switch ($node->getName()) {
314 $minVersion = $node->getAttribute(
'minversion');
315 $maxVersion = $node->getAttribute(
'maxversion');
316 if ((!isset($minVersion) || $this->currentVersion->compare($minVersion) >= 0) && (!isset($maxVersion) || $this->currentVersion->compare($maxVersion) <= 0)) {
329 $fileName = $node->getAttribute(
'file');
331 if (!isset($fileName)) {
332 $this->actions[] = array(
'type' => $node->getName(),
'file' =>
null,
'attr' => $node->getAttributes());
334 }
else if (strstr($fileName,
'{$installedLocale}')) {
336 foreach ($this->installedLocales as $thisLocale) {
337 $newFileName = str_replace(
'{$installedLocale}', $thisLocale, $fileName);
338 $this->actions[] = array(
'type' => $node->getName(),
'file' => $newFileName,
'attr' => $node->getAttributes());
342 $newFileName = str_replace(
'{$locale}', $this->locale, $fileName);
343 if (!file_exists($newFileName)) {
345 $newFileName = str_replace(
'{$locale}', INSTALLER_DEFAULT_LOCALE, $fileName);
348 $this->actions[] = array(
'type' => $node->getName(),
'file' => $newFileName,
'attr' => $node->getAttributes());
363 switch ($action[
'type']) {
365 $fileName = $action[
'file'];
366 $this->
log(sprintf(
'schema: %s', $action[
'file']));
368 $schemaXMLParser =
new adoSchema($this->dbconn);
369 $dict = $schemaXMLParser->dict;
370 $sql = $schemaXMLParser->parseSchema($fileName);
371 $schemaXMLParser->destroy();
376 $this->
setError(INSTALLER_ERROR_DB, str_replace(
'{$file}', $fileName, __(
'installer.installParseDBFileError')));
381 $fileName = $action[
'file'];
382 $condition = isset($action[
'attr'][
'condition'])?$action[
'attr'][
'condition']:
null;
383 $includeAction =
true;
386 $evalFunction =
function($installer, $action) use ($condition) {
387 return eval($condition);
389 $includeAction = $evalFunction($this, $action);
391 $this->
log(
'data: ' . $action[
'file'] . ($includeAction?
'':
' (skipped)'));
392 if (!$includeAction)
break;
394 $sql = $this->dataXMLParser->parseData($fileName);
402 assert(isset($action[
'attr'][
'class']));
403 $fullClassName = $action[
'attr'][
'class'];
404 import($fullClassName);
405 $shortClassName = substr($fullClassName, strrpos($fullClassName,
'.')+1);
406 $this->
log(sprintf(
'migration: %s', $shortClassName));
407 $migration =
new $shortClassName();
410 $this->migrations[] = $migration;
411 }
catch (Exception $e) {
413 $this->
setError(INSTALLER_ERROR_DB, $e->getMessage());
416 while ($previousMigration = array_pop($this->migrations)) {
417 $previousMigration->down();
423 $condition = isset($action[
'attr'][
'condition'])?$action[
'attr'][
'condition']:
null;
424 $includeAction =
true;
427 $evalFunction =
function($installer, $action) use ($condition) {
428 return eval($condition);
430 $includeAction = $evalFunction($this, $action);
432 $this->
log(sprintf(
'code: %s %s::%s' . ($includeAction?
'':
' (skipped)'), isset($action[
'file']) ? $action[
'file'] :
'Installer', isset($action[
'attr'][
'class']) ? $action[
'attr'][
'class'] :
'Installer', $action[
'attr'][
'function']));
433 if (!$includeAction)
return true;
435 if (isset($action[
'file'])) {
436 require_once($action[
'file']);
438 if (isset($action[
'attr'][
'class'])) {
439 return call_user_func(array($action[
'attr'][
'class'], $action[
'attr'][
'function']), $this, $action[
'attr']);
441 return call_user_func(array($this, $action[
'attr'][
'function']), $this, $action[
'attr']);
445 $this->
log(sprintf(
'note: %s', $action[
'file']));
446 $this->notes[] = join(
'', file($action[
'file']));
459 if (is_array(
$sql)) {
460 foreach(
$sql as $stmt) {
466 $this->dbconn->execute(
$sql);
467 if ($this->dbconn->errorNo() != 0) {
468 $this->
setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
486 $this->
setError(INSTALLER_ERROR_GENERAL,
'installer.configFileError');
490 $this->configContents = $configParser->getFileContents();
509 return isset($this->params[$name]) ? $this->params[$name] :
null;
569 return isset($this->errorType) ? $this->errorType : 0;
588 case INSTALLER_ERROR_DB:
601 $this->errorType = $type;
602 $this->errorMsg = $msg;
630 $this->currentVersion = $version;
641 $locales = explode(
',', $attr[
'locales']);
644 $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), $locales,
false, $attr[
'key']);
654 static $filterHelper =
false;
658 $tree = $xmlParser->parse($filterConfigFile);
661 if (!$tree)
return false;
664 if ($filterHelper ===
false) {
665 import(
'lib.pkp.classes.filter.FilterHelper');
670 $filterGroupsNode = $tree->getChildByName(
'filterGroups');
671 if (is_a($filterGroupsNode,
'XMLNode')) {
672 $filterHelper->installFilterGroups($filterGroupsNode);
676 $filtersNode = $tree->getChildByName(
'filters');
677 if (is_a($filtersNode,
'XMLNode')) {
678 foreach ($filtersNode->getChildren() as $filterNode) {
679 $filterHelper->configureFilter($filterNode);
695 $dataSource = $siteDao->getDataSource();
696 $dict = NewDataDictionary($dataSource);
699 $tables = $dict->MetaTables(
'TABLES',
false);
700 if (!in_array($tableName, $tables))
return false;
704 $columns = $dict->MetaColumns($tableName);
705 foreach ($columns as $column) {
706 if ($column->name == $columnName)
return true;
719 $dataSource = $siteDao->getDataSource();
720 $dict = NewDataDictionary($dataSource);
723 $tables = $dict->MetaTables(
'TABLES',
false);
724 return in_array($tableName, $tables);
734 import(
'lib.pkp.classes.site.VersionCheck');
737 foreach ($categories as $category) {
740 if (!empty($plugins)) {
741 foreach ($plugins as $plugin) {
742 $versionFile = $plugin->getPluginPath() .
'/version.xml';
744 if ($fileManager->fileExists($versionFile)) {
746 $pluginVersion = $versionInfo[
'version'];
752 'plugins.'.$category,
753 basename($plugin->getPluginPath()),
756 $plugin->isSitePlugin()
759 $versionDao->insertVersion($pluginVersion,
true);
773 function abort($installer, $attr) {
774 $installer->setError(INSTALLER_ERROR_GENERAL, $attr[
'message']);
786 $contexts = $contextDao->getAll();
787 while ($context = $contexts->next()) {
788 $navigationMenuDao->installSettings($context->getId(),
'registry/navigationMenus.xml');
791 $navigationMenuDao->installSettings(CONTEXT_ID_NONE,
'registry/navigationMenus.xml');
801 if (version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1)
return true;
803 $this->
setError(INSTALLER_ERROR_GENERAL,
'installer.unsupportedPhpError');
813 $result = $siteDao->retrieve(
'SELECT installed_locales, supported_locales FROM site');
816 $row = $result->GetRowAssoc(
false);
818 foreach ($row as $column => $value) {
819 if (!empty($value)) {
820 $set[] = $column .
' = ?';
821 $params[] = $siteDao->convertToDB(explode(
':', $value), $type);
824 $siteDao->update(
'UPDATE site SET ' . join(
',', $set),
$params);
839 $site = $siteDao->getSite();
842 if (empty($plugins)) {
847 $sanitizedPluginNames = array_map(
function($name) {
848 return "'" . preg_replace(
"/[^A-Za-z0-9]/",
'', $name) .
"'";
849 }, array_keys($plugins));
852 $result = $pluginSettingsDao->retrieve(
853 'SELECT plugin_name, context_id, setting_value FROM plugin_settings WHERE plugin_name IN (' . join(
',', $sanitizedPluginNames) .
') AND setting_name=\'context\';'
856 $sidebarSettings = [];
857 while (!$result->EOF) {
858 $row = $result->getRowAssoc(
false);
859 if ($row[
'setting_value'] != 1) {
862 $seq = $pluginSettingsDao->getSetting($row[
'context_id'], $row[
'plugin_name'],
'seq');
863 if (!isset($sidebarSettings[$row[
'context_id']])) {
864 $sidebarSettings[$row[
'context_id']] = [];
866 $sidebarSettings[$row[
'context_id']][(int) $seq] = $row[
'plugin_name'];
871 foreach ($sidebarSettings as $contextId => $contextSetting) {
873 ksort($contextSetting);
874 $contextSetting = array_values($contextSetting);
877 $context = $contextDao->getById($contextId);
878 $context->setData(
'sidebar', $contextSetting);
879 $contextDao->updateObject($context);
882 $site = $siteDao->getSite();
883 $site->setData(
'sidebar', $contextSetting);
884 $siteDao->updateObject($site);
888 $pluginSettingsDao->update(
'DELETE FROM plugin_settings WHERE plugin_name IN (' . join(
',', $sanitizedPluginNames ) .
') AND (setting_name=\'context\' OR setting_name=\'seq\');');
898 $contextDao = Application::getContextDao();
900 $metadataSettings = [
913 $result = $contextDao->retrieve(
'SELECT ' . $contextDao->primaryKeyColumn .
' from ' . $contextDao->tableName);
915 while (!$result->EOF) {
916 $row = $result->getRowAssoc(
false);
917 $contextIds[] = $row[$contextDao->primaryKeyColumn];
922 foreach ($metadataSettings as $metadataSetting) {
923 foreach ($contextIds as $contextId) {
924 $result = $contextDao->retrieve(
'
925 SELECT * FROM ' . $contextDao->settingsTableName .
' WHERE
926 ' . $contextDao->primaryKeyColumn .
' = ?
935 $metadataSetting .
'EnabledWorkflow',
936 $metadataSetting .
'EnabledSubmission',
937 $metadataSetting .
'Required',
940 $value = METADATA_DISABLE;
941 while (!$result->EOF) {
942 $row = $result->getRowAssoc(
false);
943 if ($row[
'setting_name'] === $metadataSetting .
'Required' && $row[
'setting_value']) {
944 $value = METADATA_REQUIRE;
945 } elseif ($row[
'setting_name'] === $metadataSetting .
'EnabledSubmission' && $row[
'setting_value'] && $value !== METADATA_REQUIRE) {
946 $value = METADATA_REQUEST;
947 } elseif ($row[
'setting_name'] === $metadataSetting .
'EnabledWorkflow' && $row[
'setting_value'] && $value !== METADATA_REQUEST && $value !== METADATA_REQUIRE) {
948 $value = METADATA_ENABLE;
954 if ($value !== METADATA_DISABLE) {
955 $contextDao->update(
'
956 INSERT INTO ' . $contextDao->settingsTableName .
' (
957 ' . $contextDao->primaryKeyColumn .
',
961 ) VALUES (?, ?, ?, ?)',
971 $contextDao->update(
'
972 DELETE FROM ' . $contextDao->settingsTableName .
' WHERE
973 ' . $contextDao->primaryKeyColumn .
' = ?
982 $metadataSetting .
'EnabledWorkflow',
983 $metadataSetting .
'EnabledSubmission',
984 $metadataSetting .
'Required',
998 import(
'lib.pkp.classes.notification.PKPNotification');
999 $roleIds = [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR];
1002 $notificationSubscriptionSettingsDao =
DAORegistry::getDAO(
'NotificationSubscriptionSettingsDAO');
1003 for ($contexts =
Application::get()->getContextDAO()->getAll(
true); $context = $contexts->next(); ) {
1004 foreach ($roleIds as $roleId) {
1005 for ($userGroups = $userGroupDao->getByRoleId($context->getId(), $roleId); $userGroup = $userGroups->next(); ) {
1006 for ($users = $userGroupDao->getUsersById($userGroup->getId(), $context->getId()); $user = $users->next(); ) {
1007 $notificationSubscriptionSettingsDao->update(
1008 'INSERT INTO notification_subscription_settings
1009 (setting_name, setting_value, user_id, context, setting_type)
1013 'blocked_emailed_notification',
1014 NOTIFICATION_TYPE_EDITORIAL_REPORT,
1034 import(
'classes.file.LibraryFileManager');
1037 $result = $libraryFileDao->retrieve(
'SELECT * FROM library_files');
1038 $libraryFiles =
new DAOResultFactory($result, $libraryFileDao,
'_fromRow', array(
'id'));
1039 $wrongFiles = array();
1040 while ($libraryFile = $libraryFiles->next()) {
1042 $wrongFilePath = $libraryFileManager->getBasePath() . $libraryFile->getOriginalFileName();
1043 $rightFilePath = $libraryFile->getFilePath();
1045 if (isset($wrongFiles[$wrongFilePath])) {
1046 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.');
1048 $wrongFiles[$wrongFilePath] = $libraryFile;
1054 if (file_exists($wrongFilePath) && !file_exists($rightFilePath)) {
1055 $libraryFileManager->copyFile($wrongFilePath, $rightFilePath);