-
Notifications
You must be signed in to change notification settings - Fork 14
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
Issue #81 No failure during duplicate and write error into event #90
Issue #81 No failure during duplicate and write error into event #90
Conversation
71e967f
to
af294bc
Compare
classes/actions.php
Outdated
try { | ||
$duplicatedmod = duplicate_module($modinfo->get_course(), $modinfo->get_cm($cmid)); | ||
} catch (\Exception $e) { | ||
$errors[] = 'cmid:' . $cmid . '(' . $e->getMessage() . ')'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it better to fire up an error event here instead of collecting errors and dump them in massaction_duplicated. Otherwise massaction_duplicated message could be very gross.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I push the error detail to a new "failed" event, and make simple for a "duplicate" event.
* @copyright 2023 Catalyst IT | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class massaction_duplicated extends base { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this event under massaction block. We don't really need to duplicate it in event name. How about renaming to activities_duplicated or course_modules_duplicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed it to "course_modules_duplicated".
foreach ($this->other['cms'] as $srccm => $dstcm) { | ||
$cms[] = 'cmid from \'' . $srccm . '\' to \'' . $dstcm . '\''; | ||
} | ||
$errormsg = !empty($this->other['errors']) ? " with error '" . implode("','", $this->other['errors']) : "'"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said before I think better just to log a number of errors rather than each individual error. And have a separate event (e.g. activity_duplication_failed ) for any error message. But it's up to a maintainer to decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error details go to a new "failed" event and the "duplicated" event has just number of failed and cmid.
public function get_description(): string { | ||
$cms = []; | ||
foreach ($this->other['cms'] as $srccm => $dstcm) { | ||
$cms[] = 'cmid from \'' . $srccm . '\' to \'' . $dstcm . '\''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be also useful to see which failed and which succeeded . A stats like 5 completed, 3 failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added total of complete/fail to the description.
protected function validate_data() { | ||
parent::validate_data(); | ||
|
||
if (!isset($this->other['cms']) || !is_array($this->other['cms'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we validate $this->other['errors'] also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the new validation.
Thanks @TomoTsuyuki for working on it. The code looks good in general. I have seen people copping hundreds of activities. I'm a bit worried how that all will look at the logs screen. I have left my comments. Also the patch covers just duplicate, what about duplicate_to_course? |
af294bc
to
7b080e0
Compare
Thanks for your review @dmitriim Please let me know if they are ok. |
try { | ||
$duplicatedmod = duplicate_module($modinfo->get_course(), $modinfo->get_cm($cmid)); | ||
} catch (\Exception $e) { | ||
$errors[$cmid] = 'cmid:' . $cmid . '(' . $e->getMessage() . ')'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any particular reason why you don't fire an event here, but instead later looping through the errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the event to catch block.
classes/actions.php
Outdated
@@ -276,6 +312,26 @@ public static function duplicate_to_course(array $modules, int $targetcourseid, | |||
moveto_module($targetmodinfo->get_cm($modid), $targetsection); | |||
} | |||
} | |||
$event = \block_massaction\event\course_modules_duplicated::create([ | |||
'context' => \context_course::instance($targetcourseid), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think we should trigger all those events in a context of a target course and not a source course?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed to $sourcecourseid
instead of $targecourseid
@TomoTsuyuki I'm sorry for all the delays on these proposed fixes. I had to make some decisions on the future direction of the plugin. We have made a fairly major change moving forward in 4.2+ so these changes and the ones in the other PR's will need rebased to the latest master commits. Also, when making these requests, please do not make changes to the version.php and I will alter the version number once we have integrated changes. That way we don't have constant conflicts on version numbers. I understand that for testing the version number might need tweaked to add new settings, lang strings, etc. Again sorry to send you back to development on all this work. Your time invested is really valued. Thank you. |
29ef3dc
to
0cd88f4
Compare
Hi @Syxton , Thanks for your comment. |
@TomoTsuyuki The 4.1 branch still works on 4.2 and 4.3, so I will of course still accept PR's that improve and extend the lifespan of that version of the plugin. Just create another PR for the sub 4.2 changes and submit against MOODLE_401_STABLE |
Thanks @Syxton , that's good news. |
0cd88f4
to
39993db
Compare
lang/en/block_massaction.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor things:
When is the event:massaction_duplicated string used?
Can we change the failed text from "Course modules duplicated failed" to "Course modules failed to duplicate"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomoTsuyuki just wanted to make sure you got notified on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review, @Syxton !
I deleted event:massaction_duplicated
and update event:course_modules_duplicated_failed
string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also rebased by the latest master/MOODLE_401_STABLE branch.
39993db
to
dd9c6f8
Compare
Implemented to avoid error in the middle of duplication. #81
Event "massaction_duplicated" has been introduced for the logging.