extract helper functions

This commit is contained in:
Daniel Seifert 2024-10-31 21:21:54 +01:00
bovenliggende 0c66cec2a2
commit 7deab9c67f
Getekend door: DanielS
GPG sleutel-ID: 6A513E13AEE66170
2 gewijzigde bestanden met toevoegingen van 24 en 13 verwijderingen

19
recipe/inc/database.php Normal file
Bestand weergeven

@ -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');
});

Bestand weergeven

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