function bat_event_update_8001 in Booking and Availability Management Tools for Drupal 8
Migrate event's dates on the new field.
File
- modules/
bat_event/ bat_event.install, line 44 - Sets up the base table for our entity and a table to store information about the entity types.
Code
function bat_event_update_8001() {
$events = \Drupal::database()
->select('event', 'e')
->fields('e', [])
->condition('start', '', '<>')
->execute()
->fetchAll();
foreach ($events as $event) {
$event_object = bat_event_load($event->id);
$start_date = new DateTime();
$start_date
->setTimestamp($event->start);
$end_date = new DateTime();
$end_date
->setTimestamp($event->end);
$event_object
->setStartDate($start_date);
$event_object
->setEndDate($end_date);
$event_object
->save();
}
}