/** * Retrieve all disabled modules from the configuration * * @return array */ protected function getDisabledModules() { $allModules = $this->fullModuleList->getNames(); $enabledModules = $this->moduleList->getNames(); $disabledModules = array_diff($allModules, $enabledModules); return $disabledModules; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('<info>List of active modules:<info>'); foreach ($this->moduleList->getNames() as $moduleName) { $output->writeln('<info>' . $moduleName . '<info>'); } }
/** * Determine whether provided name begins from any available modules, according to namespaces priority * If matched, returns as the matched module "factory" name or a fully qualified module name * * @param string $name * @param bool $asFullModuleName * @return string * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function determineOmittedNamespace($name, $asFullModuleName = false) { if (null === $this->_moduleNamespaces) { $this->_moduleNamespaces = []; foreach ($this->_moduleList->getNames() as $moduleName) { $module = strtolower($moduleName); $this->_moduleNamespaces[substr($module, 0, strpos($module, '_'))][$module] = $moduleName; } } $explodeString = strpos($name, '\\') === false ? '_' : '\\'; $name = explode($explodeString, strtolower($name)); $partsNum = count($name); $defaultNamespaceFlag = false; foreach ($this->_moduleNamespaces as $namespaceName => $namespace) { // assume the namespace is omitted (default namespace only, which comes first) if ($defaultNamespaceFlag === false) { $defaultNamespaceFlag = true; $defaultNS = $namespaceName . '_' . $name[0]; if (isset($namespace[$defaultNS])) { return $asFullModuleName ? $namespace[$defaultNS] : $name[0]; // return omitted as well } } // assume namespace is qualified if (isset($name[1])) { $fullNS = $name[0] . '_' . $name[1]; if (2 <= $partsNum && isset($namespace[$fullNS])) { return $asFullModuleName ? $namespace[$fullNS] : $fullNS; } } } return ''; }
public function execute() { $greeting = "Hello world! I am a Magento2 extension.<br/>\n"; $title = 'Hello World'; $moduleNames = implode("<br/>\n", $this->moduleList->getNames()); $body = "\n<html>\n <head>\n <title>{$title}</title>\n </head>\n <body>{$greeting}<br/>Modules Installed:<br/>{$moduleNames}</body>\n</html>"; $this->_response->setBody($body); }
/** * Prepare module namespaces * * @return void */ protected function prepareModuleNamespaces() { if (null === $this->moduleNamespaces) { $this->moduleNamespaces = []; foreach ($this->moduleList->getNames() as $moduleName) { $module = strtolower($moduleName); $this->moduleNamespaces[substr($module, 0, strpos($module, '_'))][$module] = $moduleName; } } }
/** * Options getter * * @return array */ public function toOptionArray() { $output = []; $modules = $this->_moduleList->getNames(); sort($modules); foreach ($modules as $k => $v) { if (preg_match("/Ves/", $v)) { $output[$k] = ['value' => $v, 'label' => $v]; } } return $output; }
/** * Retrieve fully-qualified module name, path belongs to * * @param string $path Full path to file or directory * @return string|null */ public function getModuleName($path) { $path = str_replace('\\', '/', $path); foreach ($this->_moduleList->getNames() as $moduleName) { $moduleDir = $this->_moduleDirs->getDir($moduleName); $moduleDir = str_replace('\\', '/', $moduleDir); if ($path == $moduleDir || strpos($path, $moduleDir . '/') === 0) { return $moduleName; } } return null; }
/** * Get array of errors if DB is out of date, return [] if DB is current * * @return string[] Array of errors, each error contains module name, current version, required version, * and type (schema or data). The array will be empty if all schema and data are current. */ public function getDbVersionErrors() { $errors = []; foreach ($this->moduleList->getNames() as $moduleName) { if (!$this->isSchemaUpToDate($moduleName)) { $errors[] = $this->getSchemaInfo($moduleName); } if (!$this->isDataUpToDate($moduleName)) { $errors[] = $this->getDataInfo($moduleName); } } return $errors; }
/** * @return array */ public function getObservers() { if (!is_null($this->observers)) { return $this->observers; } $this->observers = []; foreach ($this->moduleList->getNames() as $module) { $parts = explode('_', $module); $class = 'Magento\\Tools\\SampleData\\Module\\' . $parts[1] . '\\Observer'; if (class_exists($class)) { $this->observers[] = $this->objectManager->get($class); } } return $this->observers; }
/** * Add Link to Head * * @return void */ protected function addHeadInclude() { $styleContent = ''; foreach ($this->moduleList->getNames() as $moduleName) { $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/styles.css'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } $style = file_get_contents($fileName); $styleContent .= preg_replace('/^\\/\\*[\\s\\S]+\\*\\//', '', $style); } if (empty($styleContent)) { return; } $mediaDir = $this->directoryList->getPath(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA); file_put_contents("{$mediaDir}/styles.css", $styleContent); $linkTemplate = '<link rel="stylesheet" type="text/css" media="all" href="%sstyles.css" />'; $baseUrl = $this->baseUrl->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]); $linkText = sprintf($linkTemplate, $baseUrl); $miscScriptsNode = 'design/head/includes'; $miscScripts = $this->scopeConfig->getValue($miscScriptsNode); if (!$miscScripts || strpos($miscScripts, $linkText) === false) { $this->configWriter->save($miscScriptsNode, $miscScripts . $linkText); $this->configCacheType->clean(); } }
/** * Run installation in context of the specified admin user * * @param $userName * @param array $modules * @return void * @throws \Exception */ public function run($userName, array $modules = []) { set_time_limit(0); /** @var \Magento\User\Model\User $user */ $user = $this->userFactory->create()->loadByUsername($userName); if (!$user->getId()) { throw new \Exception('Invalid admin user provided'); } $this->state->start(); $this->session->setUser($user); $this->deploy->run(); $resources = $this->initResources($modules); $this->state->clearErrorFlag(); try { foreach ($this->moduleList->getNames() as $moduleName) { if (isset($resources[$moduleName])) { $resourceType = $resources[$moduleName]; $this->setupFactory->create($resourceType)->run(); $this->postInstaller->addModule($moduleName); } } $this->session->unsUser(); $this->postInstaller->run(); $this->state->finish(); } catch (\Exception $e) { $this->state->setError(); $this->logger->log($e->getMessage()); } }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing categories:'); $this->isMediaInstalled(); foreach ($this->moduleList->getNames() as $moduleName) { $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/categories.csv'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); foreach ($csvReader as $row) { $this->createCategory($row); } } }
/** * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $html = $this->_getHeaderHtml($element); $modules = $this->_moduleList->getNames(); $dispatchResult = new \Magento\Framework\Object($modules); $this->_eventManager->dispatch('adminhtml_system_config_advanced_disableoutput_render_before', ['modules' => $dispatchResult]); $modules = $dispatchResult->toArray(); sort($modules); foreach ($modules as $moduleName) { if ($moduleName === 'Magento_Backend') { continue; } $html .= $this->_getFieldHtml($element, $moduleName); } $html .= $this->_getFooterHtml($element); return $html; }
/** * Run installation in context of the specified admin user * * @param \Magento\User\Model\User $adminUser * @throws \Exception * * @return void */ public function run(\Magento\User\Model\User $adminUser) { set_time_limit(3600); if (!$adminUser || !$adminUser->getId()) { throw new \Exception('Invalid admin user provided'); } $this->session->setUser($adminUser); $this->deploy->run(); $resources = $this->initResources(); foreach ($this->moduleList->getNames() as $moduleName) { if (isset($resources[$moduleName])) { $resourceType = $resources[$moduleName]; $this->setupFactory->create($resourceType)->run(); $this->postInstaller->addModule($moduleName); } } $this->session->unsUser(); $this->postInstaller->run(); }
/** * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $html = $this->_getHeaderHtml($element); $modules = $this->_moduleList->getNames(); $wsaApproved = array('webshopapps', 'shipperhq'); sort($modules); $viewAllExtns = $this->_scopeConfig->isSetFlag('shqlogmenu/shqlogger/view_all_extns', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); foreach ($modules as $moduleName) { if ($moduleName === 'Mage_Adminhtml' || $moduleName === 'ShipperHQ_Common' || $moduleName === 'ShipperHQ_Logger' || stripos($moduleName, 'Mage_') !== false) { continue; } $providerArray = explode('_', $moduleName); $provider = strtolower($providerArray[0]); if (!$viewAllExtns && !in_array($provider, $wsaApproved)) { continue; } $html .= $this->_getFieldHtml($element, $moduleName); } $html .= $this->_getFooterHtml($element); return $html; }
/** * Retrieve priority of a module relatively to other modules in the system * * @param string $moduleName * @return int */ protected function getModulePriority($moduleName) { if ($this->orderedModules === null) { $this->orderedModules = $this->moduleList->getNames(); } $result = array_search($moduleName, $this->orderedModules); // Assume unknown modules have the same priority, distinctive from known modules if ($result === false) { return -1; } return $result; }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing catalog attributes:'); $attributeCount = 0; foreach ($this->moduleList->getNames() as $moduleName) { $fileName = substr($moduleName, strpos($moduleName, "_") + 1) . '/attributes.csv'; $fileName = $this->fixtureHelper->getPath($fileName); if (!$fileName) { continue; } $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); foreach ($csvReader as $data) { $data['attribute_set'] = explode("\n", $data['attribute_set']); /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */ $attribute = $this->eavConfig->getAttribute('catalog_product', $data['attribute_code']); if (!$attribute) { $attribute = $this->attributeFactory->create(); } $frontendLabel = explode("\n", $data['frontend_label']); if (count($frontendLabel) > 1) { $data['frontend_label'] = []; $data['frontend_label'][\Magento\Store\Model\Store::DEFAULT_STORE_ID] = $frontendLabel[0]; $data['frontend_label'][$this->storeManager->getStoreId()] = $frontendLabel[1]; } $data['option'] = $this->getOption($attribute, $data); $data['source_model'] = $this->productHelper->getAttributeSourceModelByInputType($data['frontend_input']); $data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType($data['frontend_input']); $data += ['is_filterable' => 0, 'is_filterable_in_search' => 0, 'apply_to' => []]; $data['backend_type'] = $attribute->getBackendTypeByInput($data['frontend_input']); $attribute->addData($data); $attribute->setIsUserDefined(1); $attribute->setEntityTypeId($this->getEntityTypeId()); $attribute->save(); $attributeId = $attribute->getId(); if (is_array($data['attribute_set'])) { foreach ($data['attribute_set'] as $setName) { $setName = trim($setName); $attributeCount++; $attributeSet = $this->processAttributeSet($setName); $attributeGroupId = $attributeSet->getDefaultGroupId(); $attribute = $this->attributeFactory->create(); $attribute->setId($attributeId)->setAttributeGroupId($attributeGroupId)->setAttributeSetId($attributeSet->getId())->setEntityTypeId($this->getEntityTypeId())->setSortOrder($attributeCount + 999)->save(); } } $this->logger->logInline('.'); } } $this->eavConfig->clear(); }
/** * Retrieve list of module action files * * @return array */ public function getActionFiles() { $actions = []; foreach ($this->modulesList->getNames() as $moduleName) { $actionDir = $this->getModuleDir('Controller', $moduleName); if (!file_exists($actionDir)) { continue; } $dirIterator = new \RecursiveDirectoryIterator($actionDir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::LEAVES_ONLY); /** @var \SplFileInfo $actionFile */ foreach ($recursiveIterator as $actionFile) { $actions[] = $this->modulesDirectory->getRelativePath($actionFile->getPathname()); } } return $actions; }
/** * Retrieve list of module action files * * @return array */ public function getActionFiles() { $actions = []; foreach ($this->modulesList->getNames() as $moduleName) { $actionDir = $this->getModuleDir('Controller', $moduleName); if (!file_exists($actionDir)) { continue; } $dirIterator = new \RecursiveDirectoryIterator($actionDir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::LEAVES_ONLY); /** @var \SplFileInfo $actionFile */ $namespace = str_replace('_', '\\', $moduleName); foreach ($recursiveIterator as $actionFile) { $actionName = str_replace('/', '\\', str_replace($actionDir, '', $actionFile->getPathname())); $action = $namespace . "\\Controller" . substr($actionName, 0, -4); $actions[strtolower($action)] = $action; } } return $actions; }
/** * Installs DB schema * * @return void */ public function installSchema() { $this->assertDeploymentConfigExists(); $this->assertDbAccessible(); $moduleNames = $this->moduleList->getNames(); $this->log->log('Schema creation/updates:'); foreach ($moduleNames as $moduleName) { $this->log->log("Module '{$moduleName}':"); $setup = $this->setupFactory->createSetupModule($this->log, $moduleName); $setup->applyUpdates(); $this->logProgress(); } $this->log->log('Schema post-updates:'); foreach ($moduleNames as $moduleName) { $this->log->log("Module '{$moduleName}':"); $setup = $this->setupFactory->createSetupModule($this->log, $moduleName); $setup->applyRecurringUpdates(); } }
/** * Returns an array of enabled modules * * @return string[] */ public function getModules() { return $this->moduleList->getNames(); }
/** * Generates list of ModuleContext * * @param \Magento\Framework\Module\ModuleResource $resource * @param string $type * @return ModuleContext[] * @throws \Magento\Setup\Exception */ private function generateListOfModuleContext($resource, $type) { $moduleContextList = []; foreach ($this->moduleList->getNames() as $moduleName) { if ($type === 'schema-version') { $dbVer = $resource->getDbVersion($moduleName); } elseif ($type === 'data-version') { $dbVer = $resource->getDataVersion($moduleName); } else { throw new \Magento\Setup\Exception("Unsupported version type $type is requested"); } if ($dbVer !== false) { $moduleContextList[$moduleName] = new ModuleContext($dbVer); } else { $moduleContextList[$moduleName] = new ModuleContext(''); } } return $moduleContextList; }