summaryrefslogtreecommitdiff
path: root/modules/image_block
diff options
context:
space:
mode:
authorNathan Kinkade <nkinkade@nkinka.de>2010-02-10 20:57:53 +0000
committerNathan Kinkade <nkinkade@nkinka.de>2010-02-10 20:57:53 +0000
commit10e36fcf1b5acf07c5cc128105af03fb09aac89e (patch)
treec5e815b0a4c540d0dc7bc5f90dd1eae3df31017e /modules/image_block
parent052476ef44ca801766cbd6bdbfe42d5a0a362e52 (diff)
parent8ef08d20883d9b9aa0b7560ce3bf6da8a6632149 (diff)
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/image_block')
-rw-r--r--modules/image_block/helpers/image_block_block.php8
1 files changed, 7 insertions, 1 deletions
diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php
index 185df850..82c92f19 100644
--- a/modules/image_block/helpers/image_block_block.php
+++ b/modules/image_block/helpers/image_block_block.php
@@ -26,7 +26,13 @@ class image_block_block_Core {
$block = "";
switch ($block_id) {
case "random_image":
- $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
+ // The random_query approach is flawed and doesn't always return a
+ // result when there actually is one. Retry a *few* times.
+ // @todo Consider another fallback if further optimizations are necessary.
+ $attempts = 0;
+ do {
+ $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
+ } while (!$item && $attempts++ < 3);
if ($item && $item->loaded()) {
$block = new Block();
$block->css_id = "g-image-block";