OXID-Deployer/recipe/setupTasks.php

37 lines
1.4 KiB
PHP

<?php
namespace Deployer;
require_once 'inc/database.php';
desc('create database configuration 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}}") ]')) {
run('mkdir -p $(dirname "{{db_conf_path}}")');
if (!test('[ -d $(dirname "{{db_conf_path}}") ]')) {
throw new \RuntimeException('unable to create configured path {{db_conf_path}}, 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_name = ask('database name');
$db_user = ask('database user');
$db_pass = askHiddenResponse('database password');
run('printf "[client]\nuser='.$db_user.'\npassword=\"'.$db_pass.'\"\nhost='.$db_host.'\nport='.$db_port.'\n\n[mysql]\ndatabase=\"'.$db_name.'\"" > {{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());
}
});