PageRenderTime 24ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/OX/Admin/UI/Install/InstallUtils.php

https://github.com/orchestra-io/sample-openx
PHP | 252 lines | 124 code | 26 blank | 102 comment | 24 complexity | 8c6148234aedbcbd7796236f20ebe25a MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id$
  25. */
  26. require_once MAX_PATH . '/lib/OA/Upgrade/UpgradePluginImport.php';
  27. /**
  28. * @package OX_Admin_UI
  29. * @subpackage Install
  30. * @author Bernard Lange <bernard@openx.org>
  31. */
  32. class OX_Admin_UI_Install_InstallUtils
  33. {
  34. public static $INSTALLER_SESSION_ID = 'ox_install_session_id';
  35. /**
  36. * Returns session storage associated with the installer.
  37. * This session storage is then used by wizard to store installer data
  38. * between the steps.
  39. *
  40. * @return OX_Admin_UI_SessionStorage session storage of installer
  41. */
  42. public static function getSessionStorage()
  43. {
  44. return new OX_Admin_UI_SessionStorage(self::$INSTALLER_SESSION_ID);
  45. }
  46. /**
  47. * Return an array of supported DB types
  48. *
  49. * @return array
  50. */
  51. public static function getSupportedDbTypes()
  52. {
  53. // These values must be the same as used for the
  54. // data access layer file names!
  55. $aTypes = array ();
  56. if (extension_loaded('mysql')) {
  57. $aTypes['mysql'] = 'MySQL';
  58. }
  59. if (extension_loaded('pgsql')) {
  60. $aTypes['pgsql'] = 'PostgreSQL';
  61. }
  62. return $aTypes;
  63. }
  64. /**
  65. * Return an array of supported Table types
  66. *
  67. * @return array
  68. */
  69. public static function getSupportedTableTypes()
  70. {
  71. // These values must be the same as used for the
  72. // data access layer file names!
  73. $aTypes = array ();
  74. if (extension_loaded('mysql')) {
  75. $aTypes['MYISAM'] = 'MyISAM';
  76. $aTypes['INNODB'] = 'InnoDB';
  77. }
  78. if (empty($aTypes)) {
  79. $aTypes[''] = 'Default';
  80. }
  81. return $aTypes;
  82. }
  83. /**
  84. * Checks a folder to make sure it exists and is writable
  85. *
  86. * @param int Folder the directory that needs to be tested
  87. * @return boolean - true if folder exists and is writable
  88. */
  89. public static function checkFolderPermissions($folder)
  90. {
  91. if (!file_exists($folder)) {
  92. return false;
  93. }
  94. elseif (!is_writable($folder)) {
  95. return false;
  96. }
  97. return true;
  98. }
  99. /**
  100. * Checks if upgrader discovered schema which is old and stores stats
  101. * in server time rather than UTC.
  102. *
  103. * @param OA_Upgrade $oUpgrader
  104. */
  105. public static function hasZoneError($oUpgrader)
  106. {
  107. $tzoneErr = false;
  108. if ($oUpgrader->canUpgradeOrInstall()) {
  109. // Timezone support check
  110. if ($oUpgrader->existing_installation_status != OA_STATUS_NOT_INSTALLED) {
  111. if ($oUpgrader->versionInitialSchema['tables_core'] < 538) {
  112. // Non TZ-enabled database
  113. $tzoneErr = true;
  114. }
  115. }
  116. }
  117. return $tzoneErr;
  118. }
  119. /**
  120. * Checks if plugins path can be verified before upgrading. If path to previous
  121. * installation is not correct try to guess one.
  122. *
  123. * List of plugins is determined by looking into config section in the loaded
  124. * config file. (more precisely $GLOBALS['_MAX']['CONF']['plugins'])
  125. *
  126. * Return values is an two element array: ('verified' => boolean, 'path' => string).
  127. * If verified is true, 'path' will be empty.
  128. *
  129. * @return array an array of two elements ('verified' => boolean, 'path' => string).
  130. */
  131. public static function checkPluginsVerified()
  132. {
  133. $verified = true;
  134. $prevPath = '';
  135. if (!empty($GLOBALS['_MAX']['CONF']['plugins'])) {
  136. $oPluginImporter = new OX_UpgradePluginImport();
  137. if (!$oPluginImporter->verifyAll($GLOBALS['_MAX']['CONF']['plugins'])) {
  138. $verified = false;
  139. // See if we can figure out the previous path
  140. if (!empty($GLOBALS['_MAX']['CONF']['store']['webDir'])){
  141. $possPath = dirname(dirname($GLOBALS['_MAX']['CONF']['store']['webDir']));
  142. $oPluginVerifier = new OX_UpgradePluginImport();
  143. $oPluginVerifier->basePath = $possPath;
  144. $oPluginVerifier->destPath = $possPath;
  145. if ($oPluginVerifier->verifyAll($GLOBALS['_MAX']['CONF']['plugins'], false)) {
  146. $prevPath = $possPath;
  147. }
  148. }
  149. }
  150. }
  151. return array('verified' => $verified, 'path' => $prevPath);
  152. }
  153. /**
  154. * Attempts import of plugins from previous installation path.
  155. * List of plugins is determined by looking into config section in the loaded
  156. * config file. (more precisely $GLOBALS['_MAX']['CONF']['plugins'])
  157. *
  158. * Copies plugin related artifacts using OX_UpgradePluginImport->import(..) function.
  159. * Also copies data objects.
  160. *
  161. * '$path' param is considered the source path. MAX path is
  162. * considered the target path.
  163. *
  164. * @param $path an absolute path to previous OpenX installation
  165. * @return boolean false if import failed, true otherwise
  166. */
  167. public static function importPlugins($path)
  168. {
  169. $success = true;
  170. // Prevent directory traversal and other nasty tricks:
  171. $path = str_replace("\\", '/', $path);
  172. $path = rtrim(str_replace("\0", '', $path), '/');
  173. if (!stristr($path, '../')) {
  174. $oPluginImporter = new OX_UpgradePluginImport();
  175. $oPluginImporter->basePath = $path;
  176. if ($oPluginImporter->verifyAll($GLOBALS['_MAX']['CONF']['plugins'], false)) {
  177. // For each plugin that's claimed to be installed... (ex|im)port it into the new codebase
  178. foreach ($GLOBALS['_MAX']['CONF']['plugins'] as $plugin => $enabled) {
  179. $oPluginImporter->import($plugin);
  180. }
  181. // Plugins may also have placed files in the MAX_PATH . /var/plugins folder,
  182. // but these files aren't declared in the XML, for now, copy all files in there up
  183. $DO_DIR = opendir($path . '/var/plugins/DataObjects/');
  184. while ($file = readdir($DO_DIR)) {
  185. if (!is_file($path . '/var/plugins/DataObjects/' . $file)) {
  186. continue;
  187. }
  188. @copy($path . '/var/plugins/DataObjects/' . $file, MAX_PATH . '/var/plugins/DataObjects/' . $file);
  189. }
  190. } else {
  191. $success = false;
  192. }
  193. }
  194. return $success;
  195. }
  196. /**
  197. * Processes upgrader messages and identfies their type (it's by prefix unfortunately...)
  198. * returns an array with errors under 'error' index, warnings under 'warning'
  199. * and other under 'info';
  200. *
  201. * @param unknown_type $aUpgraderMessages
  202. */
  203. public static function getMessagesWithType($aUpgraderMessages)
  204. {
  205. $aErrors = array();
  206. $aWarnings = array();
  207. $aInfos = array();
  208. $sErr = '#! ';
  209. $sWarn = '#> ';
  210. foreach ($aUpgraderMessages AS $key => $message) {
  211. if (substr($message, 0 , 3) == $sErr) {
  212. $message = str_replace($sErr, '', $message);
  213. $aErrors[$key] = $message;
  214. }
  215. else if (substr($message, 0, 3) == $sWarn) {
  216. $message = str_replace($sWarn, '', $message);
  217. $aWarnings[$key] = $message;
  218. }
  219. else {
  220. $aInfos[$key] = $message;
  221. }
  222. }
  223. return array('error' => $aErrors, 'warning' => $aWarnings, 'info' => $aInfos);
  224. }
  225. }
  226. ?>