Пример #1
0
 /**
  * Database installation
  *
  * @return $this
  */
 public function installDb()
 {
     $this->_dbUpdater->updateScheme();
     $data = $this->getDataModel()->getConfigData();
     /**
      * Saving host information into DB
      */
     if (!empty($data['use_rewrites'])) {
         $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_USE_REWRITES, 1);
     }
     if (!empty($data['enable_charts'])) {
         $this->_installSetup->setConfigData(\Magento\Backend\Block\Dashboard::XML_PATH_ENABLE_CHARTS, 1);
     } else {
         $this->_installSetup->setConfigData(\Magento\Backend\Block\Dashboard::XML_PATH_ENABLE_CHARTS, 0);
     }
     if (!empty($data['admin_no_form_key'])) {
         $this->_installSetup->setConfigData('admin/security/use_form_key', 0);
     }
     $unsecureBaseUrl = $this->_storeManager->getStore()->getBaseUrl('web');
     if (!empty($data['unsecure_base_url'])) {
         $unsecureBaseUrl = $data['unsecure_base_url'];
         $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl);
     }
     if (!empty($data['use_secure'])) {
         $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_FRONTEND, 1);
         $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']);
         if (!empty($data['use_secure_admin'])) {
             $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_IN_ADMINHTML, 1);
         }
     } elseif (!empty($data['unsecure_base_url'])) {
         $this->_installSetup->setConfigData(\Magento\Store\Model\Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl);
     }
     /**
      * Saving locale information into DB
      */
     $locale = $this->getDataModel()->getLocaleData();
     if (!empty($locale['locale'])) {
         $this->_installSetup->setConfigData($this->_localeResolver->getDefaultLocalePath(), $locale['locale']);
     }
     if (!empty($locale['timezone'])) {
         $this->_installSetup->setConfigData($this->_localeDate->getDefaultTimezonePath(), $locale['timezone']);
     }
     if (!empty($locale['currency'])) {
         $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE, $locale['currency']);
         $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']);
         $this->_installSetup->setConfigData(\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']);
     }
     if (!empty($data['order_increment_prefix'])) {
         $this->_setOrderIncrementPrefix($this->_installSetup, $data['order_increment_prefix']);
     }
     return $this;
 }
Пример #2
0
 /**
  * Install Magento
  *
  * @param array $options
  * @return string|false
  */
 public function install(array $options)
 {
     try {
         $options = $this->_getInstallOptions($options);
         if (!$options) {
             return false;
         }
         /**
          * Check if already installed
          */
         if ($this->_appState->isInstalled()) {
             $this->addError('ERROR: Magento is already installed.');
             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;
         }
         $installer = $this->_getInstaller();
         /**
          * Install configuration
          */
         $installer->installConfig($this->_installerData->getConfigData());
         if (!empty($options['cleanup_database'])) {
             $this->_cleanUpDatabase();
         }
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Install database
          */
         $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 = $installer->getValidEncryptionKey($encryptionKey);
         $installer->createAdministrator($this->_installerData->getAdminData());
         $installer->installEncryptionKey($encryptionKey);
         /**
          * Installation finish
          */
         $installer->finish();
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Change directories mode to be writable by apache user
          */
         $this->_filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR)->changePermissions('', 0777);
         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());
         }
         return false;
     }
 }