/**
  * Do the actual work of saving a recurring series of events
  * @param int $postId The event that is being saved
  * @param bool $updated
  * @return void
  */
 public static function saveEvents($postId, $updated = true)
 {
     $recStart = strtotime(self::get_series_start_date($postId));
     $eventEnd = strtotime(get_post_meta($postId, '_EventEndDate', true));
     $duration = $eventEnd - $recStart;
     $old_start_dates = get_post_meta($postId, '_EventStartDate');
     // different update types
     delete_post_meta($postId, '_EventStartDate');
     delete_post_meta($postId, '_EventEndDate');
     delete_post_meta($postId, '_EventDuration');
     delete_post_meta($postId, '_EventNextPendingRecurrence');
     // add back original start and end date
     add_post_meta($postId, '_EventStartDate', date(DateSeriesRules::DATE_FORMAT, $recStart));
     add_post_meta($postId, '_EventEndDate', date(DateSeriesRules::DATE_FORMAT, $eventEnd));
     add_post_meta($postId, '_EventDuration', $duration);
     $recurrence = self::getRecurrenceForEvent($postId);
     if ($recurrence) {
         $recurrence->setMinDate(strtotime(self::$scheduler->get_earliest_date()));
         $recurrence->setMaxDate(strtotime(self::$scheduler->get_latest_date()));
         $dates = (array) $recurrence->getDates($updated, $old_start_dates);
         if ($recurrence->constrainedByMaxDate() !== FALSE) {
             add_post_meta($postId, '_EventNextPendingRecurrence', date(DateSeriesRules::DATE_FORMAT, $recurrence->constrainedByMaxDate()));
         }
         foreach ($dates as $date) {
             add_post_meta($postId, '_EventStartDate', date(DateSeriesRules::DATE_FORMAT, $date));
         }
     }
 }
 /**
  * Do the actual work of saving a recurring series of events
  * @param int $postId The event that is being saved
  * @return void
  */
 public static function saveEvents($postId)
 {
     // don't use self::get_child_event_ids() due to caching that hasn't yet flushed
     $existing_instances = get_posts(array('post_parent' => $postId, 'post_type' => TribeEvents::POSTTYPE, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'any', 'meta_key' => '_EventStartDate', 'orderby' => 'meta_value', 'order' => 'ASC'));
     $recurrence = self::getRecurrenceForEvent($postId);
     if ($recurrence) {
         $recurrence->setMinDate(strtotime(self::$scheduler->get_earliest_date()));
         $recurrence->setMaxDate(strtotime(self::$scheduler->get_latest_date()));
         $dates = (array) $recurrence->getDates();
         $to_update = array();
         if ($recurrence->constrainedByMaxDate() !== FALSE) {
             update_post_meta($postId, '_EventNextPendingRecurrence', date(DateSeriesRules::DATE_FORMAT, $recurrence->constrainedByMaxDate()));
         }
         foreach ($existing_instances as $instance) {
             $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true));
             $found = array_search($start_date, $dates);
             if ($found === FALSE) {
                 do_action('tribe_events_deleting_child_post', $instance, $start_date);
                 wp_delete_post($instance, TRUE);
             } else {
                 $to_update[$instance] = $dates[$found];
                 unset($dates[$found]);
                 // so we don't re-add it
             }
         }
         foreach ($dates as $date) {
             $instance = new TribeEventsPro_RecurrenceInstance($postId, $date);
             $instance->save();
         }
         foreach ($to_update as $instance_id => $date) {
             $instance = new TribeEventsPro_RecurrenceInstance($postId, $date, $instance_id);
             $instance->save();
         }
     }
 }
 /**
  * Do the actual work of saving a recurring series of events
  *
  * @param int $postId The event that is being saved
  *
  * @return void
  */
 public static function saveEvents($postId)
 {
     // don't use self::get_child_event_ids() due to caching that hasn't yet flushed
     $existing_instances = get_posts(array('post_parent' => $postId, 'post_type' => TribeEvents::POSTTYPE, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => get_post_stati(), 'meta_key' => '_EventStartDate', 'orderby' => 'meta_value', 'order' => 'ASC'));
     $recurrence = self::getRecurrenceForEvent($postId);
     if ($recurrence) {
         $recurrence->setMinDate(strtotime(self::$scheduler->get_earliest_date()));
         $recurrence->setMaxDate(strtotime(self::$scheduler->get_latest_date()));
         $dates = (array) $recurrence->getDates();
         $to_update = array();
         if ($recurrence->constrainedByMaxDate() !== false) {
             update_post_meta($postId, '_EventNextPendingRecurrence', date(DateSeriesRules::DATE_FORMAT, $recurrence->constrainedByMaxDate()));
         }
         foreach ($existing_instances as $instance) {
             $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true));
             $found = array_search($start_date, $dates);
             if ($found === false) {
                 do_action('tribe_events_deleting_child_post', $instance, $start_date);
                 // deleting a post would normally add it to the excluded dates array
                 // we don't want that if a child is deleted due to a recurrence change
                 remove_action('before_delete_post', array(__CLASS__, 'handle_delete_request'));
                 wp_delete_post($instance, true);
                 add_action('before_delete_post', array(__CLASS__, 'handle_delete_request'));
             } else {
                 $to_update[$instance] = $dates[$found];
                 unset($dates[$found]);
                 // so we don't re-add it
             }
         }
         $excluded = array_map('strtotime', self::get_excluded_dates($postId));
         foreach ($dates as $date) {
             if (!in_array($date, $excluded)) {
                 $instance = new TribeEventsPro_RecurrenceInstance($postId, $date);
                 $instance->save();
             }
         }
         foreach ($to_update as $instance_id => $date) {
             $instance = new TribeEventsPro_RecurrenceInstance($postId, $date, $instance_id);
             $instance->save();
         }
     }
 }