]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
much better fix for #1082 1.9RC1
authorThomas Citharel <tcit@tcit.fr>
Mon, 16 Feb 2015 14:18:24 +0000 (15:18 +0100)
committerThomas Citharel <tcit@tcit.fr>
Mon, 16 Feb 2015 14:18:24 +0000 (15:18 +0100)
inc/poche/Database.class.php
inc/poche/Poche.class.php

index 210ebb74cc279b0f55d61cced87dd46108f36206..65675afe1a53b6c4ed9510f9850197b99cbfa27a 100755 (executable)
@@ -411,12 +411,14 @@ class Database {
 
         return $count;
     }
-    public function getRandomId($row, $user_id) {
-       $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? ";
-       $params = array($user_id, $row);
-       $query = $this->executeQuery($sql, $params);
+    public function getRandomId($user_id) {
+        $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()';
+        $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1";
+        $params = array($user_id);
+        $query = $this->executeQuery($sql, $params);
+        $id = $query->fetchAll();
 
-       return $query->fetchAll();
+        return $id;
     }
 
 
index 4b85d52fb3d23c2868ce57f57bd8c0308400bcdf..481382ec98665a4e8d810c6b9f44c71bca447260 100755 (executable)
@@ -393,13 +393,12 @@ class Poche
                 
             /* For some unknown reason I can't get displayView() to work here (it redirects to home view afterwards). So here's a dirty fix which redirects directly to URL */
             case 'random':
-                $count = $this->store->getEntriesByViewCount($view, $this->user->getId());
-                $id_query = $this->store->getRandomId(rand(1,$count)-1, $this->user->getId());
-                $id = $id_query[0];
                 Tools::logm('get a random article');
-                Tools::redirect('?view=view&id=' . $id[0]);
-                
-                //$this->displayView('view', $id);
+                if ($this->store->getRandomId($this->user->getId())) {
+                    $id = $this->store->getRandomId($this->user->getId())[0];
+                    Tools::redirect('?view=view&id=' . $id[0]);
+                    Tools::logm('got the article with id ' . $id[0]);
+                }
                 break;
             default:
                 break;