]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
more verif while installing
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Thu, 15 Aug 2013 08:54:14 +0000 (10:54 +0200)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Thu, 15 Aug 2013 08:54:14 +0000 (10:54 +0200)
inc/poche/Poche.class.php
inc/poche/config.inc.php
tpl/error.twig [new file with mode: 0644]
tpl/install.twig

index 82f0228e82b5914f7240ec875eb61b7cc5421633..1d8aaca2c6dcc8bb18e5e32e839325e5236a77a6 100644 (file)
@@ -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. <br />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. <br />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');
index ba8a9fa06cfcc1b8581634b38ad8e616d8dc9aca..ecbf1ce6816537785511d4299c688e01154c78f9 100644 (file)
@@ -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 <a href="http://inthepoche.com/?pages/Documentation">the documentation.</a>');
+}
 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 (file)
index 0000000..84c3bc1
--- /dev/null
@@ -0,0 +1,7 @@
+{% extends "layout.twig" %}
+{% block title %}{% trans "error" %}{% endblock %}
+{% block content %}
+    <h1>error</h1>
+        <p>{{ msg|raw }}</p>
+        <p>Don't forget <a href="http://inthepoche.com/?pages/Documentation">the documentation</a>.</p>
+{% endblock %}
\ No newline at end of file
index 8bcede0dfe3c133407d136ad055971a9820bf677..afb5b0f6bb1acd4f687ad7022e99509cc0ec2aec 100644 (file)
@@ -7,21 +7,21 @@
                 <p>
                     {% trans "poche is still not installed. Please fill the below form to install it. Don't hesitate to <a href='http://inthepoche.com/?pages/Documentation'>read the documentation on poche website</a>." %}
                 </p>
-                <div class="row">
+                <p class="row">
                     <label class="col w150p" for="login">{% trans "Login" %}</label>
                     <input class="col" type="text" id="login" name="login" placeholder="Login" tabindex="1" autofocus />
-                </div>
-                <div class="row">
+                </p>
+                <p class="row">
                     <label class="col w150p" for="password">{% trans "Password" %}</label>
                     <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2">
-                </div>
-                <div class="row">
+                </p>
+                <p class="row">
                     <label class="col w150p" for="password_repeat">{% trans "Repeat your password" %}</label>
                     <input class="col" type="password" id="password_repeat" name="password_repeat" placeholder="Password" tabindex="3">
-                </div>
-                <div class="row mts txtcenter">
+                </p>
+                <p class="row mts txtcenter">
                     <button class="bouton" type="submit" tabindex="4">{% trans "Install" %}</button>
-                </div>
+                </p>
             </fieldset>
             <input type="hidden" name="token" value="{{ token }}">
         </form>