PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/models/Installer/Requirements.php

https://github.com/libis/Flandrica
PHP | 202 lines | 173 code | 15 blank | 14 comment | 12 complexity | b7540d48d2442efdc50323aea8dd91a5 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @copyright Roy Rosenzweig Center for History and New Media, 2009
  4. * @license http://www.gnu.org/licenses/gpl-3.0.txt
  5. * @package Omeka
  6. * @access private
  7. */
  8. /**
  9. * @internal This implements Omeka internals and is not part of the public API.
  10. * @access private
  11. * @package Omeka
  12. * @copyright Roy Rosenzweig Center for History and New Media, 2009
  13. */
  14. class Installer_Requirements
  15. {
  16. const OMEKA_PHP_VERSION = '5.2.4';
  17. const OMEKA_MYSQL_VERSION = '5.0';
  18. private $_dbAdapter;
  19. private $_storage;
  20. private $_errorMessages = array();
  21. private $_warningMessages = array();
  22. public function check()
  23. {
  24. $this->_checkPhpVersionIsValid();
  25. $this->_checkMysqliIsAvailable();
  26. $this->_checkMysqlVersionIsValid();
  27. $this->_checkHtaccessFilesExist();
  28. $this->_checkRegisterGlobalsIsOff();
  29. $this->_checkExifModuleIsLoaded();
  30. $this->_checkModRewriteIsEnabled();
  31. $this->_checkArchiveStorageSetup();
  32. $this->_checkFileinfoIsLoaded();
  33. }
  34. public function getErrorMessages()
  35. {
  36. return $this->_errorMessages;
  37. }
  38. public function getWarningMessages()
  39. {
  40. return $this->_warningMessages;
  41. }
  42. public function hasError()
  43. {
  44. return (boolean)count($this->getErrorMessages());
  45. }
  46. public function hasWarning()
  47. {
  48. return (boolean)count($this->getWarningMessages());
  49. }
  50. public function setDbAdapter(Zend_Db_Adapter_Abstract $db)
  51. {
  52. $this->_dbAdapter = $db;
  53. }
  54. public function setStorage(Omeka_Storage $storage)
  55. {
  56. $this->_storage = $storage;
  57. }
  58. private function _checkPhpVersionIsValid()
  59. {
  60. if (version_compare(PHP_VERSION, self::OMEKA_PHP_VERSION, '<')) {
  61. $header = 'Incorrect version of PHP';
  62. $message = "Omeka requires PHP " . self::OMEKA_PHP_VERSION . " or
  63. greater to be installed. PHP " . PHP_VERSION . " is currently
  64. installed. <a href=\"http://www.php.net/manual/en/migration5.php\">Instructions
  65. for upgrading</a> are on the PHP website.";
  66. $this->_errorMessages[] = compact('header', 'message');
  67. }
  68. }
  69. private function _checkMysqliIsAvailable()
  70. {
  71. if (!function_exists('mysqli_get_server_info')) {
  72. $header = 'Mysqli extension is not available';
  73. $message = "The mysqli PHP extension is required for Omeka to run.
  74. Please check with your server administrator to <a href=\"http://www.php.net/manual/en/mysqli.installation.php\">enable
  75. this extension</a> and then try again.";
  76. $this->_errorMessages[] = compact('header', 'message');
  77. }
  78. }
  79. private function _checkMysqlVersionIsValid()
  80. {
  81. $mysqlVersion = $this->_dbAdapter->getServerVersion();
  82. if (version_compare($mysqlVersion, self::OMEKA_MYSQL_VERSION, '<')) {
  83. $header = 'Incorrect version of MySQL';
  84. $message = "Omeka requires MySQL " . self::OMEKA_MYSQL_VERSION . "
  85. or greater to be installed. MySQL $mysqlVersion is currently
  86. installed. <a href=\"http://dev.mysql.com/doc/refman/5.0/en/upgrade.html\">Instructions
  87. for upgrading</a> are on the MySQL website.";
  88. $this->_errorMessages[] = compact('header', 'message');
  89. }
  90. }
  91. private function _checkHtaccessFilesExist()
  92. {
  93. if (!file_exists(BASE_DIR . '/.htaccess')) {
  94. $header = 'Missing .htaccess File';
  95. $message = "Omeka's .htaccess file is missing. Please make sure this
  96. file has been uploaded correctly and try again.";
  97. $this->_errorMessages[] = compact('header', 'message');
  98. }
  99. }
  100. private function _checkRegisterGlobalsIsOff()
  101. {
  102. if (ini_get('register_globals')) {
  103. $header = '"register_globals" is enabled';
  104. $message = "Having PHP's <a href=\"http://www.php.net/manual/en/security.globals.php\">register_globals</a>
  105. setting enabled represents a security risk to your Omeka
  106. installation. Also, having this setting enabled might indicate that
  107. Omeka's .htaccess file is not being properly parsed by Apache, which
  108. can cause any number of strange errors. It is recommended (but not
  109. required) that you disable register_globals for your Omeka
  110. installation.";
  111. $this->_warningMessages[] = compact('header', 'message');
  112. }
  113. }
  114. private function _checkExifModuleIsLoaded()
  115. {
  116. if (!extension_loaded('exif')) {
  117. $header = '"exif" module not loaded';
  118. $message = "Without the <a href=\"http://www.php.net/manual/en/book.exif.php\">exif
  119. module</a> loaded into PHP, Exif data cannot be automatically
  120. extracted from uploaded images.";
  121. $this->_warningMessages[] = compact('header', 'message');
  122. }
  123. }
  124. private function _checkModRewriteIsEnabled()
  125. {
  126. $modRewriteUrl = WEB_ROOT . '/check-mod-rewrite.html';
  127. // Set the http timeout to 5 to prevent recursion, which leads to a
  128. // MySQL "too many connections" error. This assumes Apache needs only 5
  129. // second to rewrite the URL.
  130. $context = stream_context_create(array('http' => array('timeout' => 5)));
  131. // If we can't use the http wrapper for file_get_contents(), warn that
  132. // we were unable to check for mod_rewrite.
  133. if (!ini_get('allow_url_fopen')) {
  134. $header = 'Unable to check for mod_rewrite';
  135. $message = "Unable to verify that <a href=\"http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html\">mod_rewrite</a>
  136. is enabled on your server. mod_rewrite is an Apache extension that
  137. is required for Omeka to work properly. Omeka is unable to check
  138. because your php.ini <a href=\"http://us2.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen\">allow_url_fopen</a>
  139. setting has been disabled. You can manually verify that Omeka
  140. mod_rewrite by checking to see that the following URL works in your
  141. browser: <a href=\"$modRewriteUrl\">$modRewriteUrl</a>";
  142. $this->_warningMessages[] = compact('header', 'message');
  143. // We are trying to retrieve this URL.
  144. } else if (!$modRewrite = @file_get_contents($modRewriteUrl, false, $context)) {
  145. $header = 'mod_rewrite is not enabled';
  146. $message = "Apache's <a href=\"http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html\">mod_rewrite</a>
  147. extension must be enabled for Omeka to work properly. Please enable
  148. mod_rewrite and try again.";
  149. $this->_errorMessages[] = compact('header', 'message');
  150. }
  151. }
  152. private function _checkArchiveStorageSetup()
  153. {
  154. if (!$this->_storage->canStore()) {
  155. try {
  156. $this->_storage->setUp();
  157. } catch (Omeka_Storage_Exception $e) {
  158. $header = 'Archive storage not set up properly.';
  159. $exMessage = $e->getMessage();
  160. $message = "The following error occurred when attempting to "
  161. . "set up storage for your Omeka site: $exMessage "
  162. . "Please ensure that all storage directories exist and "
  163. . "are writable by your web server.";
  164. $this->_errorMessages[] = compact('header', 'message');
  165. }
  166. }
  167. }
  168. private function _checkFileinfoIsLoaded()
  169. {
  170. if (!extension_loaded('fileinfo')) {
  171. $header = '"fileinfo" module not loaded';
  172. $message = "Without the "
  173. . "<a href=\"http://php.net/manual/en/book.fileinfo.php\"> "
  174. . "fileinfo module</a> loaded into PHP, the content type "
  175. . "and encoding of uploaded files about cannot be read. "
  176. . "The installer will disable file upload validation.";
  177. $this->_warningMessages[] = compact('header', 'message');
  178. }
  179. }
  180. }