Revision: 2955
          https://sourceforge.net/p/mrbs/code/2955/
Author:   cimorrison
Date:     2015-01-18 12:12:04 +0000 (Sun, 18 Jan 2015)
Log Message:
-----------
Reintegrated repeat_id_fk branch into the trunk.   The trunk now has 
entry.repeat_id as a foreign key.

Modified Paths:
--------------
    mrbs/trunk/tables.my.sql
    mrbs/trunk/tables.pg.sql
    mrbs/trunk/web/dbsys.inc
    mrbs/trunk/web/functions_table.inc
    mrbs/trunk/web/month.php
    mrbs/trunk/web/mrbs_sql.inc
    mrbs/trunk/web/pending.php

Added Paths:
-----------
    mrbs/trunk/web/upgrade/41/
    mrbs/trunk/web/upgrade/42/

Property Changed:
----------------
    mrbs/trunk/

Index: mrbs/trunk
===================================================================
--- mrbs/trunk  2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk  2015-01-18 12:12:04 UTC (rev 2955)

Property changes on: mrbs/trunk
___________________________________________________________________
Modified: svn:mergeinfo
## -13,3 +13,4 ##
 /mrbs/branches/only_unicode:1747-1749
 /mrbs/branches/provisional_bookings:1242-1280
 /mrbs/branches/provisional_bookings_new_style:1407-1570
+/mrbs/branches/repeat_id_fk:2949-2954
\ No newline at end of property
Modified: mrbs/trunk/tables.my.sql
===================================================================
--- mrbs/trunk/tables.my.sql    2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/tables.my.sql    2015-01-18 12:12:04 UTC (rev 2955)
@@ -122,7 +122,7 @@
   start_time     int DEFAULT '0' NOT NULL,
   end_time       int DEFAULT '0' NOT NULL,
   entry_type     int DEFAULT '0' NOT NULL,
-  repeat_id      int DEFAULT '0' NOT NULL,
+  repeat_id      int DEFAULT NULL,
   room_id        int DEFAULT '1' NOT NULL,
   timestamp      timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE 
CURRENT_TIMESTAMP,
   create_by      varchar(80) CHARACTER SET utf8 COLLATE utf8_general_ci 
DEFAULT '' NOT NULL,
@@ -137,13 +137,17 @@
   info_text      text CHARACTER SET utf8 COLLATE utf8_general_ci,
   ical_uid       varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci 
DEFAULT '' NOT NULL,
   ical_sequence  smallint DEFAULT 0 NOT NULL,
-  ical_recur_id  varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci 
DEFAULT '' NOT NULL,
+  ical_recur_id  varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci 
DEFAULT NULL,
 
   PRIMARY KEY (id),
   FOREIGN KEY (room_id) 
     REFERENCES mrbs_room(id)
     ON UPDATE CASCADE
     ON DELETE RESTRICT,
+  FOREIGN KEY (repeat_id) 
+    REFERENCES mrbs_repeat(id)
+    ON UPDATE CASCADE
+    ON DELETE CASCADE,
   KEY idxStartTime (start_time),
   KEY idxEndTime   (end_time)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Modified: mrbs/trunk/tables.pg.sql
===================================================================
--- mrbs/trunk/tables.pg.sql    2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/tables.pg.sql    2015-01-18 12:12:04 UTC (rev 2955)
@@ -130,7 +130,7 @@
   start_time     int DEFAULT 0 NOT NULL,
   end_time       int DEFAULT 0 NOT NULL,
   entry_type     int DEFAULT 0 NOT NULL,
-  repeat_id      int DEFAULT 0 NOT NULL,
+  repeat_id      int DEFAULT NULL,
   room_id        int DEFAULT 1 NOT NULL
                    REFERENCES mrbs_room(id)
                    ON UPDATE CASCADE

Modified: mrbs/trunk/web/dbsys.inc
===================================================================
--- mrbs/trunk/web/dbsys.inc    2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/web/dbsys.inc    2015-01-18 12:12:04 UTC (rev 2955)
@@ -24,7 +24,7 @@
 }
 
 
-$db_schema_version = 40;
+$db_schema_version = 42;
 $local_db_schema_version = 1;
 
 // Include the abstraction configured to be used for the default MRBS

Modified: mrbs/trunk/web/functions_table.inc
===================================================================
--- mrbs/trunk/web/functions_table.inc  2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/web/functions_table.inc  2015-01-18 12:12:04 UTC (rev 2955)
@@ -116,7 +116,7 @@
     
     // fill in the id, type and start time
     $column[$s][$n]["id"] = $row['entry_id'];
-    $column[$s][$n]["is_repeat"] = !empty($row['repeat_id']);
+    $column[$s][$n]["is_repeat"] = isset($row['repeat_id']);
     $column[$s][$n]["is_multiday_start"] = $is_multiday_start;
     $column[$s][$n]["is_multiday_end"] = $is_multiday_end;
     $column[$s][$n]["status"] = $row['status'];

Modified: mrbs/trunk/web/month.php
===================================================================
--- mrbs/trunk/web/month.php    2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/web/month.php    2015-01-18 12:12:04 UTC (rev 2955)
@@ -278,7 +278,7 @@
       }
       $d[$day_num]["id"][] = $row['id'];
       $d[$day_num]["color"][] = $row['type'];
-      $d[$day_num]["is_repeat"][] = !empty($row['repeat_id']);
+      $d[$day_num]["is_repeat"][] = isset($row['repeat_id']);
       
       // Handle private events
       if (is_private_event($row['status'] & STATUS_PRIVATE)) 

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/web/mrbs_sql.inc 2015-01-18 12:12:04 UTC (rev 2955)
@@ -495,7 +495,7 @@
   }
 
   // Get rid of any orphaned rows in the repeat table
-  if ($repeat_id > 0 &&
+  if (!empty($repeat_id) &&
       sql_query1("SELECT COUNT(*) FROM $tbl_entry WHERE repeat_id=$repeat_id") 
== 0)
   {
     sql_command("DELETE FROM $tbl_repeat WHERE id=$repeat_id");
@@ -526,10 +526,13 @@
   $table_no_prefix = utf8_substr($table, utf8_strlen($db_tbl_prefix));  // 
strip the prefix off the table name
     
   $fields = sql_field_info($table);
-
+  
   foreach ($fields as $field)
   {
     $key = $field['name'];
+    // If the key doesn't exist in the $data array then the database will just 
use its
+    // default value for the column.    If it does exist and is set to NULL 
then we'll
+    // write NULL to the database (which may not necessarily be the default 
value).
     if (array_key_exists($key, $data))
     {
       switch ($key)
@@ -546,7 +549,7 @@
         case 'status':
         case 'ical_sequence':
           $sql_col[] = $key;
-          $sql_val[] = $data[$key];
+          $sql_val[] = (isset($data[$key])) ? (int)$data[$key] : 'NULL';
           break;
         
         // strings  
@@ -559,7 +562,7 @@
         case 'ical_uid':
         case 'ical_recur_id':
           $sql_col[] = $key;
-          $sql_val[] = "'" . sql_escape($data[$key]) . "'";
+          $sql_val[] = (isset($data[$key])) ? "'" . sql_escape($data[$key]) . 
"'" : 'NULL';
           break;
       
         // special case - rep_opt
@@ -597,13 +600,13 @@
                 }
                 else
                 {
-                  $value = $data[$key];
+                  $value = (int)$data[$key];
                 }
                 break;
               default:
                 if (!isset($data[$key]))
                 {
-                  $value = '';
+                  $value = ($field['is_nullable']) ? 'NULL' : '';
                 }
                 else
                 {
@@ -623,7 +626,7 @@
   
   $sql_col = array_map('sql_quote', $sql_col);
   $sql = "INSERT INTO $table (" . implode(', ', $sql_col) . ") VALUES (" . 
implode(', ',$sql_val) . ")";
-
+  
   if (sql_command($sql) < 0)
   {
     // probably because the table hasn't been created properly
@@ -641,7 +644,7 @@
  * $data      - An array containing the entry details
  * 
  * Returns:
- *   0        - An error occured while inserting the entry
+ *   0        - An error occurred while inserting the entry
  *   non-zero - The entry's ID
  */
 function mrbsCreateSingleEntry($data)
@@ -676,7 +679,7 @@
  * $data      - An array containing the entry details
  *
  * Returns:
- *   0        - An error occured while inserting the entry
+ *   0        - An error occurred while inserting the entry
  *   non-zero - The entry's ID
  */
 function mrbsCreateRepeatEntry($data)
@@ -905,7 +908,7 @@
   if (empty($reps))
   {
     $data['entry_type'] = ENTRY_SINGLE;
-    $data['repeat_id'] = 0;
+    $data['repeat_id'] = NULL;
     $id = mrbsCreateSingleEntry($data);
     $result['id'] = $id;
     $result['series'] = FALSE;
@@ -967,6 +970,36 @@
   return $result;
 }
 
+
+// Gets the repeat_id for an entry in the entry table with id $entry_id
+// Returns the repeat_id or NULL
+function get_repeat_id($entry_id)
+{
+  global $tbl_entry;
+  
+  $sql = "SELECT repeat_id
+            FROM $tbl_entry
+           WHERE id=$entry_id
+           LIMIT 1";
+           
+  $res = sql_query($sql);
+  
+  if ($res === FALSE)
+  {
+    trigger_error(sql_error(), E_USER_WARNING);
+    fatal_error(FALSE, get_vocab("fatal_db_error"));
+  }
+  if (sql_count($res) == 0)
+  {
+    // This should not happen
+    trigger_error('$entry_id=' . "$entry_id does not exist.", E_USER_NOTICE);
+    return NULL;
+  }
+  $row = sql_row_keyed($res, 0);
+  return $row['repeat_id'];
+}
+
+
 // Update the time of last reminding.
 // If the entry is part of a repeating series, then also increment
 // the last reminder time in the repeat table and all the individual 
@@ -1004,8 +1037,8 @@
              WHERE id=$id";
     if (sql_command($sql) > 0)
     {
-      $repeat_id = sql_query1("SELECT repeat_id FROM $tbl_entry WHERE id=$id 
LIMIT 1");
-      if ($repeat_id >= 0)
+      $repeat_id = get_repeat_id($entry_id);
+      if (isset($repeat_id))
       {
         $sql = "UPDATE $tbl_repeat
                    SET reminded=$now,
@@ -1188,7 +1221,7 @@
         if (!$series && !array_key_exists($field['name'], $rep_fields))
         {
           // If this is the entry table then check that the custom field also
-          // exists in the rpeat table
+          // exists in the repeat table
           fatal_error(0, "Custom fields problem, '".$field['name']."' exists 
in entry table but not in repeat table");
         }
         
@@ -1251,7 +1284,7 @@
   else
   {
     // Get the repeat information
-    if (empty($row['repeat_id']))
+    if (!isset($row['repeat_id']))
     {
       $row['rep_type'] = REP_NONE;   // just as a precaution
       $row['repeat_info_time'] = '';
@@ -1597,19 +1630,15 @@
   }
 
   // When checking for overlaps, for Edit (not New), ignore this entry and 
series:
-  $repeat_id = 0;
   if (isset($id))
   {
     $ignore_id = $id;
-    $repeat_id = sql_query1("SELECT repeat_id FROM $tbl_entry WHERE id=$id 
LIMIT 1");
-    if ($repeat_id < 0)
-    {
-      $repeat_id = 0;
-    }
+    $repeat_id = get_repeat_id($id);
   }
   else
   {
     $ignore_id = 0;
+    $repeat_id = NULL;
   }
 
   // Acquire mutex to lock out others trying to book the same slot(s).
@@ -1801,7 +1830,7 @@
 
     if ($booking['rep_type'] == REP_NONE)
     {
-      $booking['entry_type'] = ($repeat_id > 0) ? ENTRY_RPT_CHANGED : 
ENTRY_SINGLE;
+      $booking['entry_type'] = (isset($repeat_id)) ? ENTRY_RPT_CHANGED : 
ENTRY_SINGLE;
       $booking['repeat_id'] = $repeat_id;
     }
     // Add in the list of bookings to skip

Modified: mrbs/trunk/web/pending.php
===================================================================
--- mrbs/trunk/web/pending.php  2015-01-18 12:05:57 UTC (rev 2954)
+++ mrbs/trunk/web/pending.php  2015-01-18 12:12:04 UTC (rev 2955)
@@ -248,7 +248,7 @@
   display_table_head();
   
   echo "<tbody>\n";
-  $last_repeat_id = 0;
+  $last_repeat_id = NULL;
   $is_series = FALSE;
   for ($i = 0; ($row = sql_row_keyed($res, $i)); $i++)
   { 
------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to