From 4a2912880f0914b456711d695f96ce2ace18c814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 15 Aug 2013 10:54:14 +0200 Subject: more verif while installing --- inc/poche/Poche.class.php | 69 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 19 deletions(-) (limited to 'inc/poche/Poche.class.php') 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'); -- cgit v1.2.3