示例#1
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  AbortException
  * @throws  \RuntimeException
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     $this->getApplication()->outputTitle(g11n3t('Installer'));
     $this->db = $this->getContainer()->get('db');
     try {
         // Check if the database "exists"
         $tables = $this->db->getTableList();
         if (!$this->getApplication()->input->get('reinstall')) {
             $this->out()->out('<fg=black;bg=yellow>' . g11n3t('WARNING: A database has been found !!') . '</fg=black;bg=yellow>')->out()->out(g11n3t('Do you want to reinstall ?'))->out()->out('1) ' . g11n3t('Yes'))->out('2) ' . g11n3t('No'))->out()->out('<question>' . g11n3t('Select:') . '</question>', false);
             $in = trim($this->getApplication()->in());
             if (1 != (int) $in) {
                 throw new AbortException();
             }
         }
         $this->cleanDatabase($tables)->outOK();
     } catch (\RuntimeException $e) {
         // Check if the message is "Could not connect to database."  Odds are, this means the DB isn't there or the server is down.
         if (strpos($e->getMessage(), 'Could not connect to database.') !== false) {
             // ? really..
             $this->out(g11n3t('No database found.'))->out(g11n3t('Creating the database...'), false);
             $this->db->setQuery('CREATE DATABASE ' . $this->db->quoteName($this->getApplication()->get('database.name')))->execute();
             $this->db->select($this->getApplication()->get('database.name'));
             $this->outOK();
         } else {
             throw $e;
         }
     }
     // Perform the installation
     $this->processSql()->out()->out('<ok>' . g11n3t('Installation has terminated successfully.') . '</ok>');
 }
示例#2
0
 /**
  * Execute the command.
  *
  * @return  void
  *
  * @since   1.0
  * @throws  AbortException
  * @throws  \RuntimeException
  * @throws  \UnexpectedValueException
  */
 public function execute()
 {
     try {
         // Check if the database "exists"
         $tables = $this->db->getTableList();
         if (!$this->app->input->get('reinstall')) {
             $this->app->out('<fg=black;bg=yellow>WARNING: A database has been found !!</fg=black;bg=yellow>')->out('Do you want to reinstall ? [y]es / [[n]]o :', false);
             $in = trim($this->app->in());
             if (!in_array($in, ['yes', 'y'])) {
                 throw new AbortException();
             }
         }
         $this->cleanDatabase($tables);
         $this->app->out("\nFinished!");
     } catch (\RuntimeException $e) {
         // Check if the message is "Could not connect to database."  Odds are, this means the DB isn't there or the server is down.
         if (strpos($e->getMessage(), 'Could not connect to database.') !== false) {
             // ? really..
             $this->app->out('No database found.')->out('Creating the database...', false);
             $this->db->setQuery('CREATE DATABASE ' . $this->db->quoteName($this->config->get('database.name')))->execute();
             $this->db->select($this->config->get('database.name'));
             $this->app->out("\nFinished!");
         } else {
             throw $e;
         }
     }
     // Perform the installation
     $this->processSql();
     $this->app->out('Installer has terminated successfully.');
 }
示例#3
0
 /**
  * Merges the incoming structure definition with the existing structure.
  *
  * @return  void
  *
  * @note    Currently only supports XML format.
  * @since   1.0
  * @throws  \RuntimeException on error.
  */
 public function mergeStructure()
 {
     $tables = $this->db->getTableList();
     if ($this->from instanceof \SimpleXMLElement) {
         $xml = $this->from;
     } else {
         $xml = new \SimpleXMLElement($this->from);
     }
     // Get all the table definitions.
     $xmlTables = $xml->xpath('database/table_structure');
     foreach ($xmlTables as $table) {
         // Convert the magic prefix into the real table name.
         $tableName = $this->getRealTableName((string) $table['name']);
         if (in_array($tableName, $tables)) {
             // The table already exists. Now check if there is any difference.
             if ($queries = $this->getAlterTableql($xml->database->table_structure)) {
                 // Run the queries to upgrade the data structure.
                 foreach ($queries as $query) {
                     $this->db->setQuery((string) $query);
                     try {
                         $this->db->execute();
                     } catch (\RuntimeException $e) {
                         $this->db->log(LogLevel::DEBUG, 'Fail: ' . $this->db->getQuery());
                         throw $e;
                     }
                     $this->db->log(LogLevel::DEBUG, 'Pass: '******'Fail: ' . $this->db->getQuery());
                 throw $e;
             }
             $this->db->log(LogLevel::DEBUG, 'Pass: ' . $this->db->getQuery());
         }
     }
 }