Ejemplo n.º 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>');
 }
Ejemplo n.º 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.');
 }