From 05b7443a3adfed82cead1baf40c716656f3f0e42 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 1 Nov 2024 21:49:52 +0100 Subject: [PATCH] remove db_name configuration --- recipe/inc/database.php | 4 +--- recipe/setupTasks.php | 5 +++-- recipe/shopTasks.php | 10 ++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/recipe/inc/database.php b/recipe/inc/database.php index 29ca6cb..1ebb7af 100644 --- a/recipe/inc/database.php +++ b/recipe/inc/database.php @@ -7,8 +7,7 @@ set('db_conf_path', function () { }); set('database_configured', function() { - return has('db_name') && strlen(get('db_name')) && - has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]"); + return has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]"); }); set('mysql_configured', function() { @@ -20,4 +19,3 @@ set('mysqldump_configured', function() { return has('bin/mysql') && strlen(get('bin/mysql')) && get('database_configured'); }); - diff --git a/recipe/setupTasks.php b/recipe/setupTasks.php index cf3603e..4267020 100644 --- a/recipe/setupTasks.php +++ b/recipe/setupTasks.php @@ -22,9 +22,10 @@ task('setup:createDbConfig', function () { if (test("[ -f {{db_conf_path}} ]")) { $db_host = ask('database host', 'localhost'); $db_port = ask('database port', '3306'); + $db_name = ask('database name'); $db_user = ask('database user'); $db_pass = askHiddenResponse('database password'); - run('printf "[mysql]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysqldump]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'" > {{db_conf_path}}'); + run('printf "[mysql]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\ndatabase=\"'.$db_name.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysqldump]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\ndatabase=\"'.$db_name.'\"\nhost='.$db_host.'\nport='.$db_port.'" > {{db_conf_path}}'); info('config successful created'); } else { throw new \RuntimeException('can not create {{db_conf_path}}, task stopped'); @@ -32,4 +33,4 @@ task('setup:createDbConfig', function () { } catch(\RuntimeException $e) { warning($e->getMessage()); } -}); \ No newline at end of file +}); diff --git a/recipe/shopTasks.php b/recipe/shopTasks.php index 732524b..bc155aa 100644 --- a/recipe/shopTasks.php +++ b/recipe/shopTasks.php @@ -9,13 +9,14 @@ task('shop:runMigration', [ 'shop:setShopsOnline' ]); + require_once 'inc/database.php'; desc('set shops offline'); task('shop:setShopsOffline', function() { if (get('mysql_configured')) { $query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';"; - run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); + run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"'); } else { warning('missing config, task skipped'); } @@ -38,7 +39,7 @@ desc('set shops online'); task('shop:setShopsOnline', function() { if (get('mysql_configured')) { $query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';"; - run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"'); + run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} -e "'.$query.'"'); } else { warning('missing config, task skipped'); } @@ -66,10 +67,11 @@ task('shop:cloneDatabase', function () { $source_name = ask('source database name'); $source_user = ask('source database user'); $source_pass = askHiddenResponse('source database password'); - if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "{{db_name}}"? The target database "{{db_name}}" will be overwritten!')) { + $target_name = parse_ini_file(get('db_conf_path'))['database']; + if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "'.$target_name.'"? The target database "'.$target_name.'" will be overwritten!')) { info('cloning database'); $auth = "-h".$source_host." -P".$source_port." -u".$source_user." -p'".$source_pass."'"; - run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f {{db_name}}"); + run("{{bin/mysqldump}} ".$auth." --opt --no-create-db -f ".$source_name." $({{bin/mysql}} ".$auth." -ANe\"SET group_concat_max_len = 10485760; SELECT GROUP_CONCAT(table_name SEPARATOR ' ') FROM information_schema.tables WHERE table_schema='".$source_name."' AND engine IS NOT NULL;\") | {{bin/mysql}} --defaults-extra-file={{db_conf_path}} -f"); info('creating views'); run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate'); info('successfully finished');