diff --git a/Makefile b/Makefile index 218076dced..bf6fb9562a 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ php-shell: .PHONY psql-shell: .PHONY docker exec -it $(call translate-container-name,$(strip $(DIR))_db_1) sh -c "psql -U postgres social" +database-force-nuke: + docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c "cd /var/www/social; bin/console doctrine:database:drop --force && bin/console doctrine:database:create && bin/console doctrine:schema:update --dump-sql --force && bin/console app:populate_initial_values" + database-force-schema-update: docker exec -it $(call translate-container-name,$(strip $(DIR))_php_1) sh -c "/var/www/social/bin/console doctrine:schema:update --dump-sql --force" diff --git a/docker/social/install.sh b/docker/social/install.sh index b20307e958..7f54e76a13 100755 --- a/docker/social/install.sh +++ b/docker/social/install.sh @@ -28,8 +28,9 @@ if [ ${DB_EXISTS} -ne 0 ]; then chmod g+w -R . chown -R :www-data . - php bin/console doctrine:database:create || exit 1 - php bin/console doctrine:schema:create || exit 1 + php bin/console doctrine:database:create || exit 1 + php bin/console doctrine:schema:create || exit 1 + php bin/console app:populate_initial_values || exit 1 echo "GNU social is installed" else diff --git a/src/Command/PopulateInitialValuesCommand.php b/src/Command/PopulateInitialValuesCommand.php new file mode 100644 index 0000000000..d4ee7d9c74 --- /dev/null +++ b/src/Command/PopulateInitialValuesCommand.php @@ -0,0 +1,82 @@ +. +// }}} + +/** + * 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\DB; +use App\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; + } +}