Skip to content

Commit

Permalink
event observer on delete and migrate, fixes elan-ev#145
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Mar 25, 2021
1 parent c37034d commit 90ebd6a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions MeetingPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use ElanEv\Model\CourseConfig;
use ElanEv\Model\MeetingCourse;
use ElanEv\Model\Meeting;

use Meetings\AppFactory;
use Meetings\RouteMap;
Expand Down Expand Up @@ -52,6 +53,8 @@ public function __construct()
}
}

NotificationCenter::addObserver($this, 'DeleteMeetingOnUserDelete', 'UserDidDelete');
NotificationCenter::addObserver($this, 'UpdateMeetingOnUserMigrate', 'UserDidMigrate');

// do nothing if plugin is deactivated in this seminar/institute
if (!$this->isActivated()) {
Expand Down Expand Up @@ -324,4 +327,33 @@ public static function getMeetingManifestInfo()
$manifest = $plugin_manager->getPluginManifest($plugin_path);
return $manifest;
}

/**
* DeleteMeetingOnUserDelete: handler for UserDidDelete event
*
* @param object event
* @param user $user
*
*/
public function DeleteMeetingOnUserDelete($event, $user) {
foreach (MeetingCourse::findByUser($user) as $meetingCourse) {
$meetingCourse->meeting->delete();
$meetingCourse->delete();
}
}

/**
* UpdateMeetingOnUserMigrate: handler for UserDidMigrate event
*
* @param string $old_id old user id
* @param string $new_id new user id
*
*/
public function UpdateMeetingOnUserMigrate($event, $old_id, $new_id) {
$user_meetings = Meeting::findBySQL('user_id = ?', [$old_id]);
foreach ($user_meetings as $meeting) {
$meeting->user_id = $new_id;
$meeting->store();
}
}
}

0 comments on commit 90ebd6a

Please sign in to comment.