From 4a2912880f0914b456711d695f96ce2ace18c814 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 15 Aug 2013 10:54:14 +0200 Subject: [PATCH] more verif while installing --- inc/poche/Poche.class.php | 69 ++++++++++++++++++++++++++++----------- inc/poche/config.inc.php | 4 +++ tpl/error.twig | 7 ++++ tpl/install.twig | 16 ++++----- 4 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 tpl/error.twig diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 82f0228e..1d8aaca2 100644 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -18,11 +18,10 @@ class Poche function __construct() { - if (file_exists('./install') && !DEBUG_POCHE) { - Tools::logm('folder /install exists'); - die('If you want to update your poche, you just have to delete /install folder.
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.'); + $this->initTpl(); + if (!$this->checkBeforeInstall()) { + exit; } - $this->store = new Database(); $this->init(); $this->messages = new Messages(); @@ -34,27 +33,37 @@ class Poche } } - private function init() + /** + * all checks before installation. + * @return boolean + */ + private function checkBeforeInstall() { - Tools::initPhp(); - Session::init(); + $msg = ''; + $allIsGood = TRUE; + if (file_exists('./install') && !DEBUG_POCHE) { + Tools::logm('folder /install exists'); + $msg = 'If you want to update your poche, you just have to delete /install folder.
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.'; + $allIsGood = FALSE; + } - if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { - $this->user = $_SESSION['poche_user']; + if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) { + Tools::logm('you don\'t have write access on db file'); + $msg = 'You don\'t have write access on ' . STORAGE_SQLITE . ' file.'; + $allIsGood = FALSE; } - else { - # fake user, just for install & login screens - $this->user = new User(); - $this->user->setConfig($this->getDefaultConfig()); + + if (!$allIsGood) { + echo $this->tpl->render('error.twig', array( + 'msg' => $msg + )); } - # l10n - $language = $this->user->getConfigValue('language'); - putenv('LC_ALL=' . $language); - setlocale(LC_ALL, $language); - bindtextdomain($language, LOCALE); - textdomain($language); + return $allIsGood; + } + private function initTpl() + { # template engine $loader = new Twig_Loader_Filesystem(TPL); if (DEBUG_POCHE) { @@ -72,6 +81,28 @@ class Poche # filter for reading time $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); $this->tpl->addFilter($filter); + } + + private function init() + { + Tools::initPhp(); + Session::init(); + + if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) { + $this->user = $_SESSION['poche_user']; + } + else { + # fake user, just for install & login screens + $this->user = new User(); + $this->user->setConfig($this->getDefaultConfig()); + } + + # l10n + $language = $this->user->getConfigValue('language'); + putenv('LC_ALL=' . $language); + setlocale(LC_ALL, $language); + bindtextdomain($language, LOCALE); + textdomain($language); # Pagination $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php index ba8a9fa0..ecbf1ce6 100644 --- a/inc/poche/config.inc.php +++ b/inc/poche/config.inc.php @@ -34,6 +34,10 @@ define ('PAGINATION', '10'); define ('THEME', 'light'); # /!\ Be careful if you change the lines below /!\ +if (!file_exists('./vendor/autoload.php')) { + die('Twig does not seem installed. Have a look at the documentation.'); +} + require_once './inc/poche/User.class.php'; require_once './inc/poche/Tools.class.php'; require_once './inc/poche/Url.class.php'; diff --git a/tpl/error.twig b/tpl/error.twig new file mode 100644 index 00000000..84c3bc1c --- /dev/null +++ b/tpl/error.twig @@ -0,0 +1,7 @@ +{% extends "layout.twig" %} +{% block title %}{% trans "error" %}{% endblock %} +{% block content %} +

error

+

{{ msg|raw }}

+

Don't forget the documentation.

+{% endblock %} \ No newline at end of file diff --git a/tpl/install.twig b/tpl/install.twig index 8bcede0d..afb5b0f6 100644 --- a/tpl/install.twig +++ b/tpl/install.twig @@ -7,21 +7,21 @@

{% trans "poche is still not installed. Please fill the below form to install it. Don't hesitate to read the documentation on poche website." %}

-
+

-

-
+

+

-

-
+

+

-

-
+

+

-

+

-- 2.41.0