2024-10-16 08:20:07 +02:00
|
|
|
<?php
|
|
|
|
namespace Deployer;
|
|
|
|
|
|
|
|
require 'recipe/composer.php';
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
|
|
|
|
import(__DIR__. '/inventory.yml');
|
|
|
|
|
|
|
|
// Hooks
|
|
|
|
|
|
|
|
after('deploy:failed', 'deploy:unlock');
|
2024-10-16 16:11:48 +02:00
|
|
|
after('deploy:vendors', 'deploy:d3OxidTasks');
|
|
|
|
|
|
|
|
/// Tasks
|
|
|
|
|
|
|
|
desc('Oxid related tasks');
|
|
|
|
task('deploy:d3OxidTasks', [
|
2024-10-17 08:54:34 +02:00
|
|
|
'deploy:clear_paths'
|
|
|
|
]);
|
|
|
|
|
|
|
|
desc('run all database migrations');
|
|
|
|
task('migrate', [
|
|
|
|
'migrate:setShopsOffline',
|
2024-10-17 09:14:26 +02:00
|
|
|
'migrate:executeMigrations',
|
2024-10-17 08:54:34 +02:00
|
|
|
'migrate:setShopsOnline'
|
2024-10-16 16:11:48 +02:00
|
|
|
]);
|
2024-10-16 23:22:22 +02:00
|
|
|
|
|
|
|
desc('set shops offline');
|
2024-10-17 08:54:34 +02:00
|
|
|
task('migrate:setShopsOffline', function() {
|
2024-10-16 23:22:22 +02:00
|
|
|
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
|
2024-10-17 08:50:46 +02:00
|
|
|
has('db_name') && strlen(get('db_name')) &&
|
|
|
|
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
|
2024-10-16 23:22:22 +02:00
|
|
|
) {
|
|
|
|
$query = "UPDATE oxshops SET oxactive = '0', OXREGISTERSUBJECT = CONCAT('..', OXREGISTERSUBJECT) WHERE oxactive = '1';";
|
2024-10-17 08:50:46 +02:00
|
|
|
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
|
2024-10-16 23:22:22 +02:00
|
|
|
} else {
|
|
|
|
info('missing config, task skipped');
|
|
|
|
}
|
2024-10-17 08:54:34 +02:00
|
|
|
});
|
2024-10-16 23:22:22 +02:00
|
|
|
|
2024-10-17 09:14:26 +02:00
|
|
|
task('migrate:failed', function() {
|
|
|
|
invoke('migrate:setShopsOnline');
|
|
|
|
})->hidden();
|
|
|
|
|
|
|
|
fail('migrate', 'migrate:failed');
|
|
|
|
|
|
|
|
desc('execute OXID Doctrine migrations');
|
|
|
|
task('migrate: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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-10-16 23:22:22 +02:00
|
|
|
desc('set shops online');
|
2024-10-17 08:54:34 +02:00
|
|
|
task('migrate:setShopsOnline', function() {
|
2024-10-16 23:22:22 +02:00
|
|
|
if (has('bin/mysql') && strlen(get('bin/mysql')) &&
|
2024-10-17 08:50:46 +02:00
|
|
|
has('db_name') && strlen(get('db_name')) &&
|
|
|
|
has('db_conf_path') && strlen(get('db_conf_path')) && test("[ -f {{db_conf_path}} ]")
|
2024-10-16 23:22:22 +02:00
|
|
|
) {
|
|
|
|
$query = "UPDATE oxshops SET oxactive = '1', OXREGISTERSUBJECT = SUBSTR(OXREGISTERSUBJECT, 3) WHERE oxactive = '0' AND OXREGISTERSUBJECT LIKE '..%';";
|
2024-10-17 08:50:46 +02:00
|
|
|
run('{{bin/mysql}} --defaults-extra-file={{db_conf_path}} {{db_name}} -e "'.$query.'"');
|
2024-10-16 23:22:22 +02:00
|
|
|
} else {
|
|
|
|
info('missing config, task skipped');
|
|
|
|
}
|
2024-10-17 08:54:34 +02:00
|
|
|
});
|
|
|
|
|
2024-10-17 16:27:48 +02:00
|
|
|
desc('create database coniguration file');
|
|
|
|
task('setup:createDbConfig', function () {
|
|
|
|
try {
|
|
|
|
if (!has('db_conf_path') || !strlen(get('db_conf_path'))) {
|
|
|
|
throw new \RuntimeException('missing db_conf_path option, task stopped');
|
|
|
|
}
|
|
|
|
if (!test('[ -d $(dirname "{{db_conf_path}}") ]')) {
|
|
|
|
throw new \RuntimeException('configured path {{db_conf_path}} missing, task stopped');
|
|
|
|
}
|
|
|
|
if (!test("[ -f {{db_conf_path}} ]")) {
|
|
|
|
run("touch {{db_conf_path}}");
|
|
|
|
}
|
|
|
|
if (test("[ -f {{db_conf_path}} ]")) {
|
|
|
|
$db_host = ask('database host', 'localhost');
|
|
|
|
$db_port = ask('database port', '3306');
|
|
|
|
$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}}');
|
|
|
|
info('config successful created');
|
|
|
|
} else {
|
|
|
|
throw new \RuntimeException('can not create {{db_conf_path}}, task stopped');
|
|
|
|
}
|
|
|
|
} catch(\RuntimeException $e) {
|
|
|
|
warning($e->getMessage());
|
|
|
|
}
|
|
|
|
});
|