4 * @file classes/install/Install.inc.php
6 * Copyright (c) 2003-2008 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
11 * @see Installer, InstallForm
13 * @brief Perform system installation.
16 * - Create the database (optionally), and install the database tables and initial data.
17 * - Update the config file with installation parameters.
18 * It can also be used for a "manual install" to retrieve the SQL statements required for installation.
21 // $Id: Install.inc.php,v 1.6 2009/09/22 19:22:09 asmecher Exp $
24 // Default installation data
25 define('INSTALLER_DEFAULT_SITE_TITLE', 'common.openMonographPress');
26 define('INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH', 6);
28 import('install.PKPInstall');
30 class Install
extends PKPInstall
{
34 * @see install.form.InstallForm for the expected parameters
35 * @param $params array installer parameters
36 * @param $descriptor string descriptor path
37 * @param $isPlugin boolean true iff a plugin is being installed
39 function Install($params, $descriptor = 'install.xml', $isPlugin = false) {
40 parent
::PKPInstall($descriptor, $params, $isPlugin);
48 * Get the names of the directories to create.
51 function getCreateDirectories() {
52 $directories = parent
::getCreateDirectories();
53 $directories[] = 'presses';
58 * Create initial required data.
61 function createData() {
62 if ($this->getParam('manualInstall')) {
63 // Add insert statements for default data
64 // FIXME use ADODB data dictionary?
65 $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales
)));
66 $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale
::translate(INSTALLER_DEFAULT_SITE_TITLE
)), $this->getParam('locale')));
67 $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale
::translate(INSTALLER_DEFAULT_SITE_TITLE
)), $this->getParam('locale')));
68 $this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
69 $this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation
::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core
::getCurrentDate(), Core
::getCurrentDate()));
70 $this->executeSQL(sprintf('INSERT INTO roles (press_id, user_id, role_id) VALUES (%d, %d, %d)', 0, 1, ROLE_ID_SITE_ADMIN
));
72 // Install email template list and data for each locale
73 $emailTemplateDao =& DAORegistry
::getDAO('EmailTemplateDAO');
74 $this->executeSQL($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true));
75 foreach ($this->installedLocales
as $locale) {
76 $this->executeSQL($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true));
80 // Add initial site data
82 $locale = $this->getParam('locale');
83 $siteDao =& DAORegistry
::getDAO('SiteDAO', $this->dbconn
);
85 $site->setRedirect(0);
86 $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH
);
87 $site->setPrimaryLocale($locale);
88 $site->setInstalledLocales($this->installedLocales
);
89 $site->setSupportedLocales($this->installedLocales
);
90 if (!$siteDao->insertSite($site)) {
91 $this->setError(INSTALLER_ERROR_DB
, $this->dbconn
->errorMsg());
95 // Install email template list and data for each locale
96 $emailTemplateDao =& DAORegistry
::getDAO('EmailTemplateDAO');
97 $emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
98 foreach ($this->installedLocales
as $locale) {
99 $emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
103 $siteSettingsDao =& DAORegistry
::getDAO('SiteSettingsDAO');
104 $siteSettingsDao->updateSetting('title', array($locale => Locale
::translate(INSTALLER_DEFAULT_SITE_TITLE
)), null, true);
105 $siteSettingsDao->updateSetting('contactName', array($locale => Locale
::translate(INSTALLER_DEFAULT_SITE_TITLE
)), null, true);
106 $siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
108 // Add initial site administrator user
109 $userDao =& DAORegistry
::getDAO('UserDAO', $this->dbconn
);
111 $user->setUsername($this->getParam('adminUsername'));
112 $user->setPassword(Validation
::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
113 $user->setFirstName($user->getUsername());
114 $user->setLastName('');
115 $user->setEmail($this->getParam('adminEmail'));
116 if (!$userDao->insertUser($user)) {
117 $this->setError(INSTALLER_ERROR_DB
, $this->dbconn
->errorMsg());
120 $roleDao =& DAORegistry
::getDao('RoleDAO', $this->dbconn
);
122 $role->setPressId(0);
123 $role->setUserId($user->getId());
124 $role->setRoleId(ROLE_ID_SITE_ADMIN
);
125 if (!$roleDao->insertRole($role)) {
126 $this->setError(INSTALLER_ERROR_DB
, $this->dbconn
->errorMsg());
130 // Add initial plugin data to versions table
131 $versionDao =& DAORegistry
::getDAO('VersionDAO');
132 import('site.VersionCheck');
133 $categories = PluginRegistry
::getCategories();
134 foreach ($categories as $category) {
135 PluginRegistry
::loadCategory($category, true);
136 $plugins = PluginRegistry
::getPlugins($category);
137 foreach ($plugins as $plugin) {
138 $versionFile = $plugin->getPluginPath() . '/version.xml';
140 if (FileManager
::fileExists($versionFile)) {
141 $versionInfo =& VersionCheck
::parseVersionXML($versionFile);
142 $pluginVersion = $versionInfo['version'];
143 $pluginVersion->setCurrent(1);
144 $versionDao->insertVersion($pluginVersion);
146 $pluginVersion = new Version();
147 $pluginVersion->setMajor(1);
148 $pluginVersion->setMinor(0);
149 $pluginVersion->setRevision(0);
150 $pluginVersion->setBuild(0);
151 $pluginVersion->setDateInstalled(Core
::getCurrentDate());
152 $pluginVersion->setCurrent(1);
153 $pluginVersion->setProductType('plugins.' . $category);
154 $pluginVersion->setProduct(basename($plugin->getPluginPath()));
155 $versionDao->insertVersion($pluginVersion);