setName("thelia:generate-resources") ->setDescription("Outputs admin resources") ->setHelp("The thelia:generate-resources outputs admin resources.") ->addOption( 'output', null, InputOption::VALUE_OPTIONAL, 'Output format amid (string, sql, sql-i18n)', null ) ; } protected function execute(InputInterface $input, OutputInterface $output) { $class = new \ReflectionClass('Thelia\Core\Security\Resource\AdminResources'); $constants = $class->getConstants(); if (\count($constants) == 0) { throw new \RuntimeException('No resources found'); } switch ($input->getOption("output")) { case 'sql': $output->writeln( 'INSERT INTO ' . ResourceTableMap::TABLE_NAME . ' (`id`, `code`, `created_at`, `updated_at`) VALUES ' ); $compteur = 0; foreach ($constants as $constant => $value) { if ($constant == AdminResources::SUPERADMINISTRATOR) { continue; } $compteur++; $output->writeln( "($compteur, '$value', NOW(), NOW())" . ($constant === key(\array_slice($constants, -1, 1, true)) ? ';' : ',') ); } break; case 'sql-i18n': $output->writeln( 'INSERT INTO ' . ResourceI18nTableMap::TABLE_NAME . ' (`id`, `locale`, `title`) VALUES ' ); $compteur = 0; foreach ($constants as $constant => $value) { if ($constant == AdminResources::SUPERADMINISTRATOR) { continue; } $compteur++; $title = ucwords(str_replace('.', ' / ', str_replace('admin.', '', $value))); $output->writeln( "($compteur, 'en_US', '$title')," ); $output->writeln( "($compteur, 'fr_FR', '$title')" . ($constant === key(\array_slice($constants, -1, 1, true)) ? ';' : ',') ); } break; default: foreach ($constants as $constant => $value) { if ($constant == AdminResources::SUPERADMINISTRATOR) { continue; } $output->writeln('[' . $constant . "] => " . $value); } break; } } }