/application/models/Installer/Default.php

https://github.com/traffman/Omeka · PHP · 133 lines · 92 code · 14 blank · 27 comment · 1 complexity · 2bae4eb8fea6e1dc394307bb5def6462 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Roy Rosenzweig Center for History and New Media, 2007-2010
  5. * @license http://www.gnu.org/licenses/gpl-3.0.txt
  6. * @package Omeka
  7. * @access private
  8. */
  9. /**
  10. * The default installer, which extracts values from the installer form to
  11. * create the default Omeka installation.
  12. *
  13. * @internal This implements Omeka internals and is not part of the public API.
  14. * @access private
  15. * @package Omeka
  16. * @copyright Roy Rosenzweig Center for History and New Media, 2007-2010
  17. */
  18. class Installer_Default implements InstallerInterface
  19. {
  20. const DEFAULT_USER_ACTIVE = true;
  21. const DEFAULT_USER_ROLE = 'super';
  22. const DEFAULT_PUBLIC_THEME = 'default';
  23. const DEFAULT_ADMIN_THEME = 'default';
  24. private $_db;
  25. private $_form;
  26. /**
  27. * Constructor.
  28. *
  29. * @param Omeka_Db $db
  30. */
  31. public function __construct(Omeka_Db $db)
  32. {
  33. $this->_db = $db;
  34. }
  35. /**
  36. * Set the form from which to extract data for the installer.
  37. *
  38. * @param Zend_Form $form
  39. */
  40. public function setForm(Zend_Form $form)
  41. {
  42. $this->_form = $form;
  43. }
  44. public function getDb()
  45. {
  46. return $this->_db;
  47. }
  48. public function install()
  49. {
  50. $this->_createSchema();
  51. $this->_createUser();
  52. $this->_setupMigrations();
  53. $this->_addOptions();
  54. }
  55. protected function _getValue($fieldName)
  56. {
  57. if (!$this->_form) {
  58. throw new Installer_Exception("Form was not set via setForm().");
  59. }
  60. return $this->_form->getValue($fieldName);
  61. }
  62. private function _createSchema()
  63. {
  64. $schemaTask = new Installer_Task_Schema();
  65. $schemaTask->useDefaultTables();
  66. $schemaTask->install($this->_db);
  67. }
  68. private function _createUser()
  69. {
  70. $userTask = new Installer_Task_User;
  71. $userTask->setUsername($this->_getValue('username'));
  72. $userTask->setPassword($this->_getValue('password'));
  73. $userTask->setEmail($this->_getValue('super_email'));
  74. $userTask->setFirstName(Omeka_Form_Install::DEFAULT_USER_FIRST_NAME);
  75. $userTask->setLastName(Omeka_Form_Install::DEFAULT_USER_LAST_NAME);
  76. $userTask->setIsActive(Installer_Default::DEFAULT_USER_ACTIVE);
  77. $userTask->setRole(Installer_Default::DEFAULT_USER_ROLE);
  78. $userTask->install($this->_db);
  79. }
  80. private function _setupMigrations()
  81. {
  82. $task = new Installer_Task_Migrations();
  83. $task->install($this->_db);
  84. }
  85. private function _addOptions()
  86. {
  87. $task = new Installer_Task_Options();
  88. $task->setOptions(array(
  89. 'administrator_email' => $this->_getValue('administrator_email'),
  90. 'copyright' => $this->_getValue('copyright'),
  91. 'site_title' => $this->_getValue('site_title'),
  92. 'author' => $this->_getValue('author'),
  93. 'description' => $this->_getValue('description'),
  94. 'thumbnail_constraint' => $this->_getValue('thumbnail_constraint'),
  95. 'square_thumbnail_constraint' => $this->_getValue('square_thumbnail_constraint'),
  96. 'fullsize_constraint' => $this->_getValue('fullsize_constraint'),
  97. 'per_page_admin' => $this->_getValue('per_page_admin'),
  98. 'per_page_public' => $this->_getValue('per_page_public'),
  99. 'show_empty_elements' => $this->_getValue('show_empty_elements'),
  100. 'path_to_convert' => $this->_getValue('path_to_convert'),
  101. Theme::ADMIN_THEME_OPTION => Installer_Default::DEFAULT_ADMIN_THEME,
  102. Theme::PUBLIC_THEME_OPTION => Installer_Default::DEFAULT_PUBLIC_THEME,
  103. Omeka_Validate_File_Extension::WHITELIST_OPTION => Omeka_Validate_File_Extension::DEFAULT_WHITELIST,
  104. Omeka_Validate_File_MimeType::WHITELIST_OPTION => Omeka_Validate_File_MimeType::DEFAULT_WHITELIST,
  105. File::DISABLE_DEFAULT_VALIDATION_OPTION => (string)!extension_loaded('fileinfo'),
  106. Omeka_Db_Migration_Manager::VERSION_OPTION_NAME => OMEKA_VERSION,
  107. 'display_system_info' => true,
  108. 'tag_delimiter' => ',',
  109. ));
  110. $task->install($this->_db);
  111. }
  112. public function isInstalled()
  113. {
  114. // Assume Omeka is not installed if the `options` table does not exist.
  115. $sql = "SHOW TABLES LIKE '{$this->_db->prefix}options'";
  116. $tables = $this->_db->fetchAll($sql);
  117. return !empty($tables);
  118. }
  119. }