/** * Executes the database initialization and update. * * @param InputInterface $input Input object * @param OutputInterface $output Output object */ protected function execute(InputInterface $input, OutputInterface $output) { $ctx = $this->getContainer()->get('aimeos_context')->get(false, 'command'); $ctx->setEditor('aimeos:setup'); $config = $ctx->getConfig(); $site = $input->getArgument('site'); $tplsite = $input->getArgument('tplsite'); $config->set('setup/site', $site); $dbconfig = $this->getDbConfig($config); $this->setOptions($config, $input); $taskPaths = $this->getContainer()->get('aimeos')->get()->getSetupPaths($tplsite); $manager = new \Aimeos\MW\Setup\Manager\Multiple($ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx); $output->writeln(sprintf('Initializing or updating the Aimeos database tables for site <info>%1$s</info>', $site)); if (($task = $input->getOption('task')) && is_array($task)) { $task = reset($task); } switch ($input->getOption('action')) { case 'migrate': $manager->migrate($task); break; case 'rollback': $manager->rollback($task); break; case 'clean': $manager->clean($task); break; default: throw new \Exception(sprintf('Invalid setup action "%1$s"', $input->getOption('action'))); } }
/** * Executes the setup tasks for updating the database. * * The setup tasks print their information directly to the standard output. * To avoid this, it's necessary to use the output buffering handler * (ob_start(), ob_get_contents() and ob_end_clean()). */ public static function execute() { ini_set('max_execution_time', 0); $aimeos = \Aimeos\Aimeos\Base::getAimeos(); $sitecode = \Aimeos\Aimeos\Base::getExtConfig('siteCode', 'default'); $taskPaths = $aimeos->getSetupPaths('default'); $ctx = self::getContext(); $dbm = $ctx->getDatabaseManager(); $config = $ctx->getConfig(); $config->set('setup/site', $sitecode); $dbconfig = $config->get('resource', array()); foreach ($dbconfig as $rname => $dbconf) { if (strncmp($rname, 'db', 2) !== 0) { unset($dbconfig[$rname]); } else { $config->set("resource/{$rname}/limit", 2); } } $class = 'TYPO3\\CMS\\Extbase\\Object\\ObjectManager'; $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($class); $utility = $objectManager->get('TYPO3\\CMS\\Extensionmanager\\Utility\\ConfigurationUtility'); $conf = $utility->convertValuedToNestedConfiguration($utility->getCurrentConfiguration('aimeos')); $value = isset($conf['useDemoData']) ? $conf['useDemoData'] : ''; $local = array('setup' => array('default' => array('demo' => (string) $value))); $ctx->setConfig(new \Aimeos\MW\Config\Decorator\Memory($config, $local)); $manager = new \Aimeos\MW\Setup\Manager\Multiple($dbm, $dbconfig, $taskPaths, $ctx); $manager->migrate(); $conf['useDemoData'] = ''; $utility->writeConfiguration($conf, 'aimeos'); }
/** * Execute the console command. * * @return mixed */ public function fire() { $ctx = $this->getLaravel()->make('\\Aimeos\\Shop\\Base\\Context')->get(false, 'command'); $ctx->setEditor('aimeos:setup'); $config = $ctx->getConfig(); $site = $this->argument('site'); $template = $this->argument('tplsite'); $config->set('setup/site', $site); $dbconfig = $this->getDbConfig($config); $this->setOptions($config); $taskPaths = $this->getLaravel()->make('\\Aimeos\\Shop\\Base\\Aimeos')->get()->getSetupPaths($template); $manager = new \Aimeos\MW\Setup\Manager\Multiple($ctx->getDatabaseManager(), $dbconfig, $taskPaths, $ctx); $this->info(sprintf('Initializing or updating the Aimeos database tables for site "%1$s"', $site)); if (($task = $this->option('task')) && is_array($task)) { $task = reset($task); } switch ($this->option('action')) { case 'migrate': $manager->migrate($task); break; case 'rollback': $manager->rollback($task); break; case 'clean': $manager->clean($task); break; default: throw new \Exception(sprintf('Invalid setup action "%1$s"', $this->option('action'))); } }
public function testMigrate() { $taskPath = __DIR__ . DIRECTORY_SEPARATOR . 'tasks'; $conf = array('db' => $this->config->get('resource/db', array())); $object = new \Aimeos\MW\Setup\Manager\Multiple($this->dbm, $conf, $taskPath); ob_start(); $object->migrate(); $result = ob_get_contents(); ob_end_clean(); $this->assertContains('OneTask', $result); $this->assertContains('TwoTask', $result); }
/** * Initialize or update the Aimeos database tables * * After installing and updating the Aimeos package, the database structure * must be created or upgraded to the current version. Depending on the size * of the database, this may take a while. * * @param string $site Site for updating database entries * @param string $tplsite Template site for creating or updating database entries * @param array $option Optional setup configuration, name and value are separated by ":" like "setup/default/demo:1". * @param string|null $task Setup task name to execute * @param string $action Setup task action, e.g. "migrate", "rollback" or "clean" * @return void */ public function setupCommand($site = 'default', $tplsite = 'default', array $option = array(), $task = null, $action = 'migrate') { $context = $this->objectManager->get('\\Aimeos\\Shop\\Base\\Context')->get(null, 'command'); $context->setEditor('aimeos:setup'); $config = $context->getConfig(); $config->set('setup/site', $site); $dbconfig = $this->getDbConfig($config); $this->setOptions($config, $option); $taskPaths = $this->objectManager->get('\\Aimeos\\Shop\\Base\\Aimeos')->get()->getSetupPaths($tplsite); $manager = new \Aimeos\MW\Setup\Manager\Multiple($context->getDatabaseManager(), $dbconfig, $taskPaths, $context); $this->outputFormatted('Initializing or updating the Aimeos database tables for site <b>%s</b>', array($site)); switch ($action) { case 'migrate': $manager->migrate($task); break; case 'rollback': $manager->rollback($task); break; case 'clean': $manager->clean($task); break; default: throw new \Exception(sprintf('Invalid setup action "%1$s"', $action)); } }
$taskPaths = $aimeos->getSetupPaths($tplsite); setIncludePaths($taskPaths); $conf = getConfig($aimeos->getConfigPaths(), $options); $conf->set('setup/site', $site); $dbconfig = getDbConfig($conf); $ctx = getContext($conf); $dbm = $ctx->getDatabaseManager(); $manager = new \Aimeos\MW\Setup\Manager\Multiple($dbm, $dbconfig, $taskPaths, $ctx); $action = isset($options['action']) ? $options['action'] : 'migrate'; $task = isset($options['task']) ? $options['task'] : null; switch ($action) { case 'clean': $manager->clean($task); break; case 'migrate': $manager->migrate($task); break; case 'rollback': $manager->rollback($task); break; default: throw new \Exception(sprintf('Invalid action "%1$s"', $action)); } } catch (Throwable $t) { echo "\n\nCaught PHP error while processing setup"; echo "\n\nMessage:\n"; echo $t->getMessage(); echo "\n\nStack trace:\n"; echo $t->getTraceAsString(); echo "\n\n"; exit(1);