Open Journal Systems  3.3.0
Installer.inc.php
1 <?php
2 
17 // Database installation files
18 define('INSTALLER_DATA_DIR', 'dbscripts/xml');
19 
20 // Installer error codes
21 define('INSTALLER_ERROR_GENERAL', 1);
22 define('INSTALLER_ERROR_DB', 2);
23 
24 // Default data
25 define('INSTALLER_DEFAULT_LOCALE', 'en_US');
26 
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');
31 
32 require_once './lib/pkp/lib/vendor/adodb/adodb-php/adodb-xmlschema.inc.php';
33 
34 class Installer {
35 
37  var $descriptor;
38 
40  var $isPlugin;
41 
43  var $params;
44 
47 
49  var $newVersion;
50 
52  var $dbconn;
53 
55  var $locale;
56 
59 
61  var $dataXMLParser;
62 
64  var $actions;
65 
67  var $sql;
68 
70  var $notes;
71 
73  var $configContents;
74 
77 
79  var $errorType;
80 
82  var $errorMsg;
83 
85  var $logger;
86 
88  var $migrations = [];
89 
96  function __construct($descriptor, $params = array(), $isPlugin = false) {
97  // Load all plugins. If any of them use installer hooks,
98  // they'll need to be loaded here.
100  $this->isPlugin = $isPlugin;
101 
102  // Give the HookRegistry the opportunity to override this
103  // method or alter its parameters.
104  if (!HookRegistry::call('Installer::Installer', array($this, &$descriptor, &$params))) {
105  $this->descriptor = $descriptor;
106  $this->params = $params;
107  $this->actions = array();
108  $this->sql = array();
109  $this->notes = array();
110  $this->wroteConfig = true;
111  }
112  }
113 
117  function isUpgrade() {
118  die ('ABSTRACT CLASS');
119  }
120 
124  function destroy() {
125  HookRegistry::call('Installer::destroy', array($this));
126  }
127 
132  function preInstall() {
133  $this->log('pre-install');
134  if (!isset($this->dbconn)) {
135  // Connect to the database.
137  $this->dbconn = $conn->getDBConn();
138 
139  if (!$conn->isConnected()) {
140  $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
141  return false;
142  }
143  }
144 
145  if (!isset($this->currentVersion)) {
146  // Retrieve the currently installed version
147  $versionDao = DAORegistry::getDAO('VersionDAO'); /* @var $versionDao VersionDAO */
148  $this->currentVersion = $versionDao->getCurrentVersion();
149  }
150 
151  if (!isset($this->locale)) {
152  $this->locale = AppLocale::getLocale();
153  }
154 
155  if (!isset($this->installedLocales)) {
156  $this->installedLocales = array_keys(AppLocale::getAllLocales());
157  }
158 
159  if (!isset($this->dataXMLParser)) {
160  $this->dataXMLParser = new DBDataXMLParser();
161  $this->dataXMLParser->setDBConn($this->dbconn);
162  }
163 
164  $result = true;
165  HookRegistry::call('Installer::preInstall', array($this, &$result));
166 
167  return $result;
168  }
169 
174  function execute() {
175  // Ensure that the installation will not get interrupted if it takes
176  // longer than max_execution_time (php.ini). Note that this does not
177  // work under safe mode.
178  @set_time_limit (0);
179 
180  if (!$this->preInstall()) {
181  return false;
182  }
183 
184  if (!$this->parseInstaller()) {
185  return false;
186  }
187 
188  if (!$this->executeInstaller()) {
189  return false;
190  }
191 
192  if (!$this->postInstall()) {
193  return false;
194  }
195 
196  return $this->updateVersion();
197  }
198 
203  function postInstall() {
204  $this->log('post-install');
205  $result = true;
206  HookRegistry::call('Installer::postInstall', array($this, &$result));
207  return $result;
208  }
209 
210 
215  function log($message) {
216  if (isset($this->logger)) {
217  call_user_func(array($this->logger, 'log'), $message);
218  }
219  }
220 
221 
222  //
223  // Main actions
224  //
225 
230  function parseInstaller() {
231  // Read installation descriptor file
232  $this->log(sprintf('load: %s', $this->descriptor));
233  $xmlParser = new XMLParser();
234  $installPath = $this->isPlugin ? $this->descriptor : INSTALLER_DATA_DIR . DIRECTORY_SEPARATOR . $this->descriptor;
235  $installTree = $xmlParser->parse($installPath);
236  if (!$installTree) {
237  // Error reading installation file
238  $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFileError');
239  return false;
240  }
241 
242  $versionString = $installTree->getAttribute('version');
243  if (isset($versionString)) {
244  $this->newVersion = Version::fromString($versionString);
245  } else {
246  $this->newVersion = $this->currentVersion;
247  }
248 
249  // Parse descriptor
250  $this->parseInstallNodes($installTree);
251 
252  $result = $this->getErrorType() == 0;
253 
254  HookRegistry::call('Installer::parseInstaller', array($this, &$result));
255  return $result;
256  }
257 
262  function executeInstaller() {
263  $this->log(sprintf('version: %s', $this->newVersion->getVersionString(false)));
264  foreach ($this->actions as $action) {
265  if (!$this->executeAction($action)) {
266  return false;
267  }
268  }
269 
270  $result = true;
271  HookRegistry::call('Installer::executeInstaller', array($this, &$result));
272 
273  return $result;
274  }
275 
280  function updateVersion() {
281  if ($this->newVersion->compare($this->currentVersion) > 0) {
282  $versionDao = DAORegistry::getDAO('VersionDAO'); /* @var $versionDao VersionDAO */
283  if (!$versionDao->insertVersion($this->newVersion)) {
284  return false;
285  }
286  }
287 
288  $result = true;
289  HookRegistry::call('Installer::updateVersion', array($this, &$result));
290 
291  return $result;
292  }
293 
294 
295  //
296  // Installer Parsing
297  //
298 
303  function parseInstallNodes($installTree) {
304  foreach ($installTree->getChildren() as $node) {
305  switch ($node->getName()) {
306  case 'schema':
307  case 'data':
308  case 'code':
309  case 'migration':
310  case 'note':
311  $this->addInstallAction($node);
312  break;
313  case 'upgrade':
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)) {
317  $this->parseInstallNodes($node);
318  }
319  break;
320  }
321  }
322  }
323 
328  function addInstallAction($node) {
329  $fileName = $node->getAttribute('file');
330 
331  if (!isset($fileName)) {
332  $this->actions[] = array('type' => $node->getName(), 'file' => null, 'attr' => $node->getAttributes());
333 
334  } else if (strstr($fileName, '{$installedLocale}')) {
335  // Filename substitution for locales
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());
339  }
340 
341  } else {
342  $newFileName = str_replace('{$locale}', $this->locale, $fileName);
343  if (!file_exists($newFileName)) {
344  // Use version from default locale if data file is not available in the selected locale
345  $newFileName = str_replace('{$locale}', INSTALLER_DEFAULT_LOCALE, $fileName);
346  }
347 
348  $this->actions[] = array('type' => $node->getName(), 'file' => $newFileName, 'attr' => $node->getAttributes());
349  }
350  }
351 
352 
353  //
354  // Installer Execution
355  //
356 
362  function executeAction($action) {
363  switch ($action['type']) {
364  case 'schema':
365  $fileName = $action['file'];
366  $this->log(sprintf('schema: %s', $action['file']));
367 
368  $schemaXMLParser = new adoSchema($this->dbconn);
369  $dict = $schemaXMLParser->dict;
370  $sql = $schemaXMLParser->parseSchema($fileName);
371  $schemaXMLParser->destroy();
372 
373  if ($sql) {
374  return $this->executeSQL($sql);
375  } else {
376  $this->setError(INSTALLER_ERROR_DB, str_replace('{$file}', $fileName, __('installer.installParseDBFileError')));
377  return false;
378  }
379  break;
380  case 'data':
381  $fileName = $action['file'];
382  $condition = isset($action['attr']['condition'])?$action['attr']['condition']:null;
383  $includeAction = true;
384  if ($condition) {
385  // Create a new scope to evaluate the condition
386  $evalFunction = function($installer, $action) use ($condition) {
387  return eval($condition);
388  };
389  $includeAction = $evalFunction($this, $action);
390  }
391  $this->log('data: ' . $action['file'] . ($includeAction?'':' (skipped)'));
392  if (!$includeAction) break;
393 
394  $sql = $this->dataXMLParser->parseData($fileName);
395  // We might get an empty SQL if the upgrade script has
396  // been executed before.
397  if ($sql) {
398  return $this->executeSQL($sql);
399  }
400  break;
401  case 'migration':
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();
408  try {
409  $migration->up();
410  $this->migrations[] = $migration;
411  } catch (Exception $e) {
412  // Log an error message
413  $this->setError(INSTALLER_ERROR_DB, $e->getMessage());
414 
415  // Back out already-executed migrations.
416  while ($previousMigration = array_pop($this->migrations)) {
417  try {
418  $previousMigration->down();
419  } catch (PKP\install\DowngradeNotSupportedException $e) {
420  break;
421  }
422  }
423  return false;
424  }
425  return true;
426  case 'code':
427  $condition = isset($action['attr']['condition'])?$action['attr']['condition']:null;
428  $includeAction = true;
429  if ($condition) {
430  // Create a new scope to evaluate the condition
431  $evalFunction = function($installer, $action) use ($condition) {
432  return eval($condition);
433  };
434  $includeAction = $evalFunction($this, $action);
435  }
436  $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']));
437  if (!$includeAction) return true; // Condition not met; skip the action.
438 
439  if (isset($action['file'])) {
440  require_once($action['file']);
441  }
442  if (isset($action['attr']['class'])) {
443  return call_user_func(array($action['attr']['class'], $action['attr']['function']), $this, $action['attr']);
444  } else {
445  return call_user_func(array($this, $action['attr']['function']), $this, $action['attr']);
446  }
447  break;
448  case 'note':
449  $this->log(sprintf('note: %s', $action['file']));
450  $this->notes[] = join('', file($action['file']));
451  break;
452  }
453 
454  return true;
455  }
456 
462  function executeSQL($sql) {
463  if (is_array($sql)) {
464  foreach($sql as $stmt) {
465  if (!$this->executeSQL($stmt)) {
466  return false;
467  }
468  }
469  } else {
470  $this->dbconn->execute($sql);
471  if ($this->dbconn->errorNo() != 0) {
472  $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
473  return false;
474  }
475  }
476 
477  return true;
478  }
479 
485  function updateConfig($configParams) {
486  // Update config file
487  $configParser = new ConfigParser();
488  if (!$configParser->updateConfig(Config::getConfigFileName(), $configParams)) {
489  // Error reading config file
490  $this->setError(INSTALLER_ERROR_GENERAL, 'installer.configFileError');
491  return false;
492  }
493 
494  $this->configContents = $configParser->getFileContents();
495  if (!$configParser->writeConfig(Config::getConfigFileName())) {
496  $this->wroteConfig = false;
497  }
498 
499  return true;
500  }
501 
502 
503  //
504  // Accessors
505  //
506 
512  function getParam($name) {
513  return isset($this->params[$name]) ? $this->params[$name] : null;
514  }
515 
520  function getCurrentVersion() {
521  return $this->currentVersion;
522  }
523 
528  function getNewVersion() {
529  return $this->newVersion;
530  }
531 
536  function getSQL() {
537  return $this->sql;
538  }
539 
544  function getNotes() {
545  return $this->notes;
546  }
547 
552  function getConfigContents() {
553  return $this->configContents;
554  }
555 
560  function wroteConfig() {
561  return $this->wroteConfig;
562  }
563 
572  function getErrorType() {
573  return isset($this->errorType) ? $this->errorType : 0;
574  }
575 
582  function getErrorMsg() {
583  return $this->errorMsg;
584  }
585 
590  function getErrorString() {
591  switch ($this->getErrorType()) {
592  case INSTALLER_ERROR_DB:
593  return 'DB: ' . $this->getErrorMsg();
594  default:
595  return __($this->getErrorMsg());
596  }
597  }
598 
604  function setError($type, $msg) {
605  $this->errorType = $type;
606  $this->errorMsg = $msg;
607  }
608 
613  function setLogger($logger) {
614  $this->logger = $logger;
615  }
616 
622  function clearDataCache() {
623  $cacheManager = CacheManager::getManager();
624  $cacheManager->flush(null, CACHE_TYPE_FILE);
625  $cacheManager->flush(null, CACHE_TYPE_OBJECT);
626  return true;
627  }
628 
633  function setCurrentVersion($version) {
634  $this->currentVersion = $version;
635  }
636 
644  function installEmailTemplate($installer, $attr) {
645  $locales = explode(',', $attr['locales']);
646  foreach ($locales as $locale) AppLocale::requireComponents(LOCALE_COMPONENT_APP_EMAIL, $locale);
647  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
648  $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), $locales, false, $attr['key']);
649  return true;
650  }
651 
657  function installFilterConfig($filterConfigFile) {
658  static $filterHelper = false;
659 
660  // Parse the filter configuration.
661  $xmlParser = new XMLParser();
662  $tree = $xmlParser->parse($filterConfigFile);
663 
664  // Validate the filter configuration.
665  if (!$tree) return false;
666 
667  // Get the filter helper.
668  if ($filterHelper === false) {
669  import('lib.pkp.classes.filter.FilterHelper');
670  $filterHelper = new FilterHelper();
671  }
672 
673  // Are there any filter groups to be installed?
674  $filterGroupsNode = $tree->getChildByName('filterGroups');
675  if (is_a($filterGroupsNode, 'XMLNode')) {
676  $filterHelper->installFilterGroups($filterGroupsNode);
677  }
678 
679  // Are there any filters to be installed?
680  $filtersNode = $tree->getChildByName('filters');
681  if (is_a($filtersNode, 'XMLNode')) {
682  foreach ($filtersNode->getChildren() as $filterNode) { /* @var $filterNode XMLNode */
683  $filterHelper->configureFilter($filterNode);
684  }
685  }
686 
687  return true;
688  }
689 
697  function columnExists($tableName, $columnName) {
698  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
699  $dataSource = $siteDao->getDataSource();
700  $dict = NewDataDictionary($dataSource);
701 
702  // Make sure the table exists
703  $tables = $dict->MetaTables('TABLES', false);
704  if (!in_array($tableName, $tables)) return false;
705 
706  // Check to see whether it contains the specified column.
707  // Oddly, MetaColumnNames doesn't appear to be available.
708  $columns = $dict->MetaColumns($tableName);
709  foreach ($columns as $column) {
710  if ($column->name == $columnName) return true;
711  }
712  return false;
713  }
714 
721  function tableExists($tableName) {
722  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
723  $dataSource = $siteDao->getDataSource();
724  $dict = NewDataDictionary($dataSource);
725 
726  // Check whether the table exists.
727  $tables = $dict->MetaTables('TABLES', false);
728  return in_array($tableName, $tables);
729  }
730 
736  function addPluginVersions() {
737  $versionDao = DAORegistry::getDAO('VersionDAO'); /* @var $versionDao VersionDAO */
738  import('lib.pkp.classes.site.VersionCheck');
739  $fileManager = new FileManager();
740  $categories = PluginRegistry::getCategories();
741  foreach ($categories as $category) {
742  PluginRegistry::loadCategory($category);
743  $plugins = PluginRegistry::getPlugins($category);
744  if (!empty($plugins)) {
745  foreach ($plugins as $plugin) {
746  $versionFile = $plugin->getPluginPath() . '/version.xml';
747 
748  if ($fileManager->fileExists($versionFile)) {
749  $versionInfo = VersionCheck::parseVersionXML($versionFile);
750  $pluginVersion = $versionInfo['version'];
751  } else {
752  $pluginVersion = new Version(
753  1, 0, 0, 0, // Major, minor, revision, build
754  Core::getCurrentDate(), // Date installed
755  1, // Current
756  'plugins.'.$category, // Type
757  basename($plugin->getPluginPath()), // Product
758  '', // Class name
759  0, // Lazy load
760  $plugin->isSitePlugin() // Site wide
761  );
762  }
763  $versionDao->insertVersion($pluginVersion, true);
764  }
765  }
766  }
767 
768  return true;
769  }
770 
777  function abort($installer, $attr) {
778  $installer->setError(INSTALLER_ERROR_GENERAL, $attr['message']);
779  return false;
780  }
781 
786  function installDefaultNavigationMenus() {
787  $contextDao = Application::getContextDAO();
788  $navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO'); /* @var $navigationMenuDao NavigationMenuDAO */
789 
790  $contexts = $contextDao->getAll();
791  while ($context = $contexts->next()) {
792  $navigationMenuDao->installSettings($context->getId(), 'registry/navigationMenus.xml');
793  }
794 
795  $navigationMenuDao->installSettings(CONTEXT_ID_NONE, 'registry/navigationMenus.xml');
796 
797  return true;
798  }
799 
804  function checkPhpVersion() {
805  if (version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1) return true;
806 
807  $this->setError(INSTALLER_ERROR_GENERAL, 'installer.unsupportedPhpError');
808  return false;
809  }
810 
811  /*
812  * Migrate site locale settings to a serialized array in the database
813  */
814  function migrateSiteLocales() {
815  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
816 
817  $result = $siteDao->retrieve('SELECT installed_locales, supported_locales FROM site');
818 
819  $set = $params = [];
820  $row = $result->GetRowAssoc(false);
821  $type = 'array';
822  foreach ($row as $column => $value) {
823  if (!empty($value)) {
824  $set[] = $column . ' = ?';
825  $params[] = $siteDao->convertToDB(explode(':', $value), $type);
826  }
827  }
828  $siteDao->update('UPDATE site SET ' . join(',', $set), $params);
829 
830  $result->Close();
831 
832  return true;
833  }
834 
840  function migrateSidebarBlocks() {
841 
842  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
843  $site = $siteDao->getSite();
844 
845  $plugins = PluginRegistry::loadCategory('blocks');
846  if (empty($plugins)) {
847  return true;
848  }
849 
850  // Sanitize plugin names for use in sql IN().
851  $sanitizedPluginNames = array_map(function($name) {
852  return "'" . preg_replace("/[^A-Za-z0-9]/", '', $name) . "'";
853  }, array_keys($plugins));
854 
855  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */
856  $result = $pluginSettingsDao->retrieve(
857  'SELECT plugin_name, context_id, setting_value FROM plugin_settings WHERE plugin_name IN (' . join(',', $sanitizedPluginNames) . ') AND setting_name=\'context\';'
858  );
859 
860  $sidebarSettings = [];
861  while (!$result->EOF) {
862  $row = $result->getRowAssoc(false);
863  if ($row['setting_value'] != 1) { // BLOCK_CONTEXT_SIDEBAR
864  $result->MoveNext();
865  }
866  $seq = $pluginSettingsDao->getSetting($row['context_id'], $row['plugin_name'], 'seq');
867  if (!isset($sidebarSettings[$row['context_id']])) {
868  $sidebarSettings[$row['context_id']] = [];
869  }
870  $sidebarSettings[$row['context_id']][(int) $seq] = $row['plugin_name'];
871  $result->MoveNext();
872  }
873  $result->Close();
874 
875  foreach ($sidebarSettings as $contextId => $contextSetting) {
876  // Order by sequence
877  ksort($contextSetting);
878  $contextSetting = array_values($contextSetting);
879  if ($contextId) {
880  $contextDao = Application::getContextDAO();
881  $context = $contextDao->getById($contextId);
882  $context->setData('sidebar', $contextSetting);
883  $contextDao->updateObject($context);
884  } else {
885  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
886  $site = $siteDao->getSite();
887  $site->setData('sidebar', $contextSetting);
888  $siteDao->updateObject($site);
889  }
890  }
891 
892  $pluginSettingsDao->update('DELETE FROM plugin_settings WHERE plugin_name IN (' . join(',', $sanitizedPluginNames ) . ') AND (setting_name=\'context\' OR setting_name=\'seq\');');
893 
894  return true;
895  }
896 
901  function migrateMetadataSettings() {
902  $contextDao = Application::getContextDao();
903 
904  $metadataSettings = [
905  'coverage',
906  'languages',
907  'rights',
908  'source',
909  'subjects',
910  'type',
911  'disciplines',
912  'keywords',
913  'agencies',
914  'citations',
915  ];
916 
917  $result = $contextDao->retrieve('SELECT ' . $contextDao->primaryKeyColumn . ' from ' . $contextDao->tableName);
918  $contextIds = [];
919  while (!$result->EOF) {
920  $row = $result->getRowAssoc(false);
921  $contextIds[] = $row[$contextDao->primaryKeyColumn];
922  $result->MoveNext();
923  }
924  $result->Close();
925 
926  foreach ($metadataSettings as $metadataSetting) {
927  foreach ($contextIds as $contextId) {
928  $result = $contextDao->retrieve('
929  SELECT * FROM ' . $contextDao->settingsTableName . ' WHERE
930  ' . $contextDao->primaryKeyColumn . ' = ?
931  AND (
932  setting_name = ?
933  OR setting_name = ?
934  OR setting_name = ?
935  )
936  ',
937  [
938  $contextId,
939  $metadataSetting . 'EnabledWorkflow',
940  $metadataSetting . 'EnabledSubmission',
941  $metadataSetting . 'Required',
942  ]
943  );
944  $value = METADATA_DISABLE;
945  while (!$result->EOF) {
946  $row = $result->getRowAssoc(false);
947  if ($row['setting_name'] === $metadataSetting . 'Required' && $row['setting_value']) {
948  $value = METADATA_REQUIRE;
949  } elseif ($row['setting_name'] === $metadataSetting . 'EnabledSubmission' && $row['setting_value'] && $value !== METADATA_REQUIRE) {
950  $value = METADATA_REQUEST;
951  } elseif ($row['setting_name'] === $metadataSetting . 'EnabledWorkflow' && $row['setting_value'] && $value !== METADATA_REQUEST && $value !== METADATA_REQUIRE) {
952  $value = METADATA_ENABLE;
953  }
954  $result->MoveNext();
955  }
956  $result->Close();
957 
958  if ($value !== METADATA_DISABLE) {
959  $contextDao->update('
960  INSERT INTO ' . $contextDao->settingsTableName . ' (
961  ' . $contextDao->primaryKeyColumn . ',
962  locale,
963  setting_name,
964  setting_value
965  ) VALUES (?, ?, ?, ?)',
966  [
967  $contextId,
968  '',
969  $metadataSetting,
970  $value,
971  ]
972  );
973  }
974 
975  $contextDao->update('
976  DELETE FROM ' . $contextDao->settingsTableName . ' WHERE
977  ' . $contextDao->primaryKeyColumn . ' = ?
978  AND (
979  setting_name = ?
980  OR setting_name = ?
981  OR setting_name = ?
982  )
983  ',
984  [
985  $contextId,
986  $metadataSetting . 'EnabledWorkflow',
987  $metadataSetting . 'EnabledSubmission',
988  $metadataSetting . 'Required',
989  ]
990  );
991  }
992  }
993 
994  return true;
995  }
996 
1001  public function setStatsEmailSettings() {
1002  import('lib.pkp.classes.notification.PKPNotification'); // NOTIFICATION_TYPE_EDITORIAL_REPORT
1003  $roleIds = [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR];
1004 
1005  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
1006  $notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO'); /* @var $notificationSubscriptionSettingsDao NotificationSubscriptionSettingsDAO */
1007  for ($contexts = Application::get()->getContextDAO()->getAll(true); $context = $contexts->next(); ) {
1008  foreach ($roleIds as $roleId) {
1009  for ($userGroups = $userGroupDao->getByRoleId($context->getId(), $roleId); $userGroup = $userGroups->next(); ) {
1010  for ($users = $userGroupDao->getUsersById($userGroup->getId(), $context->getId()); $user = $users->next(); ) {
1011  $notificationSubscriptionSettingsDao->update(
1012  'INSERT INTO notification_subscription_settings
1013  (setting_name, setting_value, user_id, context, setting_type)
1014  VALUES
1015  (?, ?, ?, ?, ?)',
1016  array(
1017  'blocked_emailed_notification',
1018  NOTIFICATION_TYPE_EDITORIAL_REPORT,
1019  $user->getId(),
1020  $context->getId(),
1021  'int'
1022  )
1023  );
1024  }
1025  }
1026  }
1027  }
1028 
1029  return true;
1030  }
1031 
1037  public function fixLibraryFiles() {
1038  import('classes.file.LibraryFileManager');
1039  // Fetch all library files (no method currently in LibraryFileDAO for this)
1040  $libraryFileDao = DAORegistry::getDAO('LibraryFileDAO'); /* @var $libraryFileDao LibraryFileDAO */
1041  $result = $libraryFileDao->retrieve('SELECT * FROM library_files');
1042  $libraryFiles = new DAOResultFactory($result, $libraryFileDao, '_fromRow', array('id'));
1043  $wrongFiles = array();
1044  while ($libraryFile = $libraryFiles->next()) {
1045  $libraryFileManager = new LibraryFileManager($libraryFile->getContextId());
1046  $wrongFilePath = $libraryFileManager->getBasePath() . $libraryFile->getOriginalFileName();
1047  $rightFilePath = $libraryFile->getFilePath();
1048 
1049  if (isset($wrongFiles[$wrongFilePath])) {
1050  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.');
1051  } else {
1052  $wrongFiles[$wrongFilePath] = $libraryFile;
1053  }
1054 
1055  // For all files for which the "wrong" filename exists and the "right" filename doesn't,
1056  // copy the "wrong" file over to the "right" one. This will leave the "wrong" file in
1057  // place, and won't disambiguate cases for which files were clobbered.
1058  if (file_exists($wrongFilePath) && !file_exists($rightFilePath)) {
1059  $libraryFileManager->copyFile($wrongFilePath, $rightFilePath);
1060  }
1061  }
1062  return true;
1063  }
1064 }
Installer\isUpgrade
isUpgrade()
Definition: Installer.inc.php:171
PluginRegistry\loadAllPlugins
static loadAllPlugins($enabledOnly=false)
Definition: PluginRegistry.inc.php:208
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:137
PKPLocale\getAllLocales
static & getAllLocales()
Definition: PKPLocale.inc.php:537
Installer\$dbconn
$dbconn
Definition: Installer.inc.php:70
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
Installer\$logger
$logger
Definition: Installer.inc.php:136
Config\getConfigFileName
static getConfigFileName()
Definition: Config.inc.php:86
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
PluginRegistry\getPlugins
static & getPlugins($category=null)
Definition: PluginRegistry.inc.php:30
Installer\migrateSidebarBlocks
migrateSidebarBlocks()
Definition: Installer.inc.php:894
Installer\migrateMetadataSettings
migrateMetadataSettings()
Definition: Installer.inc.php:955
Installer\$params
$params
Definition: Installer.inc.php:52
PKP
Installer\executeSQL
executeSQL($sql)
Definition: Installer.inc.php:516
Installer\installEmailTemplate
installEmailTemplate($installer, $attr)
Definition: Installer.inc.php:698
Installer\__construct
__construct($descriptor, $params=array(), $isPlugin=false)
Definition: Installer.inc.php:150
Installer\$dataXMLParser
$dataXMLParser
Definition: Installer.inc.php:88
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Installer\getParam
getParam($name)
Definition: Installer.inc.php:566
Installer\setError
setError($type, $msg)
Definition: Installer.inc.php:658
Installer\setCurrentVersion
setCurrentVersion($version)
Definition: Installer.inc.php:687
Installer\addPluginVersions
addPluginVersions()
Definition: Installer.inc.php:790
Installer\$migrations
$migrations
Definition: Installer.inc.php:142
Installer\$installedLocales
$installedLocales
Definition: Installer.inc.php:82
Installer\migrateSiteLocales
migrateSiteLocales()
Definition: Installer.inc.php:868
Version
Describes system version history.
Definition: Version.inc.php:18
Installer\tableExists
tableExists($tableName)
Definition: Installer.inc.php:775
Installer\preInstall
preInstall()
Definition: Installer.inc.php:186
Installer\updateConfig
updateConfig($configParams)
Definition: Installer.inc.php:539
Installer\getNewVersion
getNewVersion()
Definition: Installer.inc.php:582
Installer\$notes
$notes
Definition: Installer.inc.php:106
Installer\setStatsEmailSettings
setStatsEmailSettings()
Definition: Installer.inc.php:1055
Installer\getSQL
getSQL()
Definition: Installer.inc.php:590
Installer\getErrorType
getErrorType()
Definition: Installer.inc.php:626
Installer\installFilterConfig
installFilterConfig($filterConfigFile)
Definition: Installer.inc.php:711
Installer\clearDataCache
clearDataCache()
Definition: Installer.inc.php:676
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
Installer\checkPhpVersion
checkPhpVersion()
Definition: Installer.inc.php:858
ConfigParser
Class for parsing and modifying php.ini style configuration files.
Definition: ConfigParser.inc.php:17
Installer\getCurrentVersion
getCurrentVersion()
Definition: Installer.inc.php:574
Installer\abort
abort($installer, $attr)
Definition: Installer.inc.php:831
Installer\destroy
destroy()
Definition: Installer.inc.php:178
CacheManager\getManager
static getManager()
Definition: CacheManager.inc.php:27
Installer\fixLibraryFiles
fixLibraryFiles()
Definition: Installer.inc.php:1091
Installer\getErrorString
getErrorString()
Definition: Installer.inc.php:644
DBDataXMLParser
Class to import and export database data from an XML format. See dbscripts/xml/dtd/xmldata....
Definition: DBDataXMLParser.inc.php:20
Installer\$isPlugin
$isPlugin
Definition: Installer.inc.php:46
Installer\getConfigContents
getConfigContents()
Definition: Installer.inc.php:606
Installer\log
log($message)
Definition: Installer.inc.php:269
Installer\addInstallAction
addInstallAction($node)
Definition: Installer.inc.php:382
Installer\wroteConfig
wroteConfig()
Definition: Installer.inc.php:614
Installer\postInstall
postInstall()
Definition: Installer.inc.php:257
Installer\$currentVersion
$currentVersion
Definition: Installer.inc.php:58
Installer\$actions
$actions
Definition: Installer.inc.php:94
LibraryFileManager
Wrapper class for uploading files to a site/context' library directory.
Definition: LibraryFileManager.inc.php:18
CACHE_TYPE_FILE
const CACHE_TYPE_FILE
Definition: CacheManager.inc.php:19
Installer\$configContents
$configContents
Definition: Installer.inc.php:112
Installer\executeAction
executeAction($action)
Definition: Installer.inc.php:416
Installer\$sql
$sql
Definition: Installer.inc.php:100
Installer\$descriptor
$descriptor
Definition: Installer.inc.php:40
Installer\$wroteConfig
$wroteConfig
Definition: Installer.inc.php:118
PluginRegistry\getCategories
static getCategories()
Definition: PluginRegistry.inc.php:196
XMLParser
Generic class for parsing an XML document into a data structure.
Definition: XMLParser.inc.php:28
Installer\columnExists
columnExists($tableName, $columnName)
Definition: Installer.inc.php:751
Installer\setLogger
setLogger($logger)
Definition: Installer.inc.php:667
Installer\execute
execute()
Definition: Installer.inc.php:228
Installer\$newVersion
$newVersion
Definition: Installer.inc.php:64
Version\fromString
static fromString($versionString, $productType=null, $product=null, $productClass='', $lazyLoad=0, $sitewide=1)
Definition: Version.inc.php:67
Installer\executeInstaller
executeInstaller()
Definition: Installer.inc.php:316
Installer\parseInstallNodes
parseInstallNodes($installTree)
Definition: Installer.inc.php:357
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
Installer\$errorMsg
$errorMsg
Definition: Installer.inc.php:130
Installer\installDefaultNavigationMenus
installDefaultNavigationMenus()
Definition: Installer.inc.php:840
Installer
Base class for install and upgrade scripts.
Definition: Installer.inc.php:34
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
Installer\getErrorMsg
getErrorMsg()
Definition: Installer.inc.php:636
FileManager
Class defining basic operations for file management.
Definition: FileManager.inc.php:35
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
Installer\getNotes
getNotes()
Definition: Installer.inc.php:598
DBConnection\getInstance
static getInstance($setInstance=null)
Definition: DBConnection.inc.php:241
FilterHelper
Class that provides filter-related helper methods.
Definition: FilterHelper.inc.php:15
Installer\$locale
$locale
Definition: Installer.inc.php:76
Installer\updateVersion
updateVersion()
Definition: Installer.inc.php:334
Installer\parseInstaller
parseInstaller()
Definition: Installer.inc.php:284
CACHE_TYPE_OBJECT
const CACHE_TYPE_OBJECT
Definition: CacheManager.inc.php:20
VersionCheck\parseVersionXML
static parseVersionXML($url)
Definition: VersionCheck.inc.php:74
Installer\$errorType
$errorType
Definition: Installer.inc.php:124