From 17d498e5e3498725180bf360a44cf3ac60da020a Mon Sep 17 00:00:00 2001
From: Yalu <yalu@157501.no-reply.drupal.org>
Date: Fri, 20 Mar 2015 12:03:03 +0545
Subject: [PATCH] removed redundant update of availability calendar and locking
 of booking event when creating new booking on commerce_checkout_complete

---
 modules/rooms_booking/rooms_booking.module    |  5 ++++
 .../rooms_booking_manager.module              | 28 -------------------
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/modules/rooms_booking/rooms_booking.module b/modules/rooms_booking/rooms_booking.module
index f8c78e4..4d57146 100644
--- a/modules/rooms_booking/rooms_booking.module
+++ b/modules/rooms_booking/rooms_booking.module
@@ -1060,8 +1060,13 @@ class RoomsBookingController extends EntityAPIController {
 
       $entity->rooms_av_update = $responses[$event_id];
 
+      // If the event addition was succesful lock the event.
       if ($responses[$event_id] == ROOMS_UPDATED) {
         $be->lock();
+        watchdog('rooms_booking', 'Unit availability has been updated.', array(), WATCHDOG_NOTICE);
+      }
+      else {
+        watchdog('rooms_booking', 'Unit availability could not be updated.', array(), WATCHDOG_ERROR);
       }
     }
   }
diff --git a/modules/rooms_booking_manager/rooms_booking_manager.module b/modules/rooms_booking_manager/rooms_booking_manager.module
index 6a9b07b..697b974 100644
--- a/modules/rooms_booking_manager/rooms_booking_manager.module
+++ b/modules/rooms_booking_manager/rooms_booking_manager.module
@@ -1956,34 +1956,6 @@ function rooms_booking_manager_commerce_checkout_complete($order) {
         // Line item 'Entity Reference field' that points to the booking.
         $line_item->rooms_booking_reference['und'][0]['target_id'] = $booking->booking_id;
         commerce_line_item_save($line_item);
-
-        // Now let us lock availability
-        // First - we get an event id.
-        $id = rooms_availability_assign_id($booking->booking_id, '1');
-        // Set the start and end dates for the booking event.
-        // They are the same as the booking above but the end date is not the
-        // departure date rather it is the last night spend in the room.
-        $sd = new DateTime($booking->start_date);
-
-        // End date is actually a day less.
-        $ed = new DateTime($line_item->rooms_booking_dates[LANGUAGE_NONE][0]['value2']);
-        $ed->sub(new DateInterval('P1D'));
-
-        // Create a booking event.
-        $be = new BookingEvent($booking->unit_id, $id, $sd, $ed);
-
-        // Call up the UnitCalendar for this unit and add the event to it.
-        $rc = new UnitCalendar($booking->unit_id);
-        $responses = $rc->updateCalendar(array($be));
-
-        // If the event addition was succesful lock the event.
-        if ($responses[$id] == ROOMS_UPDATED) {
-          $be->lock();
-          watchdog('rooms_booking_manager', 'Unit availability has been updated.', array(), WATCHDOG_NOTICE);
-        }
-        else {
-          watchdog('rooms_booking_manager', 'Unit availability could not be updated.', array(), WATCHDOG_ERROR);
-        }
       }
     }
   }