Changeset:
        92ba2d81490d
        
https://sourceforge.net/p/mrbs/hg-code/ci/92ba2d81490d1829afbcca761a96e215086fc1bf
Author:
        Campbell Morrison <[email protected]>
Date:
        Thu Oct 06 16:59:54 2016 +0100
Log message:

Made get_area_settings work with all database schema versions

diffstat:

 web/Themes/default/header.inc |   7 +--
 web/functions.inc             |  72 ++++++++++++++++++++++++++++++++----------
 2 files changed, 56 insertions(+), 23 deletions(-)

diffs (127 lines):

diff -r a23cf160f16d -r 92ba2d81490d web/Themes/default/header.inc
--- a/web/Themes/default/header.inc     Thu Oct 06 16:19:20 2016 +0100
+++ b/web/Themes/default/header.inc     Thu Oct 06 16:59:54 2016 +0100
@@ -212,11 +212,8 @@
 {
   global $search_str, $locale_warning;
 
-  if (!$simple)
-  {
-    // This makes a database query, so don't do it if we want a simple header
-    get_area_settings($area);
-  }
+  // Need to set the timezone before we can use date()
+  get_area_settings($area);
 
   // If we dont know the right date then make it up 
   if (!$day)
diff -r a23cf160f16d -r 92ba2d81490d web/functions.inc
--- a/web/functions.inc Thu Oct 06 16:19:20 2016 +0100
+++ b/web/functions.inc Thu Oct 06 16:59:54 2016 +0100
@@ -1603,24 +1603,50 @@
   // corresponding area
   if (isset($default_room))
   {
-    $area = db()->query1("SELECT area_id
-                          FROM $tbl_room R, $tbl_area A
-                         WHERE R.id=?
-                           AND R.area_id = A.id
-                           AND R.disabled = 0
-                           AND A.disabled = 0
-                         LIMIT 1", array($default_room));
+    try 
+    {
+      $area = db()->query1("SELECT area_id
+                              FROM $tbl_room R, $tbl_area A
+                             WHERE R.id=?
+                               AND R.area_id = A.id
+                               AND R.disabled = 0
+                               AND A.disabled = 0
+                             LIMIT 1", array($default_room));
+    }
+    catch (DBException $e)
+    {
+      // 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.
+      $area = db()->query1("SELECT area_id
+                              FROM $tbl_room R, $tbl_area A
+                             WHERE R.id=?
+                               AND R.area_id = A.id
+                             LIMIT 1", array($default_room));
+    }
     if ($area >= 0)
     {
       return $area;
     }
   }
-  // Otherwise return the first enabled area in sort key order in the database
-  $area = db()->query1("SELECT id
-                        FROM $tbl_area
-                       WHERE disabled=0
-                    ORDER BY sort_key
-                       LIMIT 1");
+  
+  // Otherwise return the first enabled area in the database
+  try
+  {
+    $area = db()->query1("SELECT id
+                            FROM $tbl_area
+                           WHERE disabled=0
+                        ORDER BY sort_key
+                           LIMIT 1");
+  }
+  catch (DBException $e)
+  {
+    // See comment above.  Cut the query down to the most basic.
+    $area = db()->query1("SELECT id
+                            FROM $tbl_area
+                           LIMIT 1");
+  }
+  
   return ((!isset($area) || ($area < 0)) ? 0 : $area);
 }
 
@@ -1748,7 +1774,7 @@
                    'approval_enabled', 'reminders_enabled, enable_periods',
                    'confirmation_enabled', 'confirmed_default');
                    
-  $sql = "SELECT " . implode(',', $columns) . "
+  $sql = "SELECT *
             FROM $tbl_area 
            WHERE id=?
            LIMIT 1";
@@ -1764,9 +1790,12 @@
   else
   {
     $row = clean_area_row($res->row_keyed(0));
-    foreach ($row as $key => $value)
+    foreach ($columns as $column)
     {
-      $$key = $value;
+      if (array_key_exists($column, $row))
+      {
+        $$column = $row[$column];
+      }
     }
   }
   // Set the timezone
@@ -1777,9 +1806,16 @@
   foreach ($interval_types as $interval_type)
   {
     $var = "max_per_${interval_type}_enabled";
-    $max_per_interval_area_enabled[$interval_type] = $$var;
+    if (isset($$var))
+    {
+      $max_per_interval_area_enabled[$interval_type] = $$var;
+    }
+    
     $var = "max_per_${interval_type}";
-    $max_per_interval_area[$interval_type] = $$var;
+    if (isset($$var))
+    {
+      $max_per_interval_area[$interval_type] = $$var;
+    }
   }
   
   // If we're using periods then set the resolution to 60 seconds

------------------------------------------------------------------------------
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