private function convert_recurring_event_to_child_posts($event_id)
 {
     $start_dates = get_post_meta($event_id, '_EventStartDate', false);
     if (!is_array($start_dates)) {
         return;
     }
     $original = array_shift($start_dates);
     $start_dates = array_map('strtotime', $start_dates);
     $prepared_start_dates = array_map(array($this, 'start_date_to_sequence'), $start_dates);
     $sequence = new Tribe__Events__Pro__Recurrence__Sequence($prepared_start_dates, $event_id);
     foreach ($sequence->get_sorted_sequence() as $date) {
         if (!empty($date)) {
             set_time_limit(30);
             $instance = new Tribe__Events__Pro__Recurrence__Instance($event_id, $date, 0, $date['sequence']);
             $instance->save();
             delete_post_meta($event_id, '_EventStartDate', date('Y-m-d H:i:s', $date));
         }
     }
     delete_post_meta($event_id, '_EventStartDate');
     update_post_meta($event_id, '_EventStartDate', $original);
 }
Example #2
0
 protected function do_creations()
 {
     $exclusions = $this->current_queue->instances_to_exclude();
     $instances_to_create = array_values($this->current_queue->instances_to_create());
     try {
         $sequence = new Tribe__Events__Pro__Recurrence__Sequence($instances_to_create, $this->current_event_id);
     } catch (Exception $e) {
         $exception = new Tribe__Exception($e);
         $exception->handle();
         return;
     }
     foreach ($sequence->get_sorted_sequence() as $key => $date_duration) {
         // Don't process more than the current batch size allows
         if ($this->batch_complete()) {
             break;
         }
         // Some instances may deliberately have been removed - let's remove
         // them from the list of events to create and move on
         if (in_array($date_duration, $exclusions)) {
             unset($instances_to_create[$date_duration['original_index']]);
             $this->processed++;
             continue;
         }
         if (!$this->current_queue->have_ownership_of_job()) {
             return;
         }
         $sequence_number = isset($date_duration['sequence']) ? $date_duration['sequence'] : 1;
         $instance = new Tribe__Events__Pro__Recurrence__Instance($this->current_event_id, $date_duration, 0, $sequence_number);
         if (!$instance->already_exists()) {
             $instance->save();
         }
         unset($instances_to_create[$date_duration['original_index']]);
         $this->processed++;
     }
     $this->current_queue->instances_to_create($instances_to_create);
 }
Example #3
0
 public static function save_pending_events($event_id)
 {
     if (wp_get_post_parent_id($event_id) != 0) {
         return;
     }
     $next_pending = get_post_meta($event_id, '_EventNextPendingRecurrence', true);
     if (empty($next_pending)) {
         return;
     }
     $latest_date = strtotime(self::$scheduler->get_latest_date());
     $recurrences = self::get_recurrence_for_event($event_id);
     /** @var Tribe__Events__Pro__Recurrence $recurrence */
     foreach ($recurrences['rules'] as &$recurrence) {
         $recurrence->setMinDate(strtotime($next_pending));
         $recurrence->setMaxDate($latest_date);
         $dates = (array) $recurrence->getDates();
         if (empty($dates)) {
             return;
             // nothing to add right now. try again later
         }
         $sequence = new Tribe__Events__Pro__Recurrence__Sequence($dates, $event_id);
         delete_post_meta($event_id, '_EventNextPendingRecurrence');
         if ($recurrence->constrainedByMaxDate() !== false) {
             update_post_meta($event_id, '_EventNextPendingRecurrence', date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $recurrence->constrainedByMaxDate()));
         }
         $excluded = array_map('strtotime', self::get_excluded_dates($event_id));
         foreach ($sequence->get_sorted_sequence() as $date_duration) {
             if (!in_array($date_duration, $excluded)) {
                 $instance = new Tribe__Events__Pro__Recurrence__Instance($event_id, $date_duration, 0, $date_duration['sequence']);
                 $instance->save();
             }
         }
     }
 }