The "user_created" event is not triggered during course restore on purpose, restore process does not trigger any core events.
There is a "course_restored" event that can be observed, however there is no way/API currently to find the list of created users (or modules, etc)
From conversation with Eloy Lafuente (stronk7)
Eloy Lafuente Plaza, [6 Apr 2020 at 10:53:53]:
so there are 2 alternatives:
- or we create that new user_created_on_reastore event
- or we use something into temp tables to have them at hand and we observe the course_restored event.
Marina, [6 Apr 2020 at 10:54:57]:
it is ok to add methods to course_restored event class to find relevant data? Like list of created users for example
these methods can only be used inside event observers
Eloy Lafuente Plaza, [6 Apr 2020 at 10:56:23]:
doesn't sound wrong, is my first thought.
can be useful to others observing the same event. Just hope it doesn't end being a spaghetti/monster event (then maybe we should consider moving it apart)
Marina, [6 Apr 2020 at 10:59:22]:
is it possible that there is a scenario when users are created during restore process but then another error occurs and course is not restored and course_restored event is not triggered?
Eloy Lafuente Plaza, [6 Apr 2020 at 11:01:42]:
uff, everything is possible 🙂 I don't think we run restore under transaction ...