Changeset:
        d5993c2aa1c4
        
https://sourceforge.net/p/mrbs/hg-code/ci/d5993c2aa1c4439dd3ee8fa0706bc9d0094c7ff6
Author:
        Campbell Morrison <[email protected]>
Date:
        Thu Oct 06 17:26:00 2016 +0100
Log message:

Made get_default_room() independent of database schema

diffstat:

 web/functions.inc |  53 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 40 insertions(+), 13 deletions(-)

diffs (68 lines):

diff -r c2cdf4dbf622 -r d5993c2aa1c4 web/functions.inc
--- a/web/functions.inc Thu Oct 06 17:07:28 2016 +0100
+++ b/web/functions.inc Thu Oct 06 17:26:00 2016 +0100
@@ -1660,24 +1660,51 @@
   // Check to see whether this area contains $default_room
   if (isset($default_room))
   {
-    $room = db()->query1("SELECT id
-                          FROM $tbl_room
-                         WHERE id=$default_room
-                           AND area_id=?
-                           AND disabled=0
-                         LIMIT 1", array($area));
+    try
+    {
+      // It's possible that this function is being called during
+      // an upgrade process before the disabled columns existed,
+      // so if it fails try again without the disabled columns.
+      $room = db()->query1("SELECT id
+                              FROM $tbl_room
+                             WHERE id=$default_room
+                               AND area_id=?
+                               AND disabled=0
+                             LIMIT 1", array($area));
+    }
+    catch (DBException $e)
+    {
+      $room = db()->query1("SELECT id
+                              FROM $tbl_room
+                             WHERE id=$default_room
+                               AND area_id=?
+                             LIMIT 1", array($area));
+    }
     if ($room >= 0)
     {
       return $room;
     }
   }
-  // Otherwise just return the first room (in sortkey order) in the area
-  $room = db()->query1("SELECT id
-                        FROM $tbl_room
-                       WHERE area_id=?
-                         AND disabled=0
-                    ORDER BY sort_key
-                       LIMIT 1", array($area));
+  
+  // Otherwise just return the first room in the area
+  try
+  {
+    $room = db()->query1("SELECT id
+                            FROM $tbl_room
+                           WHERE area_id=?
+                             AND disabled=0
+                        ORDER BY sort_key
+                           LIMIT 1", array($area));
+  }
+  catch (DBException $e)
+  {
+    // See comment above.  Cut the query down to the most basic.
+    $room = db()->query1("SELECT id
+                            FROM $tbl_room
+                           WHERE area_id=?
+                           LIMIT 1", array($area));
+  }
+  
   return ($room < 0 ? 0 : $room);
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to