]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
alternative random function to fix #1082 1.9beta2
authorThomas Citharel <tcit@tcit.fr>
Sun, 15 Feb 2015 23:43:18 +0000 (00:43 +0100)
committerThomas Citharel <tcit@tcit.fr>
Sun, 15 Feb 2015 23:43:18 +0000 (00:43 +0100)
inc/poche/Database.class.php
inc/poche/Poche.class.php

index a987b7cc7be88e8551574357cc3ef998e94b818b..210ebb74cc279b0f55d61cced87dd46108f36206 100755 (executable)
@@ -411,6 +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);
+
+       return $query->fetchAll();
+    }
+
 
     public function updateContent($id, $content, $user_id)
     {
index 6d4ce1377daea3d5e9760325d498ad7c66775832..4b85d52fb3d23c2868ce57f57bd8c0308400bcdf 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':
-                $id = 0;
-                while ($this->store->retrieveOneById($id,$this->user->getId()) == null) {
-                    $count = $this->store->getEntriesByViewCount($view, $this->user->getId());
-                    $id = rand(1,$count);
-                }
+                $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);
+                Tools::redirect('?view=view&id=' . $id[0]);
+                
                 //$this->displayView('view', $id);
                 break;
             default: