public function testExecute() { $this->moduleList->expects($this->once())->method('getNames')->willReturn([]); $commandTester = new CommandTester($this->command); $commandTester->execute([]); $this->assertContains('List of active modules', $commandTester->getDisplay()); }
/** * {@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 ''; }
/** * 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; }
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); }
/** * Return info block html * @param \Magento\Framework\Data\Form\Element\AbstractElement $element * @return string */ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) { $m = $this->moduleList->getOne($this->getModuleName()); $html = '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;"> Login As Customer Extension v' . $m['setup_version'] . ' was developed by <a href="http://magefan.com/" target="_blank">MageFan</a>. </div>'; return $html; }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { $time = microtime(true); $ignoreDataUpdate = $input->getOption('ignore-data'); $headers = array('Setup', 'Module', 'DB', 'Data', 'Status'); if ($ignoreDataUpdate) { unset($headers[array_search('Data', $headers)]); } $errorCounter = 0; $table = array(); foreach ($this->moduleList->getAll() as $moduleName => $moduleInfo) { $moduleVersion = $moduleInfo['setup_version']; $dbVersion = $this->resource->getDbVersion($moduleName); if (!$ignoreDataUpdate) { $dataVersion = $this->resource->getDataVersion($moduleName); } $ok = $dbVersion == $moduleVersion; if ($ok && !$ignoreDataUpdate) { $ok = $dataVersion == $moduleVersion; } if (!$ok) { $errorCounter++; } $row = array('Module' => $moduleName, 'DB' => $dbVersion, 'Data' => $dataVersion); if (!$ignoreDataUpdate) { $row['Data-Version'] = $dataVersion; } $row['Status'] = $ok ? 'OK' : 'Error'; $table[] = $row; } //if there is no output format //highlight the status //and show error'd rows at bottom if (!$input->getOption('format')) { usort($table, function ($a, $b) { return $a['Status'] !== 'OK'; }); array_walk($table, function (&$row) { $status = $row['Status']; $availableStatus = array('OK' => 'info', 'Error' => 'error'); $statusString = sprintf('<%s>%s</%s>', $availableStatus[$status], $status, $availableStatus[$status]); $row['Status'] = $statusString; }); } if ($input->getOption('log-junit')) { $this->logJUnit($table, $input->getOption('log-junit'), microtime($time) - $time); } else { $this->getHelper('table')->setHeaders($headers)->renderByFormat($output, $table, $input->getOption('format')); //if no output format specified - output summary line if (!$input->getOption('format')) { if ($errorCounter > 0) { $this->writeSection($output, sprintf('%s error%s %s found!', $errorCounter, $errorCounter === 1 ? '' : 's', $errorCounter === 1 ? 'was' : 'were'), 'error'); } else { $this->writeSection($output, 'No setup problems were found.', 'info'); } } } }
/** * Constructor * * @param LoggerInterface $log * @param ModuleListInterface $moduleList * @param SetupFileResolver $fileResolver * @param string $moduleName * @param \Magento\Framework\App\Resource $resource * @param string $connectionName */ public function __construct(LoggerInterface $log, ModuleListInterface $moduleList, SetupFileResolver $fileResolver, $moduleName, \Magento\Framework\App\Resource $resource, $connectionName = SetupInterface::DEFAULT_SETUP_CONNECTION) { parent::__construct($resource, $connectionName); $this->logger = $log; $this->fileResolver = $fileResolver; $this->moduleConfig = $moduleList->getOne($moduleName); $this->resource = new Resource($resource); $this->resourceName = $this->fileResolver->getResourceCode($moduleName); }
/** * 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; } } }
/** * Get Magefan Modules Info * * @return $this */ protected function getMagefanModules() { $modules = array(); foreach ($this->_moduleList->getAll() as $moduleName => $module) { if (strpos($moduleName, 'Magefan_') !== false && $this->_moduleManager->isEnabled($moduleName)) { $modules[$moduleName] = $module; } } return $modules; }
protected function prepareModuleList($vendor) { $this->moduleList = []; foreach ($this->moduleListObject->getAll() as $moduleName => $info) { // First index is (probably always) vendor $moduleNameData = explode('_', $moduleName); if (!is_null($vendor) && strtolower($moduleNameData[0]) !== strtolower($vendor)) { continue; } $this->moduleList[] = [$info['name'], $info['setup_version']]; } }
/** * 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; }
/** * 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; }
/** * @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; }
protected function setUp() { $this->filePermissions = $this->getMock('Magento\Framework\Setup\FilePermissions', [], [], '', false); $this->configWriter = $this->getMock('Magento\Framework\App\DeploymentConfig\Writer', [], [], '', false); $this->configReader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); $this->config = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); $this->moduleList = $this->getMockForAbstractClass('Magento\Framework\Module\ModuleListInterface'); $this->moduleList->expects($this->any())->method('getOne')->willReturn( ['setup_version' => '2.0.0'] ); $this->moduleList->expects($this->any())->method('getNames')->willReturn( ['Foo_One', 'Bar_Two'] ); $this->moduleLoader = $this->getMock('Magento\Framework\Module\ModuleList\Loader', [], [], '', false); $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); $this->adminFactory = $this->getMock('Magento\Setup\Model\AdminAccountFactory', [], [], '', false); $this->logger = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface'); $this->random = $this->getMock('Magento\Framework\Math\Random', [], [], '', false); $this->connection = $this->getMockForAbstractClass('Magento\Framework\DB\Adapter\AdapterInterface'); $this->maintenanceMode = $this->getMock('Magento\Framework\App\MaintenanceMode', [], [], '', false); $this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); $this->objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); $this->contextMock = $this->getMock('Magento\Framework\Model\ResourceModel\Db\Context', [], [], '', false); $this->configModel = $this->getMock('Magento\Setup\Model\ConfigModel', [], [], '', false); $this->cleanupFiles = $this->getMock('Magento\Framework\App\State\CleanupFiles', [], [], '', false); $this->dbValidator = $this->getMock('Magento\Setup\Validator\DbValidator', [], [], '', false); $this->setupFactory = $this->getMock('Magento\Setup\Module\SetupFactory', [], [], '', false); $this->dataSetupFactory = $this->getMock('Magento\Setup\Module\DataSetupFactory', [], [], '', false); $this->sampleDataState = $this->getMock('Magento\Framework\Setup\SampleData\State', [], [], '', false); $this->componentRegistrar = $this->getMock('Magento\Framework\Component\ComponentRegistrar', [], [], '', false); $this->phpReadinessCheck = $this->getMock('Magento\Setup\Model\PhpReadinessCheck', [], [], '', false); $this->object = $this->createObject(); }
/** * {@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); } } }
/** * Tests modules data returns array and saving in DB * * @dataProvider itemDataProvider * @return void */ public function testGetModuleDataRefreshOrStatement($data) { $moduleCollectionMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\ResourceModel\\Module\\Collection')->disableOriginalConstructor()->getMock(); /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */ $itemMock = $this->getMock('Magento\\NewRelicReporting\\Model\\Module', ['getName', 'getData', 'setData', 'getState', 'save'], [], '', false); $modulesMockArray = ['Module_Name1' => ['name' => 'Module_Name1', 'setup_version' => '2.0.0', 'sequence' => []]]; $itemMock->setData($data); $testChangesMockArray = ['entity_id' => '3', 'name' => 'Name', 'active' => 'false', 'state' => 'enabled', 'setup_version' => '2.0.0', 'some_param' => 'some_value', 'updated_at' => '2015-09-02 18:38:17']; $itemMockArray = [$itemMock]; $enabledModulesMockArray = ['Module_Name2']; $allModulesMockArray = ['Module_Name1', 'Module_Name2']; $this->moduleCollectionFactoryMock->expects($this->any())->method('create')->willReturn($moduleCollectionMock); $this->moduleFactoryMock->expects($this->any())->method('create')->willReturn($itemMock); $itemMock->expects($this->any())->method('setData')->willReturnSelf(); $itemMock->expects($this->any())->method('save')->willReturnSelf(); $itemMock->expects($this->any())->method('getState')->willReturn($data['state']); $itemMock->expects($this->any())->method('getName')->willReturn($data['name']); $moduleCollectionMock->expects($this->any())->method('getItems')->willReturn($itemMockArray); $itemMock->expects($this->any())->method('getData')->willReturn($testChangesMockArray); $this->fullModuleListMock->expects($this->once())->method('getAll')->willReturn($modulesMockArray); $this->fullModuleListMock->expects($this->any())->method('getNames')->willReturn($allModulesMockArray); $this->moduleListMock->expects($this->any())->method('getNames')->willReturn($enabledModulesMockArray); $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will($this->returnValue(true)); $this->assertInternalType('array', $this->model->getModuleData()); }
/** * 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()); } }
/** * 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(); } }
/** * Magento version * * @return string */ public function getVersion() { $module = $this->moduleList->getOne('Magento_Backend'); if (is_array($module) && isset($module['setup_version'])) { return $module['setup_version']; } return '2.0.0'; }
/** * @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; }
/** * Check if DB data is up to date * * @param string $moduleName * @param string|bool $version * @return bool * @throws \UnexpectedValueException */ private function isModuleVersionEqual($moduleName, $version) { $module = $this->_moduleList->getModule($moduleName); if (empty($module['schema_version'])) { throw new \UnexpectedValueException("Schema version for module '{$moduleName}' is not specified"); } $configVer = $module['schema_version']; return $version !== false && version_compare($configVer, $version) === SetupInterface::VERSION_COMPARE_EQUAL; }
/** * Getting the version of Magento and the version of the extension * @return array */ protected function getVersions() { $version = array(); $productMetadata = $this->_objectManager->get('\\Magento\\Framework\\App\\ProductMetadata'); $version['storePlatformVersion'] = $productMetadata->getVersion(); $version['signifydClientApp'] = 'Magento 2'; $version['storePlatform'] = 'Magento 2'; $version['signifydClientAppVersion'] = (string) $this->_moduleList->getOne('Signifyd_Connect')['setup_version']; return $version; }
/** * 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(); }
/** * Apply database data updates whenever needed * * @return void */ public function updateData() { foreach (array_keys($this->_moduleList->getModules()) as $moduleName) { foreach ($this->_resourceResolver->getResourceList($moduleName) as $resourceName) { if (!$this->_moduleManager->isDbDataUpToDate($moduleName, $resourceName)) { $this->_setupFactory->create($resourceName, $moduleName)->applyDataUpdates(); } } } }
/** * Apply database data updates whenever needed * * @return void */ public function updateData() { if (!$this->_isUpdatedSchema) { return; } foreach (array_keys($this->_moduleList->getModules()) as $moduleName) { foreach ($this->_resourceResolver->getResourceList($moduleName) as $resourceName) { $this->_setupFactory->create($resourceName, $moduleName)->applyDataUpdates(); } } }
/** * @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; }
/** * Check if DB is up to date * * @return bool */ private function isDbUpToDate() { foreach (array_keys($this->moduleList->getModules()) as $moduleName) { foreach ($this->resourceResolver->getResourceList($moduleName) as $resourceName) { $isSchemaUpToDate = $this->moduleManager->isDbSchemaUpToDate($moduleName, $resourceName); $isDataUpToDate = $this->moduleManager->isDbDataUpToDate($moduleName, $resourceName); if (!$isSchemaUpToDate || !$isDataUpToDate) { return false; } } } return true; }
protected function addVendors() { $vendors = []; $moduleList = $this->moduleList->getAll(); foreach ($moduleList as $moduleName => $info) { // First index is (probably always) vendor $moduleNameData = explode('_', $moduleName); if (isset($moduleNameData[0])) { $vendors[] = $moduleNameData[0]; } } $this->infos['Vendors'] = implode(', ', array_unique($vendors)); }