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.
15 * @see Installer, InstallForm
17 * @brief Perform system installation.
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
{
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);
44 * Returns true iff this is an upgrade process.
46 function isUpgrade() {
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'),
76 $this->dbconn
=& $conn->getDBConn();
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'),
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());
98 DBConnection
::getInstance($conn);
100 return parent
::preInstall();
109 * Get the names of the directories to create.
112 function getCreateDirectories() {
113 return array('site');
117 * Create required files directories
118 * FIXME No longer needed since FileManager will auto-create?
121 function createDirectories() {
122 if ($this->getParam('skipFilesDir')) {
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');
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');
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');
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');
171 * Create a new database if required.
174 function createDatabase() {
175 if (!$this->getParam('createDatabase')) {
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'));
189 if (!$this->executeSQL($sql)) {
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'),
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());
221 * Write the configuration file.
224 function createConfig() {
225 return $this->updateConfig(
229 'base_url' => Request
::getBaseUrl()
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')
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')
245 'files_dir' => $this->getParam('filesDir')
248 'encryption' => $this->getParam('encryption')
251 'repository_id' => $this->getParam('oaiRepositoryId')