. // }}} /** * Command to load the needed initial database values (like the language list) * * @package GNUsocial * @category Command * * @author Hugo Sales * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Command; use App\Core\DB; use Component\Language\Entity\Language; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Intl\Locales; /** * Get a list of event registered in GNU social * * Testing unfeasable, since it outputs stuff * * @codeCoverageIgnore */ class PopulateInitialValuesCommand extends Command { protected static $defaultName = 'app:populate_initial_values'; protected function configure() { $this->setDefinition([]) ->setDescription('Load the initial table values for tables like `language`') ->setHelp( <<<'EOF' The %command.name% command loads the initial table values for tables: php %command.full_name% Currently, this loads the initial values for the `language` table EOF, ); } protected function execute(InputInterface $input, OutputInterface $output): int { if (DB::count('language', []) !== 0) { $output->writeln('The `language` table already has values, aborting'); return 1; } foreach (Locales::getNames() as $key => $name) { DB::persist(Language::create(['locale' => $key, 'short_display' => $key, 'long_display' => $name])); } DB::flush(); $output->writeln('Populated the `language` table'); return 0; } }