From bad6f214d94b2697e8d5e4e1af6ab2db439b45af Mon Sep 17 00:00:00 2001
From: Adam Lyall <magicmyth@magicmyth.com>
Date: Mon, 19 Nov 2012 14:32:51 +0000
Subject: [PATCH] Update database queries to Drupal 7 API

Some update paths (such as future instance updates) would fail from bad
database API calls. It seems bits of Drupal 6's API were still in use.
---
 includes/opening_hours.pages.inc |    2 +-
 opening_hours.module             |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/includes/opening_hours.pages.inc b/includes/opening_hours.pages.inc
index 91b6649..18f6d4c 100644
--- a/includes/opening_hours.pages.inc
+++ b/includes/opening_hours.pages.inc
@@ -170,7 +170,7 @@ function _opening_hours_instance_update($instance, $original) {
         db_query("
           DELETE FROM {opening_hours}
           WHERE original_instance_id = :id
-          AND date > '%s'
+          AND date > :end_date
         ", array(
           ':id' => $instance->instance_id,
           ':end_date' => $instance->repeat_end_date,
diff --git a/opening_hours.module b/opening_hours.module
index db610ed..038e91a 100644
--- a/opening_hours.module
+++ b/opening_hours.module
@@ -156,13 +156,13 @@ function opening_hours_cron() {
       DELETE FROM {opening_hours}
       WHERE original_instance_id IS NOT NULL
       AND customised = 0
-      AND date < '%s'
+      AND date < :date
     ", array(':date' => date('Y-m-d', $_SERVER['REQUEST_TIME'] - 7 * 86400)));
 
     // Propagate instances that are still repeating.
     $propagate_query = db_query("
       SELECT * FROM {opening_hours}
-      WHERE repeat_end_date > '%s'
+      WHERE repeat_end_date > :date
       AND repeat_rule IS NOT NULL AND repeat_rule != ''
     ", array(':date' => date('Y-m-d', $_SERVER['REQUEST_TIME'])));
 
@@ -428,14 +428,14 @@ function opening_hours_repeat_instance_propagate(&$instance) {
  */
 function opening_hours_repeat_stop_propagation($instance_id) {
   // Get the date of the last non-deleted instance.
-  $max_date = db_result(db_query('
-    SELECT MAX(date) FROM {opening_hours} WHERE original_instance_id = %d
-  ', array(':id' => $instance_id)));
+  $max_date = db_query('
+    SELECT MAX(date) FROM {opening_hours} WHERE original_instance_id = :id
+  ', array(':id' => $instance_id))->fetchField();
 
   db_query("
     UPDATE {opening_hours}
-    SET repeat_end_date = '%s'
-    WHERE instance_id = %d
+    SET repeat_end_date = :date
+    WHERE instance_id = :id
   ", array(
     ':date' => $max_date,
     ':id' => $instance_id,
-- 
1.7.10.4

