/** * Test that using eo_get_add_to_google_link() does not reset timezone of * start/end date of event * @see https://wordpress.org/support/topic/eo_get_add_to_google_link?replies=1 */ public function testAddToGoogleLink() { $tz = ini_get('date.timezone'); $original_tz = get_option('timezone_string'); $original_offset = get_option('gmt_offset'); update_option('timezone_string', ''); update_option('gmt_offset', 10); $event_id = $this->factory->event->create(array('start' => new DateTime('2014-07-09 13:02:00', eo_get_blog_timezone()), 'end' => new DateTime('2014-07-09 14:02:00', eo_get_blog_timezone()), 'all_day' => 0, 'schedule' => 'once')); $occurrences = eo_get_the_occurrences($event_id); $occurrence_ids = array_keys($occurrences); $occurrence_id = array_shift($occurrence_ids); $actual = eo_get_the_start('Y-m-d H:i:s', $event_id, null, $occurrence_id); $this->assertEquals('2014-07-09 13:02:00', $actual); eo_get_add_to_google_link($event_id, $occurrence_id); $actual = eo_get_the_start('Y-m-d H:i:s', $event_id, null, $occurrence_id); $this->assertEquals('2014-07-09 13:02:00', $actual); update_option('timezone_string', $original_tz); update_option('gmt_offset', $original_offset); }
/** * @see https://github.com/stephenharris/Event-Organiser/issues/242 */ function testDuplicatePostCompatability() { $tz = eo_get_blog_timezone(); $start = new DateTime('2015-02-12 14:45:00', $tz); $end = new DateTime('2015-02-12 15:45:00', $tz); $event = array('start' => $start, 'end' => $end, 'frequency' => 1, 'schedule' => 'weekly', 'schedule_meta' => array('TH'), 'schedule_last' => new DateTime('2015-02-26 14:45:00', $tz)); $event_id = $this->factory->event->create($event); $event_post = get_post($event_id); $duplicated_event_id = $this->duplicate($event_post); $this->duplicate_metadata($duplicated_event_id, $event_post); eo_update_event($duplicated_event_id); //Check occurrences of duplicate event exist $expected = array(new DateTime('2015-02-12 14:45:00', $tz), new DateTime('2015-02-19 14:45:00', $tz), new DateTime('2015-02-26 14:45:00', $tz)); $actual = eo_get_the_occurrences($duplicated_event_id); $actual = array_values($actual); $this->assertEquals($expected, $actual); }
/** * Updates a specific occurrence, and preserves the occurrence ID. * * Currently two occurrences cannot occupy the same date. * * @ignore * @access private * @since 2.12.0 * * @param int $event_id ID of the event whose occurrence we're moving * @param int $occurrence_id ID of the occurrence we're moving * @param DateTime $start New start DateTime of the occurrence * @param DateTime $end New end DateTime of the occurrence * @return bool|WP_Error True on success. WP_Error on failure. */ function eventorganiser_move_occurrence($event_id, $occurrence_id, $start, $end) { global $wpdb; $old_start = eo_get_the_start(DATETIMEOBJ, $event_id, null, $occurrence_id); $schedule = eo_get_event_schedule($event_id); if ($start == $old_start) { return true; } $current_occurrences = eo_get_the_occurrences($event_id); unset($current_occurrences[$occurrence_id]); $current_occurrences = array_map('eo_format_datetime', $current_occurrences); if (in_array($start->format('d-m-Y'), $current_occurrences)) { return new WP_Error('events-cannot-share-date', __('There is already an occurrence on this date', 'eventorganiser')); } //We update the date directly in the DB first so the occurrence is not deleted and recreated, //but simply updated. $wpdb->update($wpdb->eo_events, array('StartDate' => $start->format('Y-m-d'), 'StartTime' => $start->format('H:i:s'), 'EndDate' => $end->format('Y-m-d'), 'FinishTime' => $end->format('H:i:s')), array('event_id' => $occurrence_id)); wp_cache_delete('eventorganiser_occurrences_' . $event_id); //Important: update DB clear cache //Now update event schedule... //If date being removed was manually included remove it, //otherwise add it to exclude. Then add new date as include. if (false === ($index = array_search($old_start, $schedule['include']))) { $schedule['exclude'][] = $old_start; } else { unset($schedule['include'][$index]); } $schedule['include'][] = $start; $re = eo_update_event($event_id, $schedule); if ($re && !is_wp_error($re)) { return true; } return $re; }