2024-10-16 08:20:07 +02:00
|
|
|
<?php
|
2024-10-16 16:11:48 +02:00
|
|
|
|
2024-10-30 14:46:31 +01:00
|
|
|
namespace Deployer;
|
2024-10-17 08:54:34 +02:00
|
|
|
|
|
|
|
desc('run all database migrations');
|
2024-10-25 10:29:42 +02:00
|
|
|
task('shop:runMigration', [
|
2024-10-25 09:47:07 +02:00
|
|
|
'shop:setShopsOffline',
|
|
|
|
'shop:executeMigrations',
|
|
|
|
'shop:setShopsOnline'
|
2024-10-16 16:11:48 +02:00
|
|
|
]);
|
2024-10-16 23:22:22 +02:00
|
|
|
|
|
|
|
desc('set shops offline');
|
2024-10-25 09:47:07 +02:00
|
|
|
task('shop: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 {
|
2024-10-29 11:28:04 +01:00
|
|
|
warning('missing config, task skipped');
|
2024-10-16 23:22:22 +02:00
|
|
|
}
|
2024-10-17 08:54:34 +02:00
|
|
|
});
|
2024-10-16 23:22:22 +02:00
|
|
|
|
2024-10-25 10:29:42 +02:00
|
|
|
task('shop:runMigration:failed', function() {
|
2024-10-25 09:47:07 +02:00
|
|
|
invoke('shop:setShopsOnline');
|
2024-10-17 09:14:26 +02:00
|
|
|
})->hidden();
|
|
|
|
|
2024-10-25 10:29:42 +02:00
|
|
|
fail('shop:runMigration', 'shop:runMigration:failed');
|
2024-10-17 09:14:26 +02:00
|
|
|
|
|
|
|
desc('execute OXID Doctrine migrations');
|
2024-10-25 09:47:07 +02:00
|
|
|
task('shop:executeMigrations', function () {
|
2024-10-17 09:14:26 +02:00
|
|
|
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-25 10:29:42 +02:00
|
|
|
})->hidden();;
|
2024-10-17 09:14:26 +02:00
|
|
|
|
2024-10-16 23:22:22 +02:00
|
|
|
desc('set shops online');
|
2024-10-25 09:47:07 +02:00
|
|
|
task('shop: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 {
|
2024-10-29 11:28:04 +01:00
|
|
|
warning('missing config, task skipped');
|
2024-10-16 23:22:22 +02:00
|
|
|
}
|
2024-10-17 08:54:34 +02:00
|
|
|
});
|
|
|
|
|
2024-10-29 11:28:04 +01:00
|
|
|
desc('show version of current OXID installation');
|
2024-10-25 10:29:42 +02:00
|
|
|
task('shop:getVersion', function () {
|
2024-10-25 09:47:07 +02:00
|
|
|
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'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2024-10-29 11:28:04 +01:00
|
|
|
|
|
|
|
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}} ]")
|
|
|
|
) {
|
|
|
|
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');
|
|
|
|
if (askConfirmation('Do you really want to clone from "'.$source_name.'" to "{{db_name}}"? The target database "{{db_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}}");
|
2024-10-29 11:42:02 +01:00
|
|
|
info('creating views');
|
|
|
|
run('{{release_or_current_path}}/vendor/bin/oe-eshop-db_views_regenerate');
|
|
|
|
info('successfully finished');
|
2024-10-29 11:28:04 +01:00
|
|
|
} else {
|
|
|
|
info('abborted');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
warning('missing config, task skipped');
|
|
|
|
}
|
|
|
|
});
|