Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure events are only triggered when necessary #595

Closed
wants to merge 1 commit into from

Conversation

mdjnelson
Copy link
Owner

  1. Suppress template_updated when creating new template.

  2. Fix Save changes/Add element so template_updated triggered if name changed.

  3. Fix context for page_created when loading a template in course instance (was system now course module).

@mdjnelson
Copy link
Owner Author

Hi @leonstr, sorry it took me a while to see you had pushed code but there was no PR yet, so created this. Does this include all fixes for events or is there still more to do? I would like to fix up the events code before I push another release.

@mdjnelson
Copy link
Owner Author

This issue should ideally solve all the issues found in #570.

@leonstr
Copy link
Contributor

leonstr commented Jan 10, 2024

@mdjnelson From memory this is not yet complete. Apologies for the delay. I'll aim to pick this up in the next week with a view to getting this wrapped up.

@mdjnelson
Copy link
Owner Author

Thanks @leonstr!

@mdjnelson
Copy link
Owner Author

Ping @leonstr! :)

@leonstr
Copy link
Contributor

leonstr commented Jan 23, 2024

Just acknowledging the ping. I've been working on this on Saturday and today. A bit more testing is required, I'll try to have this done in the next day.

@leonstr
Copy link
Contributor

leonstr commented Jan 24, 2024

Have updated PR. Hopefully this fixes all issues listed in #570 and doesn't break anything (PHPUnit tests pass on my host).

Apologies for the time taken to respond to this.

@mdjnelson
Copy link
Owner Author

Looking now 👀.

Copy link
Owner Author

@mdjnelson mdjnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @leonstr for persisting with this! Some comments to consider. I would say the more unit tests the better to consider all scenarios so adding more would be great.

classes/template.php Show resolved Hide resolved
classes/template.php Outdated Show resolved Hide resolved
classes/template.php Show resolved Hide resolved
load_template.php Outdated Show resolved Hide resolved

// Delete the pages.
$DB->delete_records('customcert_pages', array('templateid' => $template->get_id()));
if ($pages = $DB->get_records('customcert_pages', array('templateid' => $template->get_id()))) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use [] instead of array().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@leonstr
Copy link
Contributor

leonstr commented Jan 25, 2024

Thanks for the feedback @mdjnelson most of these look straightforward, give me another day or so to look at what PHPUnit testing I can add.

@mdjnelson
Copy link
Owner Author

mdjnelson commented Jan 25, 2024

No worries @leonstr, thanks for you help! I am currently doing a refactor to make pages, templates and elements persistents which can contain the logic for triggering these events (if we want (may be a bad idea havent thought abt it too much) but not just that but this was needed a long time ago cause the logic is all over the place). However, this will take me a bit so go ahead with what you are doing and yeh, unit tests would be great to know my refactor isnt screwing everything up. :D

@mdjnelson mdjnelson changed the title 564 Event fixes Ensure events are only triggered when necessary Jan 25, 2024
1. Suppress template_updated when creating new template.
2. Fix Save changes/Add element so template_updated triggered if name
   changed.
3. Fix context for page_created when loading a template in course
   instance (was CONTEXT_SYSTEM).
4. Previously with >1 pages each page_updated had template_updated too.
   Now only one template_updated is triggered when multiple page_updated
   events.
5. Previously there were two template_created events when copying
   a template.  Now fixed (i.e. just one template_created).
6. Previously loading a template had page_created without corresponding
   page_deleted (as with elements).  Now fixed.
@leonstr
Copy link
Contributor

leonstr commented Jan 30, 2024

PHPUnit tests: I've added checks for events' contexts, currently this is "system" except for test_load_template which I've added to catch one of the problems originally reported (Loading a template for a course activity instance includes a page_created event with context: system). I've also removed the objectid checks in test_copy_to_template since a) these were incorrect (param1 and param2 are the same), and b) we're using copy_to_template() to create records so don't deterministically know what their IDs will be (likely the existing IDs + 1, but we shouldn't count on that).

@mdjnelson
Copy link
Owner Author

Cherry-picked, thanks!

@mdjnelson mdjnelson closed this Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants