00001 <?php
00002
00025
00026
00027
00028
00029 define('INSTALLER_DEFAULT_SITE_TITLE', 'common.openJournalSystems');
00030 define('INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH', 6);
00031
00032 import('install.Installer');
00033
00034 class Install extends Installer {
00035
00041 function Install($params) {
00042 parent::Installer('install.xml', $params);
00043 }
00044
00048 function isUpgrade() {
00049 return false;
00050 }
00051
00056 function preInstall() {
00057 $this->currentVersion = Version::fromString('');
00058
00059 $this->locale = $this->getParam('locale');
00060 $this->installedLocales = $this->getParam('additionalLocales');
00061 if (!isset($this->installedLocales) || !is_array($this->installedLocales)) {
00062 $this->installedLocales = array();
00063 }
00064 if (!in_array($this->locale, $this->installedLocales) && Locale::isLocaleValid($this->locale)) {
00065 array_push($this->installedLocales, $this->locale);
00066 }
00067
00068 if ($this->getParam('manualInstall')) {
00069
00070
00071 $conn = &new DBConnection(
00072 $this->getParam('databaseDriver'),
00073 null,
00074 null,
00075 null,
00076 null
00077 );
00078 $this->dbconn = &$conn->getDBConn();
00079
00080 } else {
00081
00082 $conn = &new DBConnection(
00083 $this->getParam('databaseDriver'),
00084 $this->getParam('databaseHost'),
00085 $this->getParam('databaseUsername'),
00086 $this->getParam('databasePassword'),
00087 $this->getParam('createDatabase') ? null : $this->getParam('databaseName'),
00088 true,
00089 $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')
00090 );
00091
00092 $this->dbconn = &$conn->getDBConn();
00093
00094 if (!$conn->isConnected()) {
00095 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
00096 return false;
00097 }
00098 }
00099
00100 DBConnection::getInstance($conn);
00101
00102 return parent::preInstall();
00103 }
00104
00105
00106
00107
00108
00109
00115 function createDirectories() {
00116 if ($this->getParam('skipFilesDir')) {
00117 return true;
00118 }
00119
00120
00121 if (!(file_exists($this->getParam('filesDir')) && is_writeable($this->getParam('filesDir')))) {
00122
00123 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
00124 return false;
00125 } else {
00126
00127 $dirsToCreate = array('site', 'journals');
00128 foreach ($dirsToCreate as $dirName) {
00129 $dirToCreate = $this->getParam('filesDir') . '/' . $dirName;
00130 if (!file_exists($dirToCreate)) {
00131 import('file.FileManager');
00132 if (!FileManager::mkdir($dirToCreate)) {
00133 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.installFilesDirError');
00134 return false;
00135 }
00136 }
00137 }
00138 }
00139
00140
00141 $publicFilesDir = Config::getVar('files', 'public_files_dir');
00142 if (!(file_exists($publicFilesDir) && is_writeable($publicFilesDir))) {
00143
00144 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
00145 return false;
00146 } else {
00147
00148 $dirsToCreate = array('site', 'journals');
00149 foreach ($dirsToCreate as $dirName) {
00150 $dirToCreate = $publicFilesDir . '/' . $dirName;
00151 if (!file_exists($dirToCreate)) {
00152 import('file.FileManager');
00153 if (!FileManager::mkdir($dirToCreate)) {
00154 $this->setError(INSTALLER_ERROR_GENERAL, 'installer.publicFilesDirError');
00155 return false;
00156 }
00157 }
00158 }
00159 }
00160
00161 return true;
00162 }
00163
00168 function createDatabase() {
00169 if (!$this->getParam('createDatabase')) {
00170 return true;
00171 }
00172
00173
00174 $dbdict = &NewDataDictionary($this->dbconn);
00175
00176 if ($this->getParam('databaseCharset')) {
00177 $dbdict->SetCharSet($this->getParam('databaseCharset'));
00178 }
00179
00180 list($sql) = $dbdict->CreateDatabase($this->getParam('databaseName'));
00181 unset($dbdict);
00182
00183 if (!$this->executeSQL($sql)) {
00184 return false;
00185 }
00186
00187 if (!$this->getParam('manualInstall')) {
00188
00189 $this->dbconn->disconnect();
00190
00191 $conn = &new DBConnection(
00192 $this->getParam('databaseDriver'),
00193 $this->getParam('databaseHost'),
00194 $this->getParam('databaseUsername'),
00195 $this->getParam('databasePassword'),
00196 $this->getParam('databaseName'),
00197 true,
00198 $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')
00199 );
00200
00201 DBConnection::getInstance($conn);
00202
00203 $this->dbconn = &$conn->getDBConn();
00204
00205 if (!$conn->isConnected()) {
00206 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
00207 return false;
00208 }
00209 }
00210
00211 return true;
00212 }
00213
00218 function createData() {
00219 if ($this->getParam('manualInstall')) {
00220
00221
00222 $this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
00223 $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')));
00224 $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')));
00225 $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')));
00226 $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()));
00227 $this->executeSQL(sprintf('INSERT INTO roles (journal_id, user_id, role_id) VALUES (%d, %d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
00228
00229 } else {
00230
00231 $locale = $this->getParam('locale');
00232 $siteDao = &DAORegistry::getDAO('SiteDAO', $this->dbconn);
00233 $site = &new Site();
00234 $site->setTitle(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE), $locale);
00235 $site->setJournalRedirect(0);
00236 $site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
00237 $site->setPrimaryLocale($locale);
00238 $site->setInstalledLocales($this->installedLocales);
00239 $site->setSupportedLocales($this->installedLocales);
00240 $site->setContactName($site->getTitle($locale), $locale);
00241 $site->setContactEmail($this->getParam('adminEmail'), $locale);
00242 if (!$siteDao->insertSite($site)) {
00243 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
00244 return false;
00245 }
00246
00247
00248 $userDao = &DAORegistry::getDAO('UserDAO', $this->dbconn);
00249 $user = &new User();
00250 $user->setUsername($this->getParam('adminUsername'));
00251 $user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
00252 $user->setFirstName($user->getUsername());
00253 $user->setLastName('');
00254 $user->setEmail($this->getParam('adminEmail'));
00255 if (!$userDao->insertUser($user)) {
00256 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
00257 return false;
00258 }
00259
00260 $roleDao = &DAORegistry::getDao('RoleDAO', $this->dbconn);
00261 $role = &new Role();
00262 $role->setJournalId(0);
00263 $role->setUserId($user->getUserId());
00264 $role->setRoleId(ROLE_ID_SITE_ADMIN);
00265 if (!$roleDao->insertRole($role)) {
00266 $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
00267 return false;
00268 }
00269 }
00270
00271 return true;
00272 }
00273
00278 function createConfig() {
00279 return $this->updateConfig(
00280 array(
00281 'general' => array(
00282 'installed' => 'On',
00283 'base_url' => Request::getBaseUrl()
00284 ),
00285 'database' => array(
00286 'driver' => $this->getParam('databaseDriver'),
00287 'host' => $this->getParam('databaseHost'),
00288 'username' => $this->getParam('databaseUsername'),
00289 'password' => $this->getParam('databasePassword'),
00290 'name' => $this->getParam('databaseName')
00291 ),
00292 'i18n' => array(
00293 'locale' => $this->getParam('locale'),
00294 'client_charset' => $this->getParam('clientCharset'),
00295 'connection_charset' => $this->getParam('connectionCharset') == '' ? 'Off' : $this->getParam('connectionCharset'),
00296 'database_charset' => $this->getParam('databaseCharset') == '' ? 'Off' : $this->getParam('databaseCharset')
00297 ),
00298 'files' => array(
00299 'files_dir' => $this->getParam('filesDir')
00300 ),
00301 'security' => array(
00302 'encryption' => $this->getParam('encryption')
00303 ),
00304 'oai' => array(
00305 'repository_id' => $this->getParam('oaiRepositoryId')
00306 )
00307 )
00308 );
00309 }
00310
00311 }
00312
00313 ?>