baseline
[omp.pkp.sfu.ca.git] / lib / pkp / classes / install / PKPInstall.inc.php
blobd649cc86ed6fc1ae47f9c95e7cfc1000682c2295
1 <?php
3 /**
4 * @defgroup install
5 */
7 /**
8 * @file classes/install/PKPInstall.inc.php
10 * Copyright (c) 2000-2009 John Willinsky
11 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
13 * @class Install
14 * @ingroup install
15 * @see Installer, InstallForm
17 * @brief Perform system installation.
19 * This script will:
20 * - Create the database (optionally), and install the database tables and initial data.
21 * - Update the config file with installation parameters.
22 * It can also be used for a "manual install" to retrieve the SQL statements required for installation.
25 // $Id: PKPInstall.inc.php,v 1.5 2009/04/08 21:34:54 asmecher Exp $
28 import('install.Installer');
30 class PKPInstall extends Installer {
32 /**
33 * Constructor.
34 * @see install.form.InstallForm for the expected parameters
35 * @param $xmlDescriptor string descriptor path
36 * @param $params array installer parameters
37 * @param $isPlugin boolean true iff a plugin is being installed
39 function PKPInstall($xmlDescriptor, $params, $isPlugin) {
40 parent::Installer($xmlDescriptor, $params, $isPlugin);
43 /**
44 * Returns true iff this is an upgrade process.
46 function isUpgrade() {
47 return false;
50 /**
51 * Pre-installation.
52 * @return boolean
54 function preInstall() {
55 $this->currentVersion = Version::fromString('');
57 $this->locale = $this->getParam('locale');
58 $this->installedLocales = $this->getParam('additionalLocales');
59 if (!isset($this->installedLocales) || !is_array($this->installedLocales)) {
60 $this->installedLocales = array();
62 if (!in_array($this->locale, $this->installedLocales) && Locale::isLocaleValid($this->locale)) {
63 array_push($this->installedLocales, $this->locale);
66 if ($this->getParam('manualInstall')) {
67 // Do not perform database installation for manual install
68 // Create connection object with the appropriate database driver for adodb-xmlschema
69 $conn = new DBConnection(
70 $this->getParam('databaseDriver'),
71 null,
72 null,
73 null,
74 null
76 $this->dbconn =& $conn->getDBConn();
78 } else {
79 // Connect to database
80 $conn = new DBConnection(
81 $this->getParam('databaseDriver'),
82 $this->getParam('databaseHost'),
83 $this->getParam('databaseUsername'),
84 $this->getParam('databasePassword'),
85 $this->getParam('createDatabase') ? null : $this->getParam('databaseName'),
86 true,
87 $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')
90 $this->dbconn =& $conn->getDBConn();
92 if (!$conn->isConnected()) {
93 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
94 return false;
98 DBConnection::getInstance($conn);
100 return parent::preInstall();
105 // Installer actions
109 * Get the names of the directories to create.
110 * @return array
112 function getCreateDirectories() {
113 return array('site');
117 * Create required files directories
118 * FIXME No longer needed since FileManager will auto-create?
119 * @return boolean
121 function createDirectories() {
122 if ($this->getParam('skipFilesDir')) {
123 return true;
126 // Check if files directory exists and is writeable
127 if (!(file_exists($this->getParam('filesDir')) && is_writeable($this->getParam('filesDir')))) {
128 // Files upload directory unusable
129 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
130 return false;
131 } else {
132 // Create required subdirectories
133 $dirsToCreate = $this->getCreateDirectories();
134 foreach ($dirsToCreate as $dirName) {
135 $dirToCreate = $this->getParam('filesDir') . '/' . $dirName;
136 if (!file_exists($dirToCreate)) {
137 import('file.FileManager');
138 if (!FileManager::mkdir($dirToCreate)) {
139 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
140 return false;
146 // Check if public files directory exists and is writeable
147 $publicFilesDir = Config::getVar('files', 'public_files_dir');
148 if (!(file_exists($publicFilesDir) && is_writeable($publicFilesDir))) {
149 // Public files upload directory unusable
150 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
151 return false;
152 } else {
153 // Create required subdirectories
154 $dirsToCreate = $this->getCreateDirectories();
155 foreach ($dirsToCreate as $dirName) {
156 $dirToCreate = $publicFilesDir . '/' . $dirName;
157 if (!file_exists($dirToCreate)) {
158 import('file.FileManager');
159 if (!FileManager::mkdir($dirToCreate)) {
160 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
161 return false;
167 return true;
171 * Create a new database if required.
172 * @return boolean
174 function createDatabase() {
175 if (!$this->getParam('createDatabase')) {
176 return true;
179 // Get database creation sql
180 $dbdict =& NewDataDictionary($this->dbconn);
182 if ($this->getParam('databaseCharset')) {
183 $dbdict->SetCharSet($this->getParam('databaseCharset'));
186 list($sql) = $dbdict->CreateDatabase($this->getParam('databaseName'));
187 unset($dbdict);
189 if (!$this->executeSQL($sql)) {
190 return false;
193 if (!$this->getParam('manualInstall')) {
194 // Re-connect to the created database
195 $this->dbconn->disconnect();
197 $conn = new DBConnection(
198 $this->getParam('databaseDriver'),
199 $this->getParam('databaseHost'),
200 $this->getParam('databaseUsername'),
201 $this->getParam('databasePassword'),
202 $this->getParam('databaseName'),
203 true,
204 $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')
207 DBConnection::getInstance($conn);
209 $this->dbconn =& $conn->getDBConn();
211 if (!$conn->isConnected()) {
212 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
213 return false;
217 return true;
221 * Write the configuration file.
222 * @return boolean
224 function createConfig() {
225 return $this->updateConfig(
226 array(
227 'general' => array(
228 'installed' => 'On',
229 'base_url' => Request::getBaseUrl()
231 'database' => array(
232 'driver' => $this->getParam('databaseDriver'),
233 'host' => $this->getParam('databaseHost'),
234 'username' => $this->getParam('databaseUsername'),
235 'password' => $this->getParam('databasePassword'),
236 'name' => $this->getParam('databaseName')
238 'i18n' => array(
239 'locale' => $this->getParam('locale'),
240 'client_charset' => $this->getParam('clientCharset'),
241 'connection_charset' => $this->getParam('connectionCharset') == '' ? 'Off' : $this->getParam('connectionCharset'),
242 'database_charset' => $this->getParam('databaseCharset') == '' ? 'Off' : $this->getParam('databaseCharset')
244 'files' => array(
245 'files_dir' => $this->getParam('filesDir')
247 'security' => array(
248 'encryption' => $this->getParam('encryption')
250 'oai' => array(
251 'repository_id' => $this->getParam('oaiRepositoryId')