Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Installer Class Reference

Public Member Functions

 __construct (FilePermissions $filePermissions, Writer $deploymentConfigWriter, Reader $deploymentConfigReader, \Magento\Framework\App\DeploymentConfig $deploymentConfig, ModuleListInterface $moduleList, ModuleLoader $moduleLoader, AdminAccountFactory $adminAccountFactory, LoggerInterface $log, ConnectionFactory $connectionFactory, MaintenanceMode $maintenanceMode, Filesystem $filesystem, ObjectManagerProvider $objectManagerProvider, Context $context, SetupConfigModel $setupConfigModel, CleanupFiles $cleanupFiles, DbValidator $dbValidator, SetupFactory $setupFactory, DataSetupFactory $dataSetupFactory, \Magento\Framework\Setup\SampleData\State $sampleDataState, ComponentRegistrar $componentRegistrar, PhpReadinessCheck $phpReadinessCheck)
 
 install ($request)
 
 checkInstallationFilePermissions ()
 
 checkExtensions ()
 
 checkApplicationFilePermissions ()
 
 installDeploymentConfig ($data)
 
 declarativeInstallSchema (array $request)
 
 checkFilePermissionsForDbUpgrade ()
 
 installAdminUser ($data)
 
 updateModulesSequence ($keepGeneratedFiles=false)
 
 uninstall ()
 
 getInstallInfo ()
 
 cleanupDb ()
 

Data Fields

const ENABLE_MODULES = 'enable-modules'
 
const DISABLE_MODULES = 'disable-modules'
 
const PROGRESS_LOG_RENDER = '[Progress: %d / %d]'
 
const PROGRESS_LOG_REGEX = '/\[Progress: (\d+) \/ (\d+)\]/s'
 
const SCHEMA_INSTALL = \Magento\Framework\Setup\InstallSchemaInterface::class
 
const SCHEMA_UPGRADE = \Magento\Framework\Setup\UpgradeSchemaInterface::class
 
const DATA_INSTALL = \Magento\Framework\Setup\InstallDataInterface::class
 
const DATA_UPGRADE = \Magento\Framework\Setup\UpgradeDataInterface::class
 
const INFO_MESSAGE = 'message'
 
const MYSQL_VERSION_REQUIRED = '5.6.0'
 

Protected Member Functions

 createSchemaDataHandler ($className, $interfaceName)
 

Protected Attributes

 $sampleDataState
 

Detailed Description

Class Installer contains the logic to install Magento application.

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity)

Definition at line 54 of file Installer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( FilePermissions  $filePermissions,
Writer  $deploymentConfigWriter,
Reader  $deploymentConfigReader,
\Magento\Framework\App\DeploymentConfig  $deploymentConfig,
ModuleListInterface  $moduleList,
ModuleLoader  $moduleLoader,
AdminAccountFactory  $adminAccountFactory,
LoggerInterface  $log,
ConnectionFactory  $connectionFactory,
MaintenanceMode  $maintenanceMode,
Filesystem  $filesystem,
ObjectManagerProvider  $objectManagerProvider,
Context  $context,
SetupConfigModel  $setupConfigModel,
CleanupFiles  $cleanupFiles,
DbValidator  $dbValidator,
SetupFactory  $setupFactory,
DataSetupFactory  $dataSetupFactory,
\Magento\Framework\Setup\SampleData\State  $sampleDataState,
ComponentRegistrar  $componentRegistrar,
PhpReadinessCheck  $phpReadinessCheck 
)

Constructor

Parameters
FilePermissions$filePermissions
Writer$deploymentConfigWriter
Reader$deploymentConfigReader
\Magento\Framework\App\DeploymentConfig$deploymentConfig
ModuleListInterface$moduleList
ModuleLoader$moduleLoader
AdminAccountFactory$adminAccountFactory
LoggerInterface$log
ConnectionFactory$connectionFactory
MaintenanceMode$maintenanceMode
Filesystem$filesystem
ObjectManagerProvider$objectManagerProvider
Context$context
SetupConfigModel$setupConfigModel
CleanupFiles$cleanupFiles
DbValidator$dbValidator
SetupFactory$setupFactory
DataSetupFactory$dataSetupFactory
\Magento\Framework\Setup\SampleData\State$sampleDataState
ComponentRegistrar$componentRegistrar
PhpReadinessCheck$phpReadinessCheck
Exceptions

Definition at line 273 of file Installer.php.

295  {
296  $this->filePermissions = $filePermissions;
297  $this->deploymentConfigWriter = $deploymentConfigWriter;
298  $this->deploymentConfigReader = $deploymentConfigReader;
299  $this->moduleList = $moduleList;
300  $this->moduleLoader = $moduleLoader;
301  $this->adminAccountFactory = $adminAccountFactory;
302  $this->log = $log;
303  $this->connectionFactory = $connectionFactory;
304  $this->maintenanceMode = $maintenanceMode;
305  $this->filesystem = $filesystem;
306  $this->installInfo[self::INFO_MESSAGE] = [];
307  $this->deploymentConfig = $deploymentConfig;
308  $this->objectManagerProvider = $objectManagerProvider;
309  $this->context = $context;
310  $this->setupConfigModel = $setupConfigModel;
311  $this->cleanupFiles = $cleanupFiles;
312  $this->dbValidator = $dbValidator;
313  $this->setupFactory = $setupFactory;
314  $this->dataSetupFactory = $dataSetupFactory;
315  $this->sampleDataState = $sampleDataState;
316  $this->componentRegistrar = $componentRegistrar;
317  $this->phpReadinessCheck = $phpReadinessCheck;
318  $this->schemaPersistor = $this->objectManagerProvider->get()->get(SchemaPersistor::class);
319  }
$componentRegistrar
Definition: bootstrap.php:23
$deploymentConfig
$filesystem

Member Function Documentation

◆ checkApplicationFilePermissions()

checkApplicationFilePermissions ( )

Check permissions of directories that are expected to be non-writable for application

Returns
void

Definition at line 528 of file Installer.php.

529  {
530  $results = $this->filePermissions->getUnnecessaryWritableDirectoriesForApplication();
531  if ($results) {
532  $errorMsg = "For security, remove write permissions from these directories: '"
533  . implode("' '", $results) . "'";
534  $this->log->log($errorMsg);
535  $this->installInfo[self::INFO_MESSAGE][] = $errorMsg;
536  }
537  }
$results
Definition: popup.phtml:13

◆ checkExtensions()

checkExtensions ( )

Check required extensions for installation

Returns
void
Exceptions

Definition at line 511 of file Installer.php.

512  {
513  $phpExtensionsCheckResult = $this->phpReadinessCheck->checkPhpExtensions();
514  if ($phpExtensionsCheckResult['responseType'] === ResponseTypeInterface::RESPONSE_TYPE_ERROR
515  && isset($phpExtensionsCheckResult['data']['missing'])
516  ) {
517  $errorMsg = "Missing following extensions: '"
518  . implode("' '", $phpExtensionsCheckResult['data']['missing']) . "'";
519  throw new \Exception($errorMsg);
520  }
521  }

◆ checkFilePermissionsForDbUpgrade()

checkFilePermissionsForDbUpgrade ( )

Check permissions of directories that are expected to be writable for database upgrade

Returns
void
Exceptions

Definition at line 885 of file Installer.php.

886  {
887  $this->throwExceptionForNotWritablePaths(
888  $this->filePermissions->getMissingWritableDirectoriesForDbUpgrade()
889  );
890  }

◆ checkInstallationFilePermissions()

checkInstallationFilePermissions ( )

Check permissions of directories that are expected to be writable for installation

Returns
void
Exceptions

Definition at line 498 of file Installer.php.

499  {
500  $this->throwExceptionForNotWritablePaths(
501  $this->filePermissions->getMissingWritablePathsForInstallation()
502  );
503  }

◆ cleanupDb()

cleanupDb ( )

Deletes the database and creates it again

Returns
void

Definition at line 1294 of file Installer.php.

1295  {
1296  $cleanedUpDatabases = [];
1297  $connections = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS, []);
1298  //Do database cleanup for all shards
1299  foreach ($connections as $config) {
1300  try {
1301  $connection = $this->connectionFactory->create($config);
1302  if (!$connection) {
1303  $this->log->log("Can't create connection to database - skipping database cleanup");
1304  }
1305  } catch (\Exception $e) {
1306  $this->log->log($e->getMessage() . ' - skipping database cleanup');
1307  return;
1308  }
1309 
1310  $dbName = $connection->quoteIdentifier($config[ConfigOptionsListConstants::KEY_NAME]);
1311  //If for different shards one database was specified - no need to clean it few times
1312  if (!in_array($dbName, $cleanedUpDatabases)) {
1313  $this->log->log("Cleaning up database {$dbName}");
1314  $connection->query("DROP DATABASE IF EXISTS {$dbName}");
1315  $connection->query("CREATE DATABASE IF NOT EXISTS {$dbName}");
1316  $cleanedUpDatabases[] = $dbName;
1317  }
1318  }
1319 
1320  if (empty($config)) {
1321  $this->log->log('No database connection defined - skipping database cleanup');
1322  }
1323  }
$config
Definition: fraud_order.php:17
$connection
Definition: bulk.php:13

◆ createSchemaDataHandler()

createSchemaDataHandler (   $className,
  $interfaceName 
)
protected

Create data handler

Parameters
string$className
string$interfaceName
Returns
mixed|null
Exceptions

Definition at line 1096 of file Installer.php.

1097  {
1098  if (class_exists($className)) {
1099  if (!is_subclass_of($className, $interfaceName) && $className !== $interfaceName) {
1100  throw new \Magento\Setup\Exception($className . ' must implement \\' . $interfaceName);
1101  } else {
1102  return $this->objectManagerProvider->get()->create($className);
1103  }
1104  }
1105  return null;
1106  }
is_subclass_of($obj, $className)
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ declarativeInstallSchema()

declarativeInstallSchema ( array  $request)

Install Magento if declaration mode was enabled.

Parameters
array$request
Returns
void

Definition at line 806 of file Installer.php.

807  {
808  $this->getDeclarationInstaller()->installSchema($request);
809  }

◆ getInstallInfo()

getInstallInfo ( )

Return messages

Returns
array

Definition at line 1284 of file Installer.php.

1285  {
1286  return $this->installInfo;
1287  }

◆ install()

install (   $request)

Install Magento application

Parameters
\ArrayObject | array$request
Returns
void
Exceptions

Definition at line 328 of file Installer.php.

329  {
330  $script[] = ['File permissions check...', 'checkInstallationFilePermissions', []];
331  $script[] = ['Required extensions check...', 'checkExtensions', []];
332  $script[] = ['Enabling Maintenance Mode...', 'setMaintenanceMode', [1]];
333  $script[] = ['Installing deployment configuration...', 'installDeploymentConfig', [$request]];
335  $script[] = ['Cleaning up database...', 'cleanupDb', []];
336  }
337  $script[] = ['Installing database schema:', 'installSchema', [$request]];
338  $script[] = ['Installing user configuration...', 'installUserConfig', [$request]];
339  $script[] = ['Enabling caches:', 'enableCaches', []];
340  $script[] = ['Installing data...', 'installDataFixtures', [$request]];
342  $script[] = [
343  'Creating sales order increment prefix...',
344  'installOrderIncrementPrefix',
346  ];
347  }
348  if ($this->isAdminDataSet($request)) {
349  $script[] = ['Installing admin user...', 'installAdminUser', [$request]];
350  }
351 
352  if (!$this->isDryRun($request)) {
353  $script[] = ['Caches clearing:', 'cleanCaches', [$request]];
354  }
355  $script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]];
356  $script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []];
357  $script[] = ['Write installation date...', 'writeInstallationDate', []];
358  $estimatedModules = $this->createModulesConfig($request, true);
359  $total = count($script) + 4 * count(array_filter($estimatedModules));
360  $this->progress = new Installer\Progress($total, 0);
361 
362  $this->log->log('Starting Magento installation:');
363 
364  foreach ($script as $item) {
365  list($message, $method, $params) = $item;
366  $this->log->log($message);
367  call_user_func_array([$this, $method], $params);
368  $this->logProgress();
369  }
370  $this->log->logSuccess('Magento installation complete.');
371  $this->log->logSuccess(
372  'Magento Admin URI: /'
373  . $this->deploymentConfig->get(BackendConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME)
374  );
375 
376  if ($this->progress->getCurrent() != $this->progress->getTotal()) {
377  throw new \LogicException('Installation progress did not finish properly.');
378  }
379  if ($this->sampleDataState->hasError()) {
380  $this->log->log('Sample Data is installed with errors. See log file for details');
381  }
382  }
$message
$method
Definition: info.phtml:13
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ installAdminUser()

installAdminUser (   $data)

Create admin account

Parameters
\ArrayObject | array$data
Returns
void

Definition at line 1158 of file Installer.php.

1159  {
1160  if ($this->isDryRun($data)) {
1161  return;
1162  }
1163 
1164  $adminUserModuleIsInstalled = (bool)$this->deploymentConfig->get('modules/Magento_User');
1165  //Admin user data is not system data, so we need to install it only if schema for admin user was installed
1166  if ($adminUserModuleIsInstalled) {
1167  $this->assertDbConfigExists();
1168  $data += ['db-prefix' => $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_DB_PREFIX)];
1169  $setup = $this->setupFactory->create($this->context->getResources());
1170  $adminAccount = $this->adminAccountFactory->create($setup->getConnection(), (array)$data);
1171  $adminAccount->save();
1172  }
1173  }
$setup
Definition: trigger.php:12

◆ installDeploymentConfig()

installDeploymentConfig (   $data)

Installs deployment configuration

Parameters
\ArrayObject | array$data
Returns
void

Definition at line 545 of file Installer.php.

546  {
548  $this->createModulesConfig($data);
549  $userData = is_array($data) ? $data : $data->getArrayCopy();
550  $this->setupConfigModel->process($userData);
551  $deploymentConfigData = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
552  if (isset($deploymentConfigData)) {
553  $this->installInfo[ConfigOptionsListConstants::KEY_ENCRYPTION_KEY] = $deploymentConfigData;
554  }
555  // reset object manager now that there is a deployment config
556  $this->objectManagerProvider->reset();
557  }

◆ uninstall()

uninstall ( )

Uninstall Magento application

Returns
void

Definition at line 1204 of file Installer.php.

1205  {
1206  $this->log->log('Starting Magento uninstallation:');
1207 
1208  try {
1209  $this->cleanCaches();
1210  } catch (\Exception $e) {
1211  $this->log->log(
1212  'Can\'t clear cache due to the following error: '
1213  . $e->getMessage() . PHP_EOL
1214  . 'To fully clean up your uninstallation, you must manually clear your cache.'
1215  );
1216  }
1217 
1218  $this->cleanupDb();
1219 
1220  $this->log->log('File system cleanup:');
1221  $messages = $this->cleanupFiles->clearAllFiles();
1222  foreach ($messages as $message) {
1223  $this->log->log($message);
1224  }
1225 
1226  $this->deleteDeploymentConfig();
1227 
1228  $this->log->logSuccess('Magento uninstallation complete.');
1229  }
$message

◆ updateModulesSequence()

updateModulesSequence (   $keepGeneratedFiles = false)

Updates modules in deployment configuration

Parameters
bool$keepGeneratedFilesCleanup generated classes and view files and reset ObjectManager
Returns
void
Exceptions

Definition at line 1182 of file Installer.php.

1183  {
1184  $config = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES);
1185  if (!$config) {
1186  throw new \Magento\Setup\Exception(
1187  "Can't run this operation: deployment configuration is absent."
1188  . " Run 'magento setup:config:set --help' for options."
1189  );
1190  }
1191  $this->cleanCaches();
1192  if (!$keepGeneratedFiles) {
1193  $this->cleanupGeneratedFiles();
1194  }
1195  $this->log->log('Updating modules:');
1196  $this->createModulesConfig([]);
1197  }
$config
Definition: fraud_order.php:17

Field Documentation

◆ $sampleDataState

$sampleDataState
protected

Definition at line 217 of file Installer.php.

◆ DATA_INSTALL

const DATA_INSTALL = \Magento\Framework\Setup\InstallDataInterface::class

Definition at line 75 of file Installer.php.

◆ DATA_UPGRADE

const DATA_UPGRADE = \Magento\Framework\Setup\UpgradeDataInterface::class

Definition at line 76 of file Installer.php.

◆ DISABLE_MODULES

const DISABLE_MODULES = 'disable-modules'

Definition at line 60 of file Installer.php.

◆ ENABLE_MODULES

const ENABLE_MODULES = 'enable-modules'

#+ Parameters for enabling/disabling modules

Definition at line 59 of file Installer.php.

◆ INFO_MESSAGE

const INFO_MESSAGE = 'message'

#-

Definition at line 79 of file Installer.php.

◆ MYSQL_VERSION_REQUIRED

const MYSQL_VERSION_REQUIRED = '5.6.0'

The lowest supported MySQL verion

Definition at line 84 of file Installer.php.

◆ PROGRESS_LOG_REGEX

const PROGRESS_LOG_REGEX = '/\[Progress: (\d+) \/ (\d+)\]/s'

Definition at line 67 of file Installer.php.

◆ PROGRESS_LOG_RENDER

const PROGRESS_LOG_RENDER = '[Progress: %d / %d]'

#- #+ Formatting for progress log

Definition at line 66 of file Installer.php.

◆ SCHEMA_INSTALL

const SCHEMA_INSTALL = \Magento\Framework\Setup\InstallSchemaInterface::class

#- #+ Instance types for schema and data handler

Definition at line 73 of file Installer.php.

◆ SCHEMA_UPGRADE

const SCHEMA_UPGRADE = \Magento\Framework\Setup\UpgradeSchemaInterface::class

Definition at line 74 of file Installer.php.


The documentation for this class was generated from the following file: