Changeset:
        b212448e0d86
        
https://sourceforge.net/p/mrbs/hg-code/ci/b212448e0d867816a574f1becac0d321458dbc4a
Author:
        Campbell Morrison <[email protected]>
Date:
        Wed Sep 28 20:45:18 2016 +0100
Log message:

Got rid of error checking following sql_query() calls now that there's a 
default uncaught exception handler.

diffstat:

 web/admin.php           |   13 +----
 web/auth/auth_db.inc    |    7 +--
 web/dbsys.inc           |    4 +
 web/del.php             |    8 +--
 web/edit_entry.php      |  102 +++++++++++++++++++++--------------------------
 web/functions.inc       |    4 +-
 web/functions_error.inc |    4 +-
 web/functions_ical.inc  |   16 +-----
 web/lib/MRBS/DB.php     |   17 +++++++-
 web/mrbs_sql.inc        |   80 ++++++-------------------------------
 web/pending.php         |    6 +--
 web/report.php          |    5 --
 web/search.php          |    5 --
 web/upgrade/17/post.inc |    5 --
 web/upgrade/32/post.inc |    6 --
 web/upgrade/34/post.inc |    6 --
 web/upgrade/6/post.inc  |    9 +---
 web/view_entry.php      |    5 --
 18 files changed, 94 insertions(+), 208 deletions(-)

diffs (truncated from 658 to 300 lines):

diff -r 1e6287dc667c -r b212448e0d86 web/admin.php
--- a/web/admin.php     Wed Sep 28 18:07:00 2016 +0100
+++ b/web/admin.php     Wed Sep 28 20:45:18 2016 +0100
@@ -44,17 +44,14 @@
 if (isset($area))
 {
   $res = sql_query("SELECT area_name, custom_html FROM $tbl_area WHERE id=? 
LIMIT 1", array($area));
-  if (! $res)
-  {
-    trigger_error(sql_error(), E_USER_WARNING);
-    fatal_error(FALSE, get_vocab("fatal_db_error"));
-  }
+
   if (sql_count($res) == 1)
   {
     $row = sql_row_keyed($res, 0);
     $area_name = $row['area_name'];
     $custom_html = $row['custom_html'];
   }
+  
   sql_free($res);
 }
 
@@ -212,11 +209,7 @@
   if (isset($area))
   {
     $res = sql_query("SELECT * FROM $tbl_room WHERE area_id=? ORDER BY 
sort_key", array($area));
-    if (! $res)
-    {
-      trigger_error(sql_error(), E_USER_WARNING);
-      fatal_error(FALSE, get_vocab("fatal_db_error"));
-    }
+
     if (sql_count($res) == 0)
     {
       echo "<p>" . get_vocab("norooms") . "</p>\n";
diff -r 1e6287dc667c -r b212448e0d86 web/auth/auth_db.inc
--- a/web/auth/auth_db.inc      Wed Sep 28 18:07:00 2016 +0100
+++ b/web/auth/auth_db.inc      Wed Sep 28 20:45:18 2016 +0100
@@ -53,12 +53,7 @@
            LIMIT 1";
 
   $res = sql_query($sql, $sql_params);
-  if ($res == FALSE)
-  {
-    trigger_error(sql_error(), E_USER_WARNING);
-    return 0;
-  }
-
+  
   $row = sql_row_keyed($res, 0);
 
   $do_rehash = false;
diff -r 1e6287dc667c -r b212448e0d86 web/dbsys.inc
--- a/web/dbsys.inc     Wed Sep 28 18:07:00 2016 +0100
+++ b/web/dbsys.inc     Wed Sep 28 20:45:18 2016 +0100
@@ -138,6 +138,10 @@
 {
   return DB::default_db()->table_exists($table);
 }
+function sql_field_exists($table, $field)
+{
+  return DB::default_db()->field_exists($table, $field);
+}
 function sql_field_info($table)
 {
   return DB::default_db()->field_info($table);
diff -r 1e6287dc667c -r b212448e0d86 web/del.php
--- a/web/del.php       Wed Sep 28 18:07:00 2016 +0100
+++ b/web/del.php       Wed Sep 28 20:45:18 2016 +0100
@@ -56,12 +56,8 @@
    
     $sql = "SELECT name, start_time, end_time FROM $tbl_entry WHERE room_id=?";
     $res = sql_query($sql, array($room));
-    if (! $res)
-    {
-      trigger_error(sql_error(), E_USER_WARNING);
-      fatal_error(FALSE, get_vocab("fatal_db_error"));
-    }
-    else if (sql_count($res) > 0)
+    
+    if (sql_count($res) > 0)
     {
       echo "<p>\n";
       echo get_vocab("deletefollowing") . ":\n";
diff -r 1e6287dc667c -r b212448e0d86 web/edit_entry.php
--- a/web/edit_entry.php        Wed Sep 28 18:07:00 2016 +0100
+++ b/web/edit_entry.php        Wed Sep 28 20:45:18 2016 +0100
@@ -399,11 +399,7 @@
              AND A.disabled=0
         ORDER BY R.area_id, R.sort_key";
   $res = sql_query($sql);
-  if ($res === FALSE)
-  {
-    trigger_error(sql_error(), E_USER_WARNING);
-    fatal_error(FALSE, get_vocab("fatal_db_error"));
-  }
+  
   for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   {
     $all_rooms[$row['area_id']][$row['id']] = $row['room_name'];
@@ -818,13 +814,9 @@
               FROM $tbl_repeat 
              WHERE id=?
              LIMIT 1";
-   
+             
     $res = sql_query($sql, array($rep_id));
-    if (! $res)
-    {
-      trigger_error(sql_error(), E_USER_WARNING);
-      fatal_error(TRUE, get_vocab("fatal_db_error"));
-    }
+    
     if (sql_count($res) != 1)
     {
       fatal_error(1,
@@ -1041,12 +1033,10 @@
            AND A.disabled=0
       ORDER BY R.area_id, R.sort_key";
 $res = sql_query($sql);
-if ($res)
+
+for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
 {
-  for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
-  {
-    $rooms[$row['id']] = $row;
-  }
+  $rooms[$row['id']] = $row;
 }
     
 // Get the details of all the enabled areas
@@ -1059,52 +1049,50 @@
          WHERE disabled=0
       ORDER BY sort_key";
 $res = sql_query($sql);
-if ($res)
+
+for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
 {
-  for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
+  // Make sure we've got the correct resolution when using periods (it's
+  // probably OK anyway, but just in case)
+  if ($row['enable_periods'])
   {
-    // Make sure we've got the correct resolution when using periods (it's
-    // probably OK anyway, but just in case)
-    if ($row['enable_periods'])
+    $row['resolution'] = 60;
+  }
+  // Generate some derived settings
+  $row['max_duration_qty']     = $row['max_duration_secs'];
+  toTimeString($row['max_duration_qty'], $row['max_duration_units']);
+  // Get the start and end of the booking day
+  if ($row['enable_periods'])
+  {
+    $first = 12*SECONDS_PER_HOUR;
+    // If we're using periods we just go to the end of the last slot
+    $last = $first + (count($periods) * $row['resolution']);
+  }
+  else
+  {
+    $first = (($row['morningstarts'] * 60) + $row['morningstarts_minutes']) * 
60;
+    $last = ((($row['eveningends'] * 60) + $row['eveningends_minutes']) * 60) 
+ $row['resolution'];
+    // If the end of the day is the same as or before the start time, then 
it's really on the next day
+    if ($first >= $last)
     {
-      $row['resolution'] = 60;
+      $last += SECONDS_PER_DAY;
     }
-    // Generate some derived settings
-    $row['max_duration_qty']     = $row['max_duration_secs'];
-    toTimeString($row['max_duration_qty'], $row['max_duration_units']);
-    // Get the start and end of the booking day
-    if ($row['enable_periods'])
-    {
-      $first = 12*SECONDS_PER_HOUR;
-      // If we're using periods we just go to the end of the last slot
-      $last = $first + (count($periods) * $row['resolution']);
-    }
-    else
-    {
-      $first = (($row['morningstarts'] * 60) + $row['morningstarts_minutes']) 
* 60;
-      $last = ((($row['eveningends'] * 60) + $row['eveningends_minutes']) * 
60) + $row['resolution'];
-      // If the end of the day is the same as or before the start time, then 
it's really on the next day
-      if ($first >= $last)
-      {
-        $last += SECONDS_PER_DAY;
-      }
-    }
-    $row['first'] = $first;
-    $row['last'] = $last;
-    // We don't show the all day checkbox if it's going to result in bookings 
that
-    // contravene the policy - ie if max_duration is enabled and an all day 
booking
-    // would be longer than the maximum duration allowed.
-    $row['show_all_day'] = $is_admin || 
-                           !$row['max_duration_enabled'] ||
-                           ( ($row['enable_periods'] && 
($row['max_duration_periods'] >= count($periods))) ||
-                             (!$row['enable_periods'] && 
($row['max_duration_secs'] >= ($last - $first))) );
-    
-    // Clean up the settings, getting rid of any nulls and casting boolean 
fields into bools
-    $row = clean_area_row($row);
-    
-    // Now assign the row to the area      
-    $areas[$row['id']] = $row;
   }
+  $row['first'] = $first;
+  $row['last'] = $last;
+  // We don't show the all day checkbox if it's going to result in bookings 
that
+  // contravene the policy - ie if max_duration is enabled and an all day 
booking
+  // would be longer than the maximum duration allowed.
+  $row['show_all_day'] = $is_admin || 
+                         !$row['max_duration_enabled'] ||
+                         ( ($row['enable_periods'] && 
($row['max_duration_periods'] >= count($periods))) ||
+                           (!$row['enable_periods'] && 
($row['max_duration_secs'] >= ($last - $first))) );
+  
+  // Clean up the settings, getting rid of any nulls and casting boolean 
fields into bools
+  $row = clean_area_row($row);
+  
+  // Now assign the row to the area      
+  $areas[$row['id']] = $row;
 }
 
 
diff -r 1e6287dc667c -r b212448e0d86 web/functions.inc
--- a/web/functions.inc Wed Sep 28 18:07:00 2016 +0100
+++ b/web/functions.inc Wed Sep 28 20:45:18 2016 +0100
@@ -1772,7 +1772,7 @@
            LIMIT 1";
            
   $res = sql_query($sql, array($area));
-  if (!$res || (sql_count($res) == 0))
+  if (sql_count($res) == 0)
   {
     // We still need to set the timezone even if the query didn't
     // return any results
@@ -2199,7 +2199,7 @@
   $res = sql_query($sql, array($area));
   // Only show the rooms if there's more than one of them, otherwise
   // there's no point
-  if ($res && (sql_count($res) > 1))
+  if (sql_count($res) > 1)
   {
     $out_html .= "<div id=\"dwm_rooms\">\n";
     $out_html .= "<h3>" . get_vocab("rooms") . "</h3>";
diff -r 1e6287dc667c -r b212448e0d86 web/functions_error.inc
--- a/web/functions_error.inc   Wed Sep 28 18:07:00 2016 +0100
+++ b/web/functions_error.inc   Wed Sep 28 20:45:18 2016 +0100
@@ -20,7 +20,7 @@
 {
   $display_errors = ini_get('display_errors');
   
-  $title = get_error_name($errno) . " in $errfile at line $errline\n";
+  $title = "\n" . get_error_name($errno) . " in $errfile at line $errline\n";
   
   if ($display_errors)
   {
@@ -40,7 +40,7 @@
   
   $message = "Uncaught exception ($class) in " . $exception->getFile() . " at 
line " . $exception->getLine() . "\n" .
              $exception->getMessage() . "\n" .
-             $exception->getTraceAsString();
+             $exception->getTraceAsString() . "\n";
              
   trigger_error($message, E_USER_WARNING);
   
diff -r 1e6287dc667c -r b212448e0d86 web/functions_ical.inc
--- a/web/functions_ical.inc    Wed Sep 28 18:07:00 2016 +0100
+++ b/web/functions_ical.inc    Wed Sep 28 20:45:18 2016 +0100
@@ -116,12 +116,8 @@
              AND outlook_compatible=?
            LIMIT 1";
   $res = sql_query($sql, array($tz,$zoneinfo_outlook_compatible));
-  if ($res === FALSE)
-  {
-    trigger_error(sql_error(), E_USER_WARNING);
-    fatal_error(FALSE, get_vocab("fatal_db_error"));
-  }
-  elseif (sql_count($res) > 0)
+
+  if (sql_count($res) > 0)
   {
     // If there's something in the database and it hasn't expired, then
     // that's it.
@@ -313,12 +309,8 @@
   {
     $sql = "SELECT name FROM $tbl_users WHERE email=?";
     $res = sql_query($sql, array($email));
-    if ($res === FALSE)
-    {
-      trigger_error(sql_error(), E_USER_WARNING);
-      fatal_error(FALSE, get_vocab("fatal_db_error"));
-    }
-    elseif (sql_count($res) == 0)
+
+    if (sql_count($res) == 0)
     {
       return NULL;
     }

------------------------------------------------------------------------------
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to