PageRenderTime 70ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/setup/includes/runner/modinstallrunnerweb.class.php

http://github.com/modxcms/revolution
PHP | 152 lines | 152 code | 0 blank | 0 comment | 3 complexity | 4cd0b2360ba79822c6430ed24984ae6c MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. require_once strtr(realpath(MODX_SETUP_PATH.'includes/runner/modinstallrunner.class.php'),'\\','/');
  3. /*
  4. * This file is part of MODX Revolution.
  5. *
  6. * Copyright (c) MODX, LLC. All Rights Reserved.
  7. *
  8. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  9. * files found in the top-level directory of this distribution.
  10. */
  11. class modInstallRunnerWeb extends modInstallRunner {
  12. public function initialize() {
  13. /* set the time limit infinite in case it takes a bit
  14. * TODO: fix this by allowing resume when it takes a long time
  15. */
  16. @ set_time_limit(0);
  17. }
  18. /**
  19. * Execute the installation process.
  20. *
  21. * @param integer $mode The install mode.
  22. * @return array An array of result messages collected during execution.
  23. */
  24. public function execute($mode) {
  25. /* write config file */
  26. $this->writeConfig();
  27. /* get connection */
  28. $this->install->getConnection($mode);
  29. /* run appropriate database routines */
  30. switch ($mode) {
  31. case modInstall::MODE_UPGRADE_REVO :
  32. case modInstall::MODE_UPGRADE_REVO_ADVANCED :
  33. $this->loadVersionInstaller();
  34. $this->versioner->install();
  35. break;
  36. /* new install, create tables */
  37. default :
  38. $modx =& $this->install->xpdo;
  39. $install =& $this->install;
  40. include MODX_SETUP_PATH . 'includes/tables_create.php';
  41. break;
  42. }
  43. if ($this->install->xpdo) {
  44. if (!$this->installPackage()) {
  45. return $this->getResults();
  46. }
  47. $this->updateWorkspace();
  48. $modx =& $this->install->xpdo;
  49. $settings =& $this->install->settings;
  50. $install =& $this->install;
  51. /* if new install */
  52. if ($mode == modInstall::MODE_NEW) {
  53. include MODX_SETUP_PATH.'includes/new.install.php';
  54. /* if upgrade */
  55. } else {
  56. include MODX_SETUP_PATH.'includes/upgrade.install.php';
  57. }
  58. $this->postRun();
  59. $this->success = true;
  60. }
  61. return $this->getResults();
  62. }
  63. /**
  64. * Do post-run cleanups
  65. * @return void
  66. */
  67. public function cleanup() {
  68. /* empty sessions table to prevent old permissions from loading */
  69. $tableName = $this->install->xpdo->getTableName('modSession');
  70. $this->install->xpdo->exec($this->install->driver->truncate($tableName));
  71. /* clear cache */
  72. $this->install->xpdo->cacheManager->deleteTree(MODX_CORE_PATH.'cache/',array(
  73. 'skipDirs' => false,
  74. 'extensions' => array(
  75. '.cache.php',
  76. '.tpl.php',
  77. ),
  78. ));
  79. $this->install->lock();
  80. $this->install->settings->store(array(
  81. 'finished' => true,
  82. ));
  83. }
  84. public function postRun() {
  85. $compressJs = $this->install->settings->get('compress_js');
  86. if ($compressJs === 0) {
  87. /** @var modSystemSetting $setting */
  88. $setting = $this->install->xpdo->getObject('modSystemSetting',array(
  89. 'key' => 'compress_js',
  90. ));
  91. if (empty($setting)) {
  92. $setting = $this->install->xpdo->newObject('modSystemSetting');
  93. $setting->fromArray(array(
  94. 'key' => 'compress_js',
  95. 'xtype' => 'combo-boolean',
  96. 'namespace' => 'core',
  97. 'area' => 'manager',
  98. ),'',true);
  99. }
  100. $setting->set('value',0);
  101. $setting->save();
  102. }
  103. $compressCss = $this->install->settings->get('compress_css');
  104. if ($compressCss === 0) {
  105. /** @var modSystemSetting $setting */
  106. $setting = $this->install->xpdo->getObject('modSystemSetting',array(
  107. 'key' => 'compress_css',
  108. ));
  109. if (empty($setting)) {
  110. $setting = $this->install->xpdo->newObject('modSystemSetting');
  111. $setting->fromArray(array(
  112. 'key' => 'compress_css',
  113. 'xtype' => 'combo-boolean',
  114. 'namespace' => 'core',
  115. 'area' => 'manager',
  116. ),'',true);
  117. }
  118. $setting->set('value',0);
  119. $setting->save();
  120. }
  121. // If the user opted in to send the powered by header, enable the setting here
  122. // The setting is installed disabled by default, so we don't have to force it off if unchecked
  123. $sendPoweredByHeader = $this->install->settings->get('send_poweredby_header');
  124. if (!empty($sendPoweredByHeader)) {
  125. $setting = $this->install->xpdo->getObject('modSystemSetting',array(
  126. 'key' => 'send_poweredby_header',
  127. ));
  128. if ($setting instanceof modSystemSetting) {
  129. $setting->set('value', 1);
  130. $setting->save();
  131. }
  132. }
  133. return true;
  134. }
  135. }