Exemplo n.º 1
0
 /**
  * Deletes the database and creates it again
  *
  * @return void
  */
 private function recreateDatabase()
 {
     $connectionData = $this->db->getConnectionData();
     if (empty($connectionData['dbName'])) {
         $this->log('No database connection defined - skipping cleanup');
     } else {
         $this->log("Recreating database '{$connectionData['dbName']}'");
         $this->db->cleanUpDatabase();
     }
 }
Exemplo n.º 2
0
 /**
  * Install Magento
  *
  * @param array $options
  * @return string|false
  */
 public function install(array $options)
 {
     try {
         $options = $this->_getInstallOptions($options);
         if (!$options) {
             return false;
         }
         /**
          * Skip URL validation, if set
          */
         $this->_installerData->setSkipUrlValidation($options['skip_url_validation']);
         $this->_installerData->setSkipBaseUrlValidation($options['skip_url_validation']);
         /**
          * Locale settings
          */
         $this->_installerData->setLocaleData(['locale' => $options['locale'], 'timezone' => $options['timezone'], 'currency' => $options['default_currency']]);
         /**
          * Database and web config
          */
         $this->_installerData->setConfigData(['db_model' => $options['db_model'], 'db_host' => $options['db_host'], 'db_name' => $options['db_name'], 'db_user' => $options['db_user'], 'db_pass' => $options['db_pass'], 'db_prefix' => $options['db_prefix'], 'use_rewrites' => $this->_getFlagValue($options['use_rewrites']), 'use_secure' => $this->_getFlagValue($options['use_secure']), 'unsecure_base_url' => $options['url'], 'secure_base_url' => $options['secure_base_url'], 'use_secure_admin' => $this->_getFlagValue($options['use_secure_admin']), 'session_save' => $this->_checkSessionSave($options['session_save']), 'backend_frontname' => $this->_checkBackendFrontname($options['backend_frontname']), 'admin_no_form_key' => $this->_getFlagValue($options['admin_no_form_key']), 'skip_url_validation' => $this->_getFlagValue($options['skip_url_validation']), 'enable_charts' => $this->_getFlagValue($options['enable_charts']), 'order_increment_prefix' => $options['order_increment_prefix']]);
         /**
          * Primary admin user
          */
         $this->_installerData->setAdminData(['firstname' => $options['admin_firstname'], 'lastname' => $options['admin_lastname'], 'email' => $options['admin_email'], 'username' => $options['admin_username'], 'password' => $options['admin_password']]);
         $this->checkServer();
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Install configuration
          */
         $this->installer->installConfig($this->_installerData->getConfigData());
         if (!empty($options['cleanup_database'])) {
             $this->db->cleanUpDatabase();
         }
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Install database
          */
         $this->installer->installDb();
         if ($this->hasErrors()) {
             return false;
         }
         // apply data updates
         $this->_dbUpdater->updateData();
         /**
          * Create primary administrator user & install encryption key
          */
         $encryptionKey = !empty($options['encryption_key']) ? $options['encryption_key'] : null;
         $encryptionKey = $this->installer->getValidEncryptionKey($encryptionKey);
         $this->installer->createAdministrator($this->_installerData->getAdminData());
         $this->installer->installEncryptionKey($encryptionKey);
         /**
          * Installation finish
          */
         $this->installer->finish();
         if ($this->hasErrors()) {
             return false;
         }
         return $encryptionKey;
     } catch (\Exception $e) {
         if ($e instanceof \Magento\Framework\Model\Exception) {
             $errorMessages = $e->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR);
             if (!empty($errorMessages)) {
                 foreach ($errorMessages as $errorMessage) {
                     $this->addError($errorMessage);
                 }
             } else {
                 $this->addError($e->getMessage());
             }
         } else {
             $this->addError('ERROR: ' . $e->getMessage() . $e->getTraceAsString());
         }
         return false;
     }
 }