Ejemplo n.º 1
0
 /**
  * Do the actual work of saving a recurring series of events
  *
  * @param int $event_id The event that is being saved
  *
  * @return void
  */
 public static function saveEvents($event_id)
 {
     // don't use self::get_child_event_ids() due to caching that hasn't yet flushed
     $existing_instances = get_posts(array('post_parent' => $event_id, 'post_type' => Tribe__Events__Main::POSTTYPE, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => get_post_stati(), 'meta_key' => '_EventStartDate', 'orderby' => 'meta_value', 'order' => 'ASC'));
     $recurrences = self::get_recurrence_for_event($event_id);
     $to_create = array();
     $exclusions = array();
     $to_update = array();
     $to_delete = array();
     $possible_next_pending = array();
     $earliest_date = strtotime(self::$scheduler->get_earliest_date());
     $latest_date = strtotime(self::$scheduler->get_latest_date());
     foreach ($recurrences['rules'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $to_create = array_merge($to_create, $recurrence->getDates());
         if ($recurrence->constrainedByMaxDate() !== false) {
             $possible_next_pending[] = $recurrence->constrainedByMaxDate();
         }
     }
     $to_create = self::array_unique($to_create);
     // find days we should exclude
     foreach ($recurrences['exclusions'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $exclusions = array_merge($exclusions, $recurrence->getDates());
     }
     // make sure we don't create excluded dates
     $exclusions = self::array_unique($exclusions);
     $to_create = self::remove_exclusions($to_create, $exclusions);
     if ($possible_next_pending) {
         update_post_meta($event_id, '_EventNextPendingRecurrence', date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, min($possible_next_pending)));
     }
     foreach ($existing_instances as $instance) {
         $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true) . '+00:00');
         $end_date = strtotime(get_post_meta($instance, '_EventEndDate', true) . '+00:00');
         $duration = $end_date - $start_date;
         $existing_date_duration = array('timestamp' => $start_date, 'duration' => $duration);
         $found = array_search($existing_date_duration, $to_create);
         $should_be_excluded = in_array($existing_date_duration, $exclusions);
         if ($found === false || false !== $should_be_excluded) {
             $to_delete[$instance] = $existing_date_duration;
         } else {
             $to_update[$instance] = $to_create[$found];
             unset($to_create[$found]);
             // so we don't re-add it
         }
     }
     // Store the list of instances to create/update/delete etc for future processing
     $queue = new Tribe__Events__Pro__Recurrence__Queue($event_id);
     $queue->update($to_create, $to_update, $to_delete, $exclusions);
     // ...but don't wait around, process a small initial batch right away
     Tribe__Events__Pro__Main::instance()->queue_processor->process_batch($event_id);
 }
Ejemplo n.º 2
0
 /**
  * Do the actual work of saving a recurring series of events
  *
  * @return bool
  */
 public function save_events()
 {
     $existing_instances = Tribe__Events__Pro__Recurrence__Children_Events::instance()->get_ids($this->event_id);
     $recurrences = Tribe__Events__Pro__Recurrence__Meta::get_recurrence_for_event($this->event_id);
     $to_create = array();
     $exclusions = array();
     $to_update = array();
     $to_delete = array();
     $possible_next_pending = array();
     $earliest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_earliest_date());
     $latest_date = strtotime(Tribe__Events__Pro__Recurrence__Meta::$scheduler->get_latest_date());
     foreach ($recurrences['rules'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $to_create = array_merge($to_create, $recurrence->getDates());
         if ($recurrence->constrainedByMaxDate() !== false) {
             $possible_next_pending[] = $recurrence->constrainedByMaxDate();
         }
     }
     $to_create = tribe_array_unique($to_create);
     // find days we should exclude
     foreach ($recurrences['exclusions'] as &$recurrence) {
         if (!$recurrence) {
             continue;
         }
         $recurrence->setMinDate($earliest_date);
         $recurrence->setMaxDate($latest_date);
         $exclusions = array_merge($exclusions, $recurrence->getDates());
     }
     // make sure we don't create excluded dates
     $exclusions = tribe_array_unique($exclusions);
     $to_create = $this->exclusions->remove_exclusions($to_create, $exclusions);
     if ($possible_next_pending) {
         update_post_meta($this->event_id, '_EventNextPendingRecurrence', date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, min($possible_next_pending)));
     }
     foreach ($existing_instances as $instance) {
         $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true) . '+00:00');
         $end_date = strtotime(get_post_meta($instance, '_EventEndDate', true) . '+00:00');
         $duration = $end_date - $start_date;
         $existing_date_duration = array('timestamp' => $start_date, 'duration' => $duration);
         $found = array_search($existing_date_duration, $to_create);
         $should_be_excluded = in_array($existing_date_duration, $exclusions);
         if ($found === false || false !== $should_be_excluded) {
             $to_delete[$instance] = $existing_date_duration;
         } else {
             $to_update[$instance] = $to_create[$found];
             unset($to_create[$found]);
             // so we don't re-add it
         }
     }
     // Store the list of instances to create/update/delete etc for future processing
     $queue = new Tribe__Events__Pro__Recurrence__Queue($this->event_id);
     $queue->update($to_create, $to_update, $to_delete, $exclusions);
     // ...but don't wait around, process a small initial batch right away
     Tribe__Events__Pro__Main::instance()->queue_processor->process_batch($this->event_id);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Do the actual work of saving a recurring series of events
  *
  * @param int $event_id The event that is being saved
  *
  * @return void
  */
 public static function saveEvents($event_id)
 {
     // don't use self::get_child_event_ids() due to caching that hasn't yet flushed
     $existing_instances = get_posts(array('post_parent' => $event_id, 'post_type' => Tribe__Events__Main::POSTTYPE, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => get_post_stati(), 'meta_key' => '_EventStartDate', 'orderby' => 'meta_value', 'order' => 'ASC'));
     $recurrence = self::getRecurrenceForEvent($event_id);
     if ($recurrence) {
         $recurrence->setMinDate(strtotime(self::$scheduler->get_earliest_date()));
         $recurrence->setMaxDate(strtotime(self::$scheduler->get_latest_date()));
         $to_create = (array) $recurrence->getDates();
         $to_update = array();
         $to_delete = array();
         if ($recurrence->constrainedByMaxDate() !== false) {
             update_post_meta($event_id, '_EventNextPendingRecurrence', date(Tribe__Events__Pro__Date_Series_Rules__Rules_Interface::DATE_FORMAT, $recurrence->constrainedByMaxDate()));
         }
         foreach ($existing_instances as $instance) {
             $start_date = strtotime(get_post_meta($instance, '_EventStartDate', true) . '+00:00');
             $found = array_search($start_date, $to_create);
             if ($found === false) {
                 $to_delete[$instance] = $start_date;
             } else {
                 $to_update[$instance] = $to_create[$found];
                 unset($to_create[$found]);
                 // so we don't re-add it
             }
         }
         $exclusions = array_map('strtotime', self::get_excluded_dates($event_id));
         // Store the list of instances to create/update/delete etc for future processing
         $queue = new Tribe__Events__Pro__Recurrence__Queue($event_id);
         $queue->update($to_create, $to_update, $to_delete, $exclusions);
         // ...but don't wait around, process a small initial batch right away
         Tribe__Events__Pro__Main::instance()->queue_processor->process_batch($event_id);
     }
 }