aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2015-02-16 00:43:18 +0100
committerThomas Citharel <tcit@tcit.fr>2015-02-16 00:43:18 +0100
commit6b60741600321e4a2c414e91595b09d35516a3ea (patch)
tree4c7dc3c93d4a3d1dfa861ce565602f41b7714b8d
parentd523c9939968d894d56b617be5210bd936e10c39 (diff)
downloadwallabag-6b60741600321e4a2c414e91595b09d35516a3ea.tar.gz
wallabag-6b60741600321e4a2c414e91595b09d35516a3ea.tar.zst
wallabag-6b60741600321e4a2c414e91595b09d35516a3ea.zip
alternative random function to fix #10821.9beta2
-rwxr-xr-xinc/poche/Database.class.php8
-rwxr-xr-xinc/poche/Poche.class.php11
2 files changed, 13 insertions, 6 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index a987b7cc..210ebb74 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -411,6 +411,14 @@ class Database {
411 411
412 return $count; 412 return $count;
413 } 413 }
414 public function getRandomId($row, $user_id) {
415 $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? ";
416 $params = array($user_id, $row);
417 $query = $this->executeQuery($sql, $params);
418
419 return $query->fetchAll();
420 }
421
414 422
415 public function updateContent($id, $content, $user_id) 423 public function updateContent($id, $content, $user_id)
416 { 424 {
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 6d4ce137..4b85d52f 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -393,13 +393,12 @@ class Poche
393 393
394 /* 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 */ 394 /* 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 */
395 case 'random': 395 case 'random':
396 $id = 0; 396 $count = $this->store->getEntriesByViewCount($view, $this->user->getId());
397 while ($this->store->retrieveOneById($id,$this->user->getId()) == null) { 397 $id_query = $this->store->getRandomId(rand(1,$count)-1, $this->user->getId());
398 $count = $this->store->getEntriesByViewCount($view, $this->user->getId()); 398 $id = $id_query[0];
399 $id = rand(1,$count);
400 }
401 Tools::logm('get a random article'); 399 Tools::logm('get a random article');
402 Tools::redirect('?view=view&id=' . $id); 400 Tools::redirect('?view=view&id=' . $id[0]);
401
403 //$this->displayView('view', $id); 402 //$this->displayView('view', $id);
404 break; 403 break;
405 default: 404 default: