1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-01 17:38:38 +00:00

changes for 1026 for PDO exceptions

This commit is contained in:
Thomas Citharel 2015-01-27 00:41:25 +01:00
parent 369e00e60b
commit ca056e7fd1
2 changed files with 130 additions and 140 deletions

View file

@ -13,19 +13,6 @@ $successes = array();
require_once('wallabag_compatibility_test.php');
/* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
* Idea : nbari at dalmp dot com
* Rights unknown
* Here in case of .gitignore files
*/
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
if (isset($_GET['clean'])) {
if (is_dir('install')){
delTree('install');
@ -60,27 +47,10 @@ if (isset($_POST['download'])) {
else if (isset($_POST['install'])) {
if (!is_dir('vendor')) {
$errors[] = 'You must install twig before.';
}
else {
} else {
$continue = true;
// Create config.inc.php
if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
$errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
$continue = false;
}
else {
function generate_salt() {
mt_srand(microtime(true)*100000 + memory_get_usage(true));
return md5(uniqid(mt_rand(), true));
}
$content = file_get_contents('inc/poche/config.inc.php');
$salt = generate_salt();
$content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
file_put_contents('inc/poche/config.inc.php', $content);
}
if ($continue) {
$content = file_get_contents('inc/poche/config.inc.default.php');
// User informations
$username = trim($_POST['username']);
@ -89,19 +59,20 @@ else if (isset($_POST['install'])) {
// Database informations
$moreQueries = array();
if ($_POST['db_engine'] == 'sqlite') {
if (!copy('install/poche.sqlite', 'db/poche.sqlite')) {
$errors[] = 'Impossible to create inc/poche/config.inc.php file.';
$continue = false;
$errors[] = 'Impossible to create the SQLite database file.';
}
else {
$db_path = 'sqlite:' . realpath('') . '/db/poche.sqlite';
$handle = new PDO($db_path);
$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql_structure = "";
}
}
else {
$content = file_get_contents('inc/poche/config.inc.php');
} else {
// MySQL and Postgre
try {
if ($_POST['db_engine'] == 'mysql') {
$db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'] . ';charset=utf8mb4';
@ -139,34 +110,15 @@ else if (isset($_POST['install'])) {
$sql_structure = file_get_contents('install/postgres.sql');
}
$content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
file_put_contents('inc/poche/config.inc.php', $content);
}
if ($continue) {
function executeQuery($handle, $sql, $params) {
try
{
$query = $handle->prepare($sql);
$query->execute($params);
return $query->fetchAll();
}
catch (Exception $e)
{
return FALSE;
}
}
if ($_POST['db_engine'] != "sqlite") {
// create database structure
$query = $handle->exec($sql_structure);
} catch (PDOException $e) {
$errors[] = $e->getMessage();
$continue = false;
}
// Create user
$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
}
if ($continue) {
$sql = "INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, '')";
$params = array($username, $salted_password, $username);
$query = executeQuery($handle, $sql, $params);
@ -184,11 +136,19 @@ else if (isset($_POST['install'])) {
foreach ($moreQueries as $query) {
executeQuery($handle, $query, array());
}
$successes[] = 'wallabag is now installed. You can now <a href="index.php?clean=0">access it !</a>';
if (!copy('inc/poche/config.inc.default.php', 'inc/poche/config.inc.php')) {
$errors[] = 'Installation aborted, impossible to create inc/poche/config.inc.php file. Maybe you don\'t have write access to create it.';
} else {
if ($_POST['db_engine'] != 'sqlite') {
$content = str_replace("define ('STORAGE', 'sqlite');", "define ('STORAGE', '".$_POST['db_engine']."');", $content);
file_put_contents('inc/poche/config.inc.php', $content);
}
$content = str_replace("define ('SALT', '');", "define ('SALT', '".$salt."');", $content);
file_put_contents('inc/poche/config.inc.php', $content);
}
}
}
}
?>
<!DOCTYPE html>
@ -368,21 +328,6 @@ cursor: pointer;
<p>To install wallabag, you just have to fill the following fields. That's all.</p>
<p>If you need help, you can read the doc: <a href="docs/" target="_blank">offline documentation</a> and <a href="http://doc.wallabag.org" target="_blank">online one</a> (already up-to-date).</p>
<?php if (!is_dir('vendor')) : ?>
<div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it:<br />
<ul>
<li>automatically download and extract vendor.zip into your wallabag folder.
<p><input type="submit" name="download" value="Download vendor.zip" /></p>
<?php if (!extension_loaded('zip')) : ?>
<b>Be careful, zip extension is not enabled in your PHP configuration. You'll have to unzip vendor.zip manually.</b>
<?php endif; ?>
<em>This method is mainly recommended if you don't have a dedicated server.</em></li>
<li>use <a href="http://getcomposer.org/">Composer</a> :<pre><code>curl -s http://getcomposer.org/installer | php
php composer.phar install</code></pre></li>
</ul>
</div>
<?php endif; ?>
<p class="detail">Server compatibility test (click to view details) : <?php if (isOkay()) { ?>
<span class="good">All good</span>
<?php } elseif (isPassing()) { ?>
@ -532,9 +477,22 @@ php composer.phar install</code></pre></li>
</div>
</div>
<form method="post" class="technical">
<hr>
<form method="post" class="technical">
<?php if (!is_dir('vendor')) : ?>
<div class='messages notice install'>wallabag needs twig, a template engine (<a href="http://twig.sensiolabs.org/">?</a>). Two ways to install it:<br />
<ul>
<li>automatically download and extract vendor.zip into your wallabag folder.
<p><input type="submit" name="download" value="Download vendor.zip" /></p>
<?php if (!extension_loaded('zip')) : ?>
<b>Be careful, zip extension is not enabled in your PHP configuration. You'll have to unzip vendor.zip manually.</b>
<?php endif; ?>
<em>This method is mainly recommended if you don't have a dedicated server.</em></li>
<li>use <a href="http://getcomposer.org/">Composer</a> :<pre><code>curl -s http://getcomposer.org/installer | php
php composer.phar install</code></pre></li>
</ul>
</div>
<?php endif; ?>
<fieldset>
<legend><strong>Technical settings</strong></legend>
<p>

View file

@ -52,4 +52,36 @@ function isPassing() {
return !in_array(false, $status);
}
/* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
* Idea : nbari at dalmp dot com
* Rights unknown
* Here in case of .gitignore files
*/
function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
function generate_salt() {
mt_srand(microtime(true)*100000 + memory_get_usage(true));
return md5(uniqid(mt_rand(), true));
}
function executeQuery($handle, $sql, $params) {
try
{
$query = $handle->prepare($sql);
$query->execute($params);
return $query->fetchAll();
}
catch (Exception $e)
{
return FALSE;
}
}
?>