more verif while installing

This commit is contained in:
Nicolas Lœuillet 2013-08-15 10:54:14 +02:00
parent ca1b0a1a6f
commit 4a2912880f
4 changed files with 72 additions and 30 deletions

View 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,6 +33,56 @@ class Poche
}
}
/**
* all checks before installation.
* @return boolean
*/
private function checkBeforeInstall()
{
$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 (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;
}
if (!$allIsGood) {
echo $this->tpl->render('error.twig', array(
'msg' => $msg
));
}
return $allIsGood;
}
private function initTpl()
{
# template engine
$loader = new Twig_Loader_Filesystem(TPL);
if (DEBUG_POCHE) {
$twig_params = array();
}
else {
$twig_params = array('cache' => CACHE);
}
$this->tpl = new Twig_Environment($loader, $twig_params);
$this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
# filter to display domain name of an url
$filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
$this->tpl->addFilter($filter);
# filter for reading time
$filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
$this->tpl->addFilter($filter);
}
private function init()
{
Tools::initPhp();
@ -55,24 +104,6 @@ class Poche
bindtextdomain($language, LOCALE);
textdomain($language);
# template engine
$loader = new Twig_Loader_Filesystem(TPL);
if (DEBUG_POCHE) {
$twig_params = array();
}
else {
$twig_params = array('cache' => CACHE);
}
$this->tpl = new Twig_Environment($loader, $twig_params);
$this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
# filter to display domain name of an url
$filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
$this->tpl->addFilter($filter);
# filter for reading time
$filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
$this->tpl->addFilter($filter);
# Pagination
$this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
}

View 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';

7
tpl/error.twig Normal file
View File

@ -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 %}

View 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>