Ejemplo n.º 1
0
 /**
  * execute the installation steps
  *
  * @return boolean
  */
 function install($aConfig)
 {
     $this->oLogger->setLogFile('install.log');
     $this->oLogger->deleteLogFile();
     // Always use lower case prefixes for new installs
     $aConfig['table']['prefix'] = strtolower($aConfig['table']['prefix']);
     if ($aConfig['database']['localsocket'] == true) {
         $aConfig['database']['protocol'] = 'unix';
     } else {
         $aConfig['database']['protocol'] = 'tcp';
     }
     $this->aDsn['database'] = $aConfig['database'];
     $this->aDsn['table'] = $aConfig['table'];
     $this->oLogger->log('Installation started ' . OA::getNow());
     $this->oLogger->log('Attempting to connect to database ' . $this->aDsn['database']['name'] . ' with user ' . $this->aDsn['database']['username']);
     if (!$this->_createDatabase()) {
         $this->oLogger->logError('Installation failed to create the database ' . stripslashes($this->aDsn['database']['name']));
         return false;
     }
     $this->oLogger->log('Connected to database ' . $this->oDbh->connected_database_name);
     /**
      * validate table prefix before creating DB since it does not
      * make much sense to create a DB and then be unable to add tables
      */
     if (PEAR::isError(OA_DB::validateTableName($aConfig['table']['prefix']))) {
         $this->oLogger->logError('Illegal characters in table prefix ' . stripslashes($aConfig['table']['prefix']));
         return false;
     }
     if (!$this->checkExistingTables()) {
         if (!$this->oLogger->errorExists) {
             $this->oLogger->logError();
         }
         return false;
     }
     if (!$this->checkPermissionToCreateTable()) {
         $this->oLogger->logError('Insufficient database permissions or incorrect database settings to install');
         return false;
     }
     if (!$this->initDatabaseConnection()) {
         $this->oLogger->logError('Installation failed to connect to the database ' . $this->aDsn['database']['name']);
         $this->_dropDatabase();
         return false;
     }
     $aConfig = $this->initDatabaseParameters($aConfig);
     if (!$this->createCoreTables()) {
         $this->oLogger->logError('Installation failed to create the core tables');
         $this->_dropDatabase();
         return false;
     }
     $this->oLogger->log('Installation created the core tables');
     $this->oAuditor->setKeyParams(array('upgrade_name' => 'install_' . OA_VERSION, 'version_to' => OA_VERSION, 'version_from' => 0, 'logfile' => basename($this->oLogger->logFile)));
     if (!$this->oVersioner->putSchemaVersion('tables_core', $this->oTable->aDefinition['version'])) {
         $this->_auditInstallationFailure('Installation failed to update the schema version to ' . $oTable->aDefinition['version']);
         $this->_dropDatabase();
         return false;
     }
     $this->oLogger->log('Installation updated the schema version to ' . $this->oTable->aDefinition['version']);
     if (!$this->oVersioner->putApplicationVersion(OA_VERSION)) {
         $this->_auditInstallationFailure('Installation failed to update the application version to ' . OA_VERSION);
         $this->_dropDatabase();
         return false;
     }
     $this->oLogger->log('Installation updated the application version to ' . OA_VERSION);
     $this->oConfiguration->getInitialConfig();
     if (!$this->saveConfigDB($aConfig)) {
         $this->_auditInstallationFailure('Installation failed to write database details to the configuration file ' . $this->oConfiguration->configFile);
         if (file_exists($this->oConfiguration->configPath . $this->oConfiguration->configFile)) {
             @unlink($this->oConfiguration->configPath . $this->oConfiguration->configFile);
             $this->oLogger->log('Installation deleted the configuration file ' . $this->oConfiguration->configFile);
         }
         $this->_dropDatabase();
         return false;
     }
     $this->oAuditor->logAuditAction(array('description' => 'UPGRADE_COMPLETE', 'action' => UPGRADE_ACTION_UPGRADE_SUCCEEDED));
     if ($this->upgrading_from_milestone_version) {
         if (!$this->removeUpgradeTriggerFile()) {
             $this->oLogger->log('failed to remove the UPGRADE trigger file');
         }
     }
     return true;
 }