MDL-59382 calendar: fix event mapper and exporter
authorRyan Wyllie <ryan@moodle.com>
Mon, 24 Jul 2017 07:31:17 +0000 (07:31 +0000)
committerRyan Wyllie <ryan@moodle.com>
Wed, 2 Aug 2017 04:47:42 +0000 (04:47 +0000)
calendar/classes/external/event_exporter.php
calendar/classes/local/event/mappers/event_mapper.php

index baa73f6..ec2d938 100644 (file)
@@ -71,7 +71,7 @@ class event_exporter extends exporter {
         $data->timestart = $starttimestamp;
         $data->timeduration = $endtimestamp - $starttimestamp;
         $data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
-        $data->visible = $event->is_visible();
+        $data->visible = $event->is_visible() ? 1 : 0;
         $data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
 
         if ($repeats = $event->get_repeats()) {
index a4191f2..8e544dd 100644 (file)
@@ -54,28 +54,34 @@ class event_mapper implements event_mapper_interface {
 
     public function from_legacy_event_to_event(\calendar_event $legacyevent) {
         $coalesce = function($property) use ($legacyevent) {
-            return property_exists($legacyevent, $property) ? $legacyevent->{$property} : null;
+            try {
+                return $legacyevent->$property;
+            } catch (\coding_exception $e) {
+                // The magic setter throews an exception if the
+                // property doesn't exist.
+                return null;
+            }
         };
 
         return $this->factory->create_instance(
             (object)[
-                $coalesce('id'),
-                $coalesce('name'),
-                $coalesce('description'),
-                $coalesce('format'),
-                $coalesce('courseid'),
-                $coalesce('groupid'),
-                $coalesce('userid'),
-                $coalesce('repeatid'),
-                $coalesce('modulename'),
-                $coalesce('instance'),
-                $coalesce('type'),
-                $coalesce('timestart'),
-                $coalesce('timeduration'),
-                $coalesce('timemodified'),
-                $coalesce('timesort'),
-                $coalesce('visible'),
-                $coalesce('subscription')
+                'id' => $coalesce('id'),
+                'name' => $coalesce('name'),
+                'description' => $coalesce('description'),
+                'format' => $coalesce('format'),
+                'courseid' => $coalesce('courseid'),
+                'groupid' => $coalesce('groupid'),
+                'userid' => $coalesce('userid'),
+                'repeatid' => $coalesce('repeatid'),
+                'modulename' => $coalesce('modulename'),
+                'instance' => $coalesce('instance'),
+                'eventtype' => $coalesce('eventtype'),
+                'timestart' => $coalesce('timestart'),
+                'timeduration' => $coalesce('timeduration'),
+                'timemodified' => $coalesce('timemodified'),
+                'timesort' => $coalesce('timesort'),
+                'visible' => $coalesce('visible'),
+                'subscriptionid' => $coalesce('subscriptionid')
             ]
         );
     }