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

Issue #81 No failure during duplicate and write error into event #90

Merged
merged 8 commits into from
Jan 11, 2024

Conversation

TomoTsuyuki
Copy link

@TomoTsuyuki TomoTsuyuki commented Oct 13, 2023

Implemented to avoid error in the middle of duplication. #81
Event "massaction_duplicated" has been introduced for the logging.

image

@TomoTsuyuki TomoTsuyuki force-pushed the issue81-update-mass-duplicate branch from 71e967f to af294bc Compare October 13, 2023 00:20
try {
$duplicatedmod = duplicate_module($modinfo->get_course(), $modinfo->get_cm($cmid));
} catch (\Exception $e) {
$errors[] = 'cmid:' . $cmid . '(' . $e->getMessage() . ')';

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.

Copy link
Author

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 {

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?

Copy link
Author

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']) : "'";

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.

Copy link
Author

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 . '\'';
Copy link

@dmitriim dmitriim Oct 13, 2023

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.

Copy link
Author

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'])) {

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?

Copy link
Author

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.

@dmitriim
Copy link

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?

@TomoTsuyuki TomoTsuyuki force-pushed the issue81-update-mass-duplicate branch from af294bc to 7b080e0 Compare October 13, 2023 05:53
@TomoTsuyuki
Copy link
Author

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?

Thanks for your review @dmitriim
I updated the events and support duplicate_to_course.

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() . ')';
Copy link

@dmitriim dmitriim Oct 13, 2023

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?

Copy link
Author

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.

@@ -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),

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?

Copy link
Author

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

classes/actions.php Outdated Show resolved Hide resolved
@Syxton
Copy link
Owner

Syxton commented Oct 24, 2023

@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.

@Syxton Syxton linked an issue Oct 24, 2023 that may be closed by this pull request
@TomoTsuyuki TomoTsuyuki force-pushed the issue81-update-mass-duplicate branch from 29ef3dc to 0cd88f4 Compare October 24, 2023 22:49
@TomoTsuyuki
Copy link
Author

Hi @Syxton ,

Thanks for your comment.
I rebased my branch with master, and removed the version.php from the commit.
Are you accepting PRs for the new MOODLE_401_STABLE branch?
If you will maintain only master branch, we need to make our fork to update the MOODLE_401_STABLE branch as our clients are using 4.1 LTS.

@Syxton
Copy link
Owner

Syxton commented Oct 25, 2023

@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

@TomoTsuyuki
Copy link
Author

Thanks @Syxton , that's good news.
I made PRs for 401 branches.
Please review and let me know if I need to do extra work.

@TomoTsuyuki TomoTsuyuki force-pushed the issue81-update-mass-duplicate branch from 0cd88f4 to 39993db Compare November 21, 2023 00:53
Copy link
Owner

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"

Copy link
Owner

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.

Copy link
Author

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.

Copy link
Author

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.

@TomoTsuyuki TomoTsuyuki force-pushed the issue81-update-mass-duplicate branch from 39993db to dd9c6f8 Compare January 11, 2024 04:39
@Syxton Syxton merged commit 692919f into Syxton:master Jan 11, 2024
8 checks passed
Syxton pushed a commit that referenced this pull request Dec 16, 2024
* Update ci.yml

* Issue #81 No failure during duplicate and write error into event

* Issue #81 Add fail event and support duplicate to another course

* Issue #81 Refactor error event trigger
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.

Rerunning duplicate_task can cause duplicates
3 participants