105 Zeilen
4.7 KiB
PHP
105 Zeilen
4.7 KiB
PHP
<?php
|
|
|
|
namespace Deployer;
|
|
|
|
desc('run all database migrations');
|
|
task('shop:runMigration', [
|
|
'shop:setShopsOffline',
|
|
'shop:executeMigrations',
|
|
'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}} -e "'.$query.'"');
|
|
} else {
|
|
warning('missing config, task skipped');
|
|
}
|
|
});
|
|
|
|
task('shop:runMigration:failed', function() {
|
|
invoke('shop:setShopsOnline');
|
|
})->hidden();
|
|
|
|
fail('shop:runMigration', 'shop:runMigration:failed');
|
|
|
|
desc('execute OXID Doctrine migrations');
|
|
task('shop:executeMigrations', function () {
|
|
if (test("[ -f {{current_path}}/vendor/bin/oe-eshop-doctrine_migration ]")) {
|
|
run('{{bin/php}} {{current_path}}/vendor/bin/oe-eshop-doctrine_migration migrations:migrate');
|
|
}
|
|
})->hidden();;
|
|
|
|
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}} -e "'.$query.'"');
|
|
} else {
|
|
warning('missing config, task skipped');
|
|
}
|
|
});
|
|
|
|
desc('show version of current OXID installation');
|
|
task('shop:getVersion', function () {
|
|
if (test("[ -f {{current_path}}/composer.lock ]")) {
|
|
cd('{{current_path}}');
|
|
info(
|
|
run(
|
|
'{{bin/composer}} show oxid-esales/oxideshop-ce | grep -ws "versions" | cut -d " " -f 4'
|
|
)
|
|
);
|
|
}
|
|
});
|
|
|
|
desc('dump contents from source to destination database');
|
|
task('shop:cloneDatabase', function () {
|
|
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');
|
|
$source_port = ask('source database port', '3306');
|
|
$source_name = ask('source database name');
|
|
$source_user = ask('source database user');
|
|
$source_pass = askHiddenResponse('source database password');
|
|
$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");
|
|
info('creating views');
|
|
run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate');
|
|
info('successfully finished');
|
|
} else {
|
|
info('abborted');
|
|
}
|
|
} else {
|
|
warning('missing config, task skipped');
|
|
}
|
|
});
|
|
|
|
desc('rotate old database backups and create a new one');
|
|
task('shop:backupDatabase', function () {
|
|
if (get('mysql_configured') && get('mysqldump_configured')) {
|
|
if (!test("[ -f {{deploy_path}}/database/rotatemap.conf ]")) {
|
|
run('printf "{{deploy_path}}/database/backup/backup.sql {\n rotate 5\n}" > {{deploy_path}}/database/rotatemap.conf');
|
|
}
|
|
if (!test("[ -d {{deploy_path}}/database/backup ]")) {
|
|
run("mkdir -p {{deploy_path}}/database/backup");
|
|
}
|
|
$source_name = parse_ini_file(get('db_conf_path'))['database'];
|
|
if (test("[ -f {{deploy_path}}/database/backup/backup.sql ]")) {
|
|
run("logrotate -f -s {{deploy_path}}/database/rotatemap.state {{deploy_path}}/database/rotatemap.conf");
|
|
}
|
|
run("{{bin/mysqldump}} --defaults-extra-file={{db_conf_path}} --opt --no-create-db -f ".$source_name." $({{bin/mysql}} --defaults-extra-file={{db_conf_path}} -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;\") > {{deploy_path}}/database/backup/backup.sql");
|
|
info('successfully dumped to {{deploy_path}}/database/backup/backup.sql');
|
|
} else {
|
|
warning('missing config, task skipped');
|
|
}
|
|
});
|