diff --git a/Console/Command/Activate.php b/Console/Command/Activate.php new file mode 100644 index 0000000..bdab39c --- /dev/null +++ b/Console/Command/Activate.php @@ -0,0 +1,157 @@ +configWriter = $configWriter; + $this->structure = $structure; + $this->moduleList = $moduleList; + $this->moduleManager = $moduleManager; + } + + /** + * @inheritDoc + */ + protected function configure() + { + $this->setName('magefan:license:activate') + ->setDescription('This is the console command to activate Magefan extensions license.') + ->addOption( + self::EXTENSION_NAME, + null, + InputOption::VALUE_REQUIRED, + 'Extension Name' + ) + ->addOption( + self::LICENSE_KEY, + null, + InputOption::VALUE_REQUIRED, + 'Extension License Key' + ); + parent::configure(); + } + + /** + * Execute the command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return null|int + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $extensionName = $input->getOption(self::EXTENSION_NAME); + $licenseKey = $input->getOption(self::LICENSE_KEY); + + if ($extensionName) { + $output->writeln('Provided extension name is `' . $extensionName . '`'); + } elseif ($licenseKey) { + $output->writeln('Provided license key is `' . $licenseKey . '`'); + } + + $output->writeln('Success Message.'); + $output->writeln('An error encountered.'); + $output->writeln('Some Comment.'); + + /* + if (in_array($extensionName, $this->getMagefanModules())) { + $this->configWriter->save('my/path/whatever', $extensionName, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); + $this->configWriter->save('my/path/whatever', $licenseKey, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); + $this->getConfigSections(); + } + */ + } + + /** + * Retrieve Magefan modules info + * + * @return array + */ + private function getMagefanModules() + { + $modules = []; + foreach ($this->moduleList->getNames() as $moduleName) { + if (strpos($moduleName, 'Magefan_') !== false && $this->moduleManager->isEnabled($moduleName)) { + $modules[] = $moduleName; + } + } + return $modules; + } + + private function getConfigSections() + { + $sections = []; + if (count($sections)) { + $tabs = $this->structure->getTabs(); + foreach ($tabs as $tab) { + if ($tab->getId() == 'magefan') { + $sections = $tab->getData()['children']; + break; + } + } + var_dump($sections); + } + + exit; + + return $sections; + } +} diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..37878e1 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,16 @@ + + + + + + + Magefan\Community\Console\Command\Activate + + + +