extract helper functions

This commit is contained in:
Daniel Seifert 2024-10-31 21:21:54 +01:00
parent 0c66cec2a2
commit 7deab9c67f
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
2 changed files with 24 additions and 13 deletions

19
recipe/inc/database.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace Deployer;
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}} ]");
});
set('mysql_configured', function() {
return has('bin/mysql') && strlen(get('bin/mysql')) &&
get('database_configured');
});
set('mysqldump_configured', function() {
return has('bin/mysql') && strlen(get('bin/mysql')) &&
get('database_configured');
});

View File

@ -9,12 +9,11 @@ task('shop:runMigration', [
'shop:setShopsOnline' 'shop:setShopsOnline'
]); ]);
require_once 'inc/database.php';
desc('set shops offline'); desc('set shops offline');
task('shop:setShopsOffline', function() { task('shop:setShopsOffline', function() {
if (has('bin/mysql') && strlen(get('bin/mysql')) && if (get('mysql_configured')) {
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
$query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';"; $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}} {{db_name}} -e "'.$query.'"');
} else { } else {
@ -37,10 +36,7 @@ task('shop:executeMigrations', function () {
desc('set shops online'); desc('set shops online');
task('shop:setShopsOnline', function() { task('shop:setShopsOnline', function() {
if (has('bin/mysql') && strlen(get('bin/mysql')) && if (get('mysql_configured')) {
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
$query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';"; $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}} {{db_name}} -e "'.$query.'"');
} else { } else {
@ -62,11 +58,7 @@ task('shop:getVersion', function () {
desc('dump contents from source to destination database'); desc('dump contents from source to destination database');
task('shop:cloneDatabase', function () { task('shop:cloneDatabase', function () {
if (has('bin/mysql') && strlen(get('bin/mysql')) && if (get('mysql_configured') && get('mysqldump_configured')) {
has('bin/mysqldump') && strlen(get('bin/mysqldump')) &&
has('db_name') && strlen(get('db_name')) &&
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
) {
info('Note: Use a dedicated read only user for accessing the source database.'); info('Note: Use a dedicated read only user for accessing the source database.');
info('Using the following source database:'); info('Using the following source database:');
$source_host = ask('source database host', 'localhost'); $source_host = ask('source database host', 'localhost');