Open Preprint 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  $previousMigration->down();
418  }
419  return false;
420  }
421  return true;
422  case 'code':
423  $condition = isset($action['attr']['condition'])?$action['attr']['condition']:null;
424  $includeAction = true;
425  if ($condition) {
426  // Create a new scope to evaluate the condition
427  $evalFunction = function($installer, $action) use ($condition) {
428  return eval($condition);
429  };
430  $includeAction = $evalFunction($this, $action);
431  }
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; // Condition not met; skip the action.
434 
435  if (isset($action['file'])) {
436  require_once($action['file']);
437  }
438  if (isset($action['attr']['class'])) {
439  return call_user_func(array($action['attr']['class'], $action['attr']['function']), $this, $action['attr']);
440  } else {
441  return call_user_func(array($this, $action['attr']['function']), $this, $action['attr']);
442  }
443  break;
444  case 'note':
445  $this->log(sprintf('note: %s', $action['file']));
446  $this->notes[] = join('', file($action['file']));
447  break;
448  }
449 
450  return true;
451  }
452 
458  function executeSQL($sql) {
459  if (is_array($sql)) {
460  foreach($sql as $stmt) {
461  if (!$this->executeSQL($stmt)) {
462  return false;
463  }
464  }
465  } else {
466  $this->dbconn->execute($sql);
467  if ($this->dbconn->errorNo() != 0) {
468  $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
469  return false;
470  }
471  }
472 
473  return true;
474  }
475 
481  function updateConfig($configParams) {
482  // Update config file
483  $configParser = new ConfigParser();
484  if (!$configParser->updateConfig(Config::getConfigFileName(), $configParams)) {
485  // Error reading config file
486  $this->setError(INSTALLER_ERROR_GENERAL, 'installer.configFileError');
487  return false;
488  }
489 
490  $this->configContents = $configParser->getFileContents();
491  if (!$configParser->writeConfig(Config::getConfigFileName())) {
492  $this->wroteConfig = false;
493  }
494 
495  return true;
496  }
497 
498 
499  //
500  // Accessors
501  //
502 
508  function getParam($name) {
509  return isset($this->params[$name]) ? $this->params[$name] : null;
510  }
511 
516  function getCurrentVersion() {
517  return $this->currentVersion;
518  }
519 
524  function getNewVersion() {
525  return $this->newVersion;
526  }
527 
532  function getSQL() {
533  return $this->sql;
534  }
535 
540  function getNotes() {
541  return $this->notes;
542  }
543 
548  function getConfigContents() {
549  return $this->configContents;
550  }
551 
556  function wroteConfig() {
557  return $this->wroteConfig;
558  }
559 
568  function getErrorType() {
569  return isset($this->errorType) ? $this->errorType : 0;
570  }
571 
578  function getErrorMsg() {
579  return $this->errorMsg;
580  }
581 
586  function getErrorString() {
587  switch ($this->getErrorType()) {
588  case INSTALLER_ERROR_DB:
589  return 'DB: ' . $this->getErrorMsg();
590  default:
591  return __($this->getErrorMsg());
592  }
593  }
594 
600  function setError($type, $msg) {
601  $this->errorType = $type;
602  $this->errorMsg = $msg;
603  }
604 
609  function setLogger($logger) {
610  $this->logger = $logger;
611  }
612 
618  function clearDataCache() {
619  $cacheManager = CacheManager::getManager();
620  $cacheManager->flush(null, CACHE_TYPE_FILE);
621  $cacheManager->flush(null, CACHE_TYPE_OBJECT);
622  return true;
623  }
624 
629  function setCurrentVersion($version) {
630  $this->currentVersion = $version;
631  }
632 
640  function installEmailTemplate($installer, $attr) {
641  $locales = explode(',', $attr['locales']);
642  foreach ($locales as $locale) AppLocale::requireComponents(LOCALE_COMPONENT_APP_EMAIL, $locale);
643  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO'); /* @var $emailTemplateDao EmailTemplateDAO */
644  $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), $locales, false, $attr['key']);
645  return true;
646  }
647 
653  function installFilterConfig($filterConfigFile) {
654  static $filterHelper = false;
655 
656  // Parse the filter configuration.
657  $xmlParser = new XMLParser();
658  $tree = $xmlParser->parse($filterConfigFile);
659 
660  // Validate the filter configuration.
661  if (!$tree) return false;
662 
663  // Get the filter helper.
664  if ($filterHelper === false) {
665  import('lib.pkp.classes.filter.FilterHelper');
666  $filterHelper = new FilterHelper();
667  }
668 
669  // Are there any filter groups to be installed?
670  $filterGroupsNode = $tree->getChildByName('filterGroups');
671  if (is_a($filterGroupsNode, 'XMLNode')) {
672  $filterHelper->installFilterGroups($filterGroupsNode);
673  }
674 
675  // Are there any filters to be installed?
676  $filtersNode = $tree->getChildByName('filters');
677  if (is_a($filtersNode, 'XMLNode')) {
678  foreach ($filtersNode->getChildren() as $filterNode) { /* @var $filterNode XMLNode */
679  $filterHelper->configureFilter($filterNode);
680  }
681  }
682 
683  return true;
684  }
685 
693  function columnExists($tableName, $columnName) {
694  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
695  $dataSource = $siteDao->getDataSource();
696  $dict = NewDataDictionary($dataSource);
697 
698  // Make sure the table exists
699  $tables = $dict->MetaTables('TABLES', false);
700  if (!in_array($tableName, $tables)) return false;
701 
702  // Check to see whether it contains the specified column.
703  // Oddly, MetaColumnNames doesn't appear to be available.
704  $columns = $dict->MetaColumns($tableName);
705  foreach ($columns as $column) {
706  if ($column->name == $columnName) return true;
707  }
708  return false;
709  }
710 
717  function tableExists($tableName) {
718  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
719  $dataSource = $siteDao->getDataSource();
720  $dict = NewDataDictionary($dataSource);
721 
722  // Check whether the table exists.
723  $tables = $dict->MetaTables('TABLES', false);
724  return in_array($tableName, $tables);
725  }
726 
732  function addPluginVersions() {
733  $versionDao = DAORegistry::getDAO('VersionDAO'); /* @var $versionDao VersionDAO */
734  import('lib.pkp.classes.site.VersionCheck');
735  $fileManager = new FileManager();
736  $categories = PluginRegistry::getCategories();
737  foreach ($categories as $category) {
738  PluginRegistry::loadCategory($category);
739  $plugins = PluginRegistry::getPlugins($category);
740  if (!empty($plugins)) {
741  foreach ($plugins as $plugin) {
742  $versionFile = $plugin->getPluginPath() . '/version.xml';
743 
744  if ($fileManager->fileExists($versionFile)) {
745  $versionInfo = VersionCheck::parseVersionXML($versionFile);
746  $pluginVersion = $versionInfo['version'];
747  } else {
748  $pluginVersion = new Version(
749  1, 0, 0, 0, // Major, minor, revision, build
750  Core::getCurrentDate(), // Date installed
751  1, // Current
752  'plugins.'.$category, // Type
753  basename($plugin->getPluginPath()), // Product
754  '', // Class name
755  0, // Lazy load
756  $plugin->isSitePlugin() // Site wide
757  );
758  }
759  $versionDao->insertVersion($pluginVersion, true);
760  }
761  }
762  }
763 
764  return true;
765  }
766 
773  function abort($installer, $attr) {
774  $installer->setError(INSTALLER_ERROR_GENERAL, $attr['message']);
775  return false;
776  }
777 
782  function installDefaultNavigationMenus() {
783  $contextDao = Application::getContextDAO();
784  $navigationMenuDao = DAORegistry::getDAO('NavigationMenuDAO'); /* @var $navigationMenuDao NavigationMenuDAO */
785 
786  $contexts = $contextDao->getAll();
787  while ($context = $contexts->next()) {
788  $navigationMenuDao->installSettings($context->getId(), 'registry/navigationMenus.xml');
789  }
790 
791  $navigationMenuDao->installSettings(CONTEXT_ID_NONE, 'registry/navigationMenus.xml');
792 
793  return true;
794  }
795 
800  function checkPhpVersion() {
801  if (version_compare(PHP_REQUIRED_VERSION, PHP_VERSION) != 1) return true;
802 
803  $this->setError(INSTALLER_ERROR_GENERAL, 'installer.unsupportedPhpError');
804  return false;
805  }
806 
807  /*
808  * Migrate site locale settings to a serialized array in the database
809  */
810  function migrateSiteLocales() {
811  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
812 
813  $result = $siteDao->retrieve('SELECT installed_locales, supported_locales FROM site');
814 
815  $set = $params = [];
816  $row = $result->GetRowAssoc(false);
817  $type = 'array';
818  foreach ($row as $column => $value) {
819  if (!empty($value)) {
820  $set[] = $column . ' = ?';
821  $params[] = $siteDao->convertToDB(explode(':', $value), $type);
822  }
823  }
824  $siteDao->update('UPDATE site SET ' . join(',', $set), $params);
825 
826  $result->Close();
827 
828  return true;
829  }
830 
836  function migrateSidebarBlocks() {
837 
838  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
839  $site = $siteDao->getSite();
840 
841  $plugins = PluginRegistry::loadCategory('blocks');
842  if (empty($plugins)) {
843  return true;
844  }
845 
846  // Sanitize plugin names for use in sql IN().
847  $sanitizedPluginNames = array_map(function($name) {
848  return "'" . preg_replace("/[^A-Za-z0-9]/", '', $name) . "'";
849  }, array_keys($plugins));
850 
851  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO'); /* @var $pluginSettingsDao PluginSettingsDAO */
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\';'
854  );
855 
856  $sidebarSettings = [];
857  while (!$result->EOF) {
858  $row = $result->getRowAssoc(false);
859  if ($row['setting_value'] != 1) { // BLOCK_CONTEXT_SIDEBAR
860  $result->MoveNext();
861  }
862  $seq = $pluginSettingsDao->getSetting($row['context_id'], $row['plugin_name'], 'seq');
863  if (!isset($sidebarSettings[$row['context_id']])) {
864  $sidebarSettings[$row['context_id']] = [];
865  }
866  $sidebarSettings[$row['context_id']][(int) $seq] = $row['plugin_name'];
867  $result->MoveNext();
868  }
869  $result->Close();
870 
871  foreach ($sidebarSettings as $contextId => $contextSetting) {
872  // Order by sequence
873  ksort($contextSetting);
874  $contextSetting = array_values($contextSetting);
875  if ($contextId) {
876  $contextDao = Application::getContextDAO();
877  $context = $contextDao->getById($contextId);
878  $context->setData('sidebar', $contextSetting);
879  $contextDao->updateObject($context);
880  } else {
881  $siteDao = DAORegistry::getDAO('SiteDAO'); /* @var $siteDao SiteDAO */
882  $site = $siteDao->getSite();
883  $site->setData('sidebar', $contextSetting);
884  $siteDao->updateObject($site);
885  }
886  }
887 
888  $pluginSettingsDao->update('DELETE FROM plugin_settings WHERE plugin_name IN (' . join(',', $sanitizedPluginNames ) . ') AND (setting_name=\'context\' OR setting_name=\'seq\');');
889 
890  return true;
891  }
892 
897  function migrateMetadataSettings() {
898  $contextDao = Application::getContextDao();
899 
900  $metadataSettings = [
901  'coverage',
902  'languages',
903  'rights',
904  'source',
905  'subjects',
906  'type',
907  'disciplines',
908  'keywords',
909  'agencies',
910  'citations',
911  ];
912 
913  $result = $contextDao->retrieve('SELECT ' . $contextDao->primaryKeyColumn . ' from ' . $contextDao->tableName);
914  $contextIds = [];
915  while (!$result->EOF) {
916  $row = $result->getRowAssoc(false);
917  $contextIds[] = $row[$contextDao->primaryKeyColumn];
918  $result->MoveNext();
919  }
920  $result->Close();
921 
922  foreach ($metadataSettings as $metadataSetting) {
923  foreach ($contextIds as $contextId) {
924  $result = $contextDao->retrieve('
925  SELECT * FROM ' . $contextDao->settingsTableName . ' WHERE
926  ' . $contextDao->primaryKeyColumn . ' = ?
927  AND (
928  setting_name = ?
929  OR setting_name = ?
930  OR setting_name = ?
931  )
932  ',
933  [
934  $contextId,
935  $metadataSetting . 'EnabledWorkflow',
936  $metadataSetting . 'EnabledSubmission',
937  $metadataSetting . 'Required',
938  ]
939  );
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;
949  }
950  $result->MoveNext();
951  }
952  $result->Close();
953 
954  if ($value !== METADATA_DISABLE) {
955  $contextDao->update('
956  INSERT INTO ' . $contextDao->settingsTableName . ' (
957  ' . $contextDao->primaryKeyColumn . ',
958  locale,
959  setting_name,
960  setting_value
961  ) VALUES (?, ?, ?, ?)',
962  [
963  $contextId,
964  '',
965  $metadataSetting,
966  $value,
967  ]
968  );
969  }
970 
971  $contextDao->update('
972  DELETE FROM ' . $contextDao->settingsTableName . ' WHERE
973  ' . $contextDao->primaryKeyColumn . ' = ?
974  AND (
975  setting_name = ?
976  OR setting_name = ?
977  OR setting_name = ?
978  )
979  ',
980  [
981  $contextId,
982  $metadataSetting . 'EnabledWorkflow',
983  $metadataSetting . 'EnabledSubmission',
984  $metadataSetting . 'Required',
985  ]
986  );
987  }
988  }
989 
990  return true;
991  }
992 
997  public function setStatsEmailSettings() {
998  import('lib.pkp.classes.notification.PKPNotification'); // NOTIFICATION_TYPE_EDITORIAL_REPORT
999  $roleIds = [ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR];
1000 
1001  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
1002  $notificationSubscriptionSettingsDao = DAORegistry::getDAO('NotificationSubscriptionSettingsDAO'); /* @var $notificationSubscriptionSettingsDao 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)
1010  VALUES
1011  (?, ?, ?, ?, ?)',
1012  array(
1013  'blocked_emailed_notification',
1014  NOTIFICATION_TYPE_EDITORIAL_REPORT,
1015  $user->getId(),
1016  $context->getId(),
1017  'int'
1018  )
1019  );
1020  }
1021  }
1022  }
1023  }
1024 
1025  return true;
1026  }
1027 
1033  public function fixLibraryFiles() {
1034  import('classes.file.LibraryFileManager');
1035  // Fetch all library files (no method currently in LibraryFileDAO for this)
1036  $libraryFileDao = DAORegistry::getDAO('LibraryFileDAO'); /* @var $libraryFileDao LibraryFileDAO */
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()) {
1041  $libraryFileManager = new LibraryFileManager($libraryFile->getContextId());
1042  $wrongFilePath = $libraryFileManager->getBasePath() . $libraryFile->getOriginalFileName();
1043  $rightFilePath = $libraryFile->getFilePath();
1044 
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.');
1047  } else {
1048  $wrongFiles[$wrongFilePath] = $libraryFile;
1049  }
1050 
1051  // For all files for which the "wrong" filename exists and the "right" filename doesn't,
1052  // copy the "wrong" file over to the "right" one. This will leave the "wrong" file in
1053  // place, and won't disambiguate cases for which files were clobbered.
1054  if (file_exists($wrongFilePath) && !file_exists($rightFilePath)) {
1055  $libraryFileManager->copyFile($wrongFilePath, $rightFilePath);
1056  }
1057  }
1058  return true;
1059  }
1060 }
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:127
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:890
Installer\migrateMetadataSettings
migrateMetadataSettings()
Definition: Installer.inc.php:951
Installer\$params
$params
Definition: Installer.inc.php:52
Installer\executeSQL
executeSQL($sql)
Definition: Installer.inc.php:512
Installer\installEmailTemplate
installEmailTemplate($installer, $attr)
Definition: Installer.inc.php:694
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:562
Installer\setError
setError($type, $msg)
Definition: Installer.inc.php:654
Installer\setCurrentVersion
setCurrentVersion($version)
Definition: Installer.inc.php:683
Installer\addPluginVersions
addPluginVersions()
Definition: Installer.inc.php:786
Installer\$migrations
$migrations
Definition: Installer.inc.php:142
Installer\$installedLocales
$installedLocales
Definition: Installer.inc.php:82
Installer\migrateSiteLocales
migrateSiteLocales()
Definition: Installer.inc.php:864
Version
Describes system version history.
Definition: Version.inc.php:18
Installer\tableExists
tableExists($tableName)
Definition: Installer.inc.php:771
Installer\preInstall
preInstall()
Definition: Installer.inc.php:186
Installer\updateConfig
updateConfig($configParams)
Definition: Installer.inc.php:535
Installer\getNewVersion
getNewVersion()
Definition: Installer.inc.php:578
Installer\$notes
$notes
Definition: Installer.inc.php:106
Installer\setStatsEmailSettings
setStatsEmailSettings()
Definition: Installer.inc.php:1051
Installer\getSQL
getSQL()
Definition: Installer.inc.php:586
Installer\getErrorType
getErrorType()
Definition: Installer.inc.php:622
Installer\installFilterConfig
installFilterConfig($filterConfigFile)
Definition: Installer.inc.php:707
Installer\clearDataCache
clearDataCache()
Definition: Installer.inc.php:672
PluginRegistry\loadCategory
static loadCategory($category, $enabledOnly=false, $mainContextId=null)
Definition: PluginRegistry.inc.php:103
Installer\checkPhpVersion
checkPhpVersion()
Definition: Installer.inc.php:854
ConfigParser
Class for parsing and modifying php.ini style configuration files.
Definition: ConfigParser.inc.php:17
Installer\getCurrentVersion
getCurrentVersion()
Definition: Installer.inc.php:570
Installer\abort
abort($installer, $attr)
Definition: Installer.inc.php:827
Installer\destroy
destroy()
Definition: Installer.inc.php:178
CacheManager\getManager
static getManager()
Definition: CacheManager.inc.php:27
Installer\fixLibraryFiles
fixLibraryFiles()
Definition: Installer.inc.php:1087
Installer\getErrorString
getErrorString()
Definition: Installer.inc.php:640
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:602
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:610
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:747
Installer\setLogger
setLogger($logger)
Definition: Installer.inc.php:663
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:836
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:632
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:594
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