From 5ffd4361e457e4b7a1f72f3ab5e799245836cc11 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 3 Aug 2018 14:06:23 +0200 Subject: [PATCH] Fix #358, #355 and #342 Signed-off-by: Thomas Citharel --- .gitignore | 3 +- .gitlab-ci.yml | 6 ++-- admin/install.php | 8 +++-- .../Framadate/Services/InstallService.php | 32 +++++++++++-------- tpl/admin/install.tpl | 5 ++- tpl_c/.gitkeep | 0 6 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 tpl_c/.gitkeep diff --git a/.gitignore b/.gitignore index 69538d1..cf92027 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,8 @@ nav app/inc/config.php vendor cache/ -tpl_c/ +tpl_c/* +!tpl_c/.gitkeep .php_cs.cache .zanata-cache/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e56ec24..976a30b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,7 +10,6 @@ test: stage: test script: - composer install -o --no-interaction --no-progress --prefer-dist - - mkdir tpl_c - php vendor/bin/php-cs-fixer fix --verbose --dry-run - vendor/bin/phpunit --bootstrap app/tests/bootstrap.php --debug app/tests cache: @@ -39,10 +38,10 @@ pages: - git checkout ${latesttag} - composer install -o --no-interaction --no-progress --prefer-dist --no-dev - composer dump-autoload --optimize --no-dev --classmap-authoritative - - mkdir tpl_c - mkdir framadate - mv `ls -A | grep -v framadate` ./framadate - - chmod -R 644 framadate/ && chmod -R 770 framadate/tpl_c/ && chmod -R 770 framadate/app/inc/ + - find framadate/ -type d -exec chmod 750 {} \; + - find framadate/ -type f -exec chmod 640 {} \; - zip -r latest.zip framadate - mkdir .public - cp latest.zip .public @@ -64,7 +63,6 @@ beta: - composer dump-autoload --optimize --no-dev --classmap-authoritative - if [ ! -z ${ZANATA_CONFIG_FRAMABOT+x} ]; then mkdir -p ${HOME}/.config; echo -e "${ZANATA_CONFIG_FRAMABOT}" > ${HOME}/.config/zanata.ini; fi - if [ ! -z ${ZANATA_CONFIG_FRAMABOT+x} ]; then make pull-locales; fi - - mkdir tpl_c - mkdir .public - cp -r * .public - cp -r .git .public diff --git a/admin/install.php b/admin/install.php index 2876120..ee9edd3 100644 --- a/admin/install.php +++ b/admin/install.php @@ -37,11 +37,13 @@ if (!empty($_POST)) { if ($result['status'] === 'OK') { header(('Location: ' . Utils::get_server_name() . 'admin/migration.php')); exit; - } - $error = __('Error', $result['code']); + } + + $error = __('Error', $result['code']); } $smarty->assign('error', $error); +$smarty->assign('error_details', $result['details']); $smarty->assign('title', __('Admin', 'Installation')); $smarty->assign('fields', $installService->getFields()); -$smarty->display('admin/install.tpl'); \ No newline at end of file +$smarty->display('admin/install.tpl'); diff --git a/app/classes/Framadate/Services/InstallService.php b/app/classes/Framadate/Services/InstallService.php index 13672fa..8f9f668 100644 --- a/app/classes/Framadate/Services/InstallService.php +++ b/app/classes/Framadate/Services/InstallService.php @@ -55,9 +55,10 @@ class InstallService { } // Connect to database - $connect = $this->connectTo($this->fields['dbConnectionString'], $this->fields['dbUser'], $this->fields['dbPassword']); - if (!$connect) { - return $this->error('CANT_CONNECT_TO_DATABASE'); + try { + $connect = $this->connectTo($this->fields['dbConnectionString'], $this->fields['dbUser'], $this->fields['dbPassword']); + } catch(\Exception $e) { + return $this->error('CANT_CONNECT_TO_DATABASE', $e->getMessage()); } // Write configuration to conf.php file @@ -68,15 +69,19 @@ class InstallService { return $this->ok(); } + /** + * Connect to PDO compatible source + * + * @param string $connectionString + * @param string $user + * @param string $password + * @return \PDO + */ function connectTo($connectionString, $user, $password) { - try { - $pdo = @new \PDO($connectionString, $user, $password); - $pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - return $pdo; - } catch(\Exception $e) { - return null; - } + $pdo = @new \PDO($connectionString, $user, $password); + $pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ); + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + return $pdo; } function writeConfiguration(Smarty &$smarty) { @@ -110,10 +115,11 @@ class InstallService { * @param $msg * @return array */ - function error($msg) { + function error($msg, $details = '') { return [ 'status' => 'ERROR', - 'code' => $msg + 'code' => $msg, + 'details' => $details, ]; } diff --git a/tpl/admin/install.tpl b/tpl/admin/install.tpl index 38f613c..21b9cbc 100644 --- a/tpl/admin/install.tpl +++ b/tpl/admin/install.tpl @@ -6,7 +6,10 @@
{if $error} -
{$error}
+
+

{$error}

+ {$error_details} +
{/if}
diff --git a/tpl_c/.gitkeep b/tpl_c/.gitkeep new file mode 100644 index 0000000..e69de29