]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
(definitely) fixed utf8mb4 and check if user already exists in database before instal...
authorThomas Citharel <tcit@tcit.fr>
Sat, 14 Feb 2015 14:12:02 +0000 (15:12 +0100)
committerThomas Citharel <tcit@tcit.fr>
Sat, 14 Feb 2015 14:12:02 +0000 (15:12 +0100)
inc/poche/Database.class.php
inc/poche/config.inc.default.php
install/index.php

index 6bac0f5d0e76d54b186d3b7fb33682ff150bd220..a987b7cc7be88e8551574357cc3ef998e94b818b 100755 (executable)
@@ -31,10 +31,15 @@ class Database {
                 $this->handle = new PDO($db_path);
                 break;
             case 'mysql':
-                $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4';
-                $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array(
-                    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
-                ));
+                if (MYSQL_USE_UTF8MB4) {
+                    $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4';
+                    $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array(
+                        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
+                    ));
+                } else {
+                    $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
+                    $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD);
+                }
                 break;
             case 'postgres':
                 $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
index 6750383e3998b47b3905d3d4a49c3cda67156171..16b96f7e343979b6de2d1e44b82b4afee0727281 100755 (executable)
@@ -20,6 +20,7 @@
 @define ('STORAGE_DB', 'poche');
 @define ('STORAGE_USER', 'poche');
 @define ('STORAGE_PASSWORD', 'poche');
+@define ('MYSQL_USE_UTF8MB4', FALSE); // This should be false unless you know what it is
 
 #################################################################################
 # Do not trespass unless you know what you are doing
index 46638f8f02331c4391412c084d67dce25cf28ce3..191c2574c5c039459833c4e0c6df118112d93b6a 100755 (executable)
@@ -83,6 +83,7 @@ else if (isset($_POST['install'])) {
                     $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password'], array(
                         PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
                     ));
+                    $content = str_replace("define ('MYSQL_USE_UTF8MB4', FALSE);", "define ('MYSQL_USE_UTF8MB4', TRUE);", $content);
                 } else { // regular UTF8
                     $db_path = 'mysql:host=' . $_POST['mysql_server'] . ';dbname=' . $_POST['mysql_database'];
                     $handle = new PDO($db_path, $_POST['mysql_user'], $_POST['mysql_password']);
@@ -126,6 +127,14 @@ else if (isset($_POST['install'])) {
         }
         }
     }
+
+    $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username));
+    if (!empty($usertest)) {
+        $continue = false;
+        $errors[] = "An user already exists with this username in database.";
+    }
+
+
     if ($continue) {
         $sql = "INSERT INTO users (username, password, name, email) VALUES (?, ?, ?, '')";
         $params = array($username, $salted_password, $username);