diff --git a/actions/notification/classes/actionform.php b/actions/notification/classes/actionform.php index de4aed1..062c20d 100644 --- a/actions/notification/classes/actionform.php +++ b/actions/notification/classes/actionform.php @@ -308,8 +308,8 @@ protected function recreate_instance_schedules(int $templateid) { $instances = $this->get_template_instances($templateid); foreach ($instances as $instanceid => $instance) { - $notification = $DB->get_field('pulseaction_notification', 'id', ['instanceid' => $instanceid]); - notification::instance($notification->id)->recreate_schedule_forinstance(); + $notification = $DB->get_field('pulseaction_notification_ins', 'id', ['instanceid' => $instanceid]); + notification::instance($notification)->recreate_schedule_forinstance(); } } diff --git a/actions/notification/classes/notification.php b/actions/notification/classes/notification.php index ac5ae5a..658b49c 100644 --- a/actions/notification/classes/notification.php +++ b/actions/notification/classes/notification.php @@ -191,8 +191,13 @@ class notification { /** * Create the instance of the notification controller. * +<<<<<<< .mine + * @param [type] $notificationid Notification instance record id NOT autoinstanceid or notificationid. + * @return self +======= * @param int $notificationid Notification instance record id NOT autoinstanceid. * @return notification +>>>>>>> .theirs */ public static function instance($notificationid) { static $instance; @@ -222,7 +227,10 @@ protected function create_instance_data() { global $DB; $notification = $DB->get_record('pulseaction_notification_ins', ['id' => $this->notificationid]); - + + if (empty($notification)) { + throw new \moodle_exception('notificationinstancenotfound', 'pulse'); + } $instance = instances::create($notification->instanceid); $autoinstance = $instance->get_instance_data(); @@ -459,6 +467,8 @@ protected function remove_schedules($status=self::STATUS_SENT) { */ public function recreate_schedule_forinstance() { // Remove the current queued schedules. + $this->create_instance_data(); + $this->remove_schedules(self::STATUS_QUEUED); // Create the schedules for all users. $this->create_schedule_forinstance(); diff --git a/actions/notification/classes/schedule.php b/actions/notification/classes/schedule.php index f980314..cbd8431 100644 --- a/actions/notification/classes/schedule.php +++ b/actions/notification/classes/schedule.php @@ -309,7 +309,7 @@ protected function get_scheduled_records($userid=null) { AND (ej1_ue.timeend = 0 OR ej1_ue.timeend > :timeend) GROUP BY eu1_u.id, ej1_e.courseid ) AS active_enrols ON active_enrols.id = ue.id AND active_enrols.courseid = c.id - WHERE ns.status = :status AND an.status = 1 + WHERE ns.status = :status AND active_enrols.activeenrolment <> 0 AND c.visible = 1 AND c.startdate <= :startdate AND (c.enddate = 0 OR c.enddate >= :enddate) diff --git a/actions/notification/lib.php b/actions/notification/lib.php index c9a3318..e25b31f 100644 --- a/actions/notification/lib.php +++ b/actions/notification/lib.php @@ -124,7 +124,8 @@ function pulseaction_notification_output_fragment_preview_content($args) { $coursecontext = $args['context']; if (isset($args['contentheader'])) { - $course = get_course($args['courseid'] ?? $coursecontext->instanceid); + $courseid = $args['courseid'] ?? $coursecontext->instanceid; + $course = get_course($courseid ?: SITEID); // Get the enrolled users for this course. $users = get_enrolled_users($coursecontext); diff --git a/classes/automation/instances.php b/classes/automation/instances.php index 8406d76..30d2533 100644 --- a/classes/automation/instances.php +++ b/classes/automation/instances.php @@ -521,7 +521,7 @@ public static function manage_instance($formdata) { ]; // Check the isntance is already created. if created update the record otherwise create new instance. - + $instancedata->timemodified = time(); if (isset($formdata->instanceid) && $DB->record_exists('pulse_autoinstances', ['id' => $formdata->instanceid])) { $instancedata->id = $formdata->instanceid; @@ -585,6 +585,7 @@ public static function manage_instance($formdata) { $tablename = 'pulse_autotemplates_ins'; // Template instance tablename to update. // Update the instance overridden data related to template. + $templatedata['timemodified'] = time(); \mod_pulse\automation\templates::update_instance_data($instanceid, $templatedata); // ...Send the data to action plugins for perform the data store. diff --git a/classes/automation/templates.php b/classes/automation/templates.php index 7011a6e..175f4c8 100644 --- a/classes/automation/templates.php +++ b/classes/automation/templates.php @@ -380,6 +380,7 @@ public static function manage_instance($formdata) { // Create template record. $record->reference = shorten_text(strip_tags($record->reference), 30); + $record->timemodified = time(); if (isset($formdata->id) && $DB->record_exists('pulse_autotemplates', ['id' => $formdata->id])) { $templateid = $formdata->id; // Update the template. @@ -433,13 +434,10 @@ public static function update_instance_data($instanceid, $options) { } if ($record = $DB->get_record('pulse_autotemplates_ins', ['instanceid' => $instanceid])) { - $diff = array_diff_key((array) $record, $options); $removeoverrides = array_combine(array_keys($diff), array_fill(0, count($diff), null)); - $removeoverrides['id'] = $record->id; $removeoverrides['instanceid'] = $record->instanceid; - $removeoverrides['timemodified'] = date('Y-m-d H:i'); $removeoverrides = array_merge($removeoverrides, $options); return $DB->update_record('pulse_autotemplates_ins', $removeoverrides); diff --git a/classes/table/auto_templates.php b/classes/table/auto_templates.php index 99fc805..f347644 100644 --- a/classes/table/auto_templates.php +++ b/classes/table/auto_templates.php @@ -48,8 +48,8 @@ class auto_templates extends table_sql { public function out($pagesize, $useinitialsbar, $downloadhelpbutton = '') { // Define table headers and columns. - $columns = ['title', 'templateaction', 'reference', 'actions']; - $headers = ["", "", "", ""]; + $columns = ['title', 'reference', 'actions']; + $headers = ["", "", ""]; $this->define_columns($columns); $this->define_headers($headers); diff --git a/db/install.xml b/db/install.xml index 78cf8b5..c4e1b5e 100644 --- a/db/install.xml +++ b/db/install.xml @@ -93,7 +93,7 @@ - + @@ -105,7 +105,7 @@ - + @@ -123,7 +123,7 @@ - + diff --git a/db/upgrade.php b/db/upgrade.php index cb6f45d..675cd4c 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -120,7 +120,7 @@ function xmldb_pulse_upgrade($oldversion) { $table->add_field('templateid', XMLDB_TYPE_INTEGER, '9', null, XMLDB_NOTNULL, null, null, 'id'); $table->add_field('courseid', XMLDB_TYPE_INTEGER, '9', null, XMLDB_NOTNULL, null, null, 'templateid'); $table->add_field('status', XMLDB_TYPE_INTEGER, '9', null, null, null, '1', 'courseid'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'status'); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null, 'status'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for pulse_autoinstaces. @@ -141,7 +141,7 @@ function xmldb_pulse_upgrade($oldversion) { $table->add_field('categories', XMLDB_TYPE_TEXT, null, null, null, null, null, 'tenants'); $table->add_field('triggerconditions', XMLDB_TYPE_TEXT, null, null, null, null, null, 'categories'); $table->add_field('triggeroperator', XMLDB_TYPE_INTEGER, '9', null, null, null, '1', 'triggerconditions'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'triggeroperator'); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null, 'triggeroperator'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); // Conditionally launch create table for pulse_autotemplates. @@ -162,7 +162,7 @@ function xmldb_pulse_upgrade($oldversion) { $table->add_field('categories', XMLDB_TYPE_TEXT, null, null, null, null, null, 'tenants'); $table->add_field('triggerconditions', XMLDB_TYPE_TEXT, null, null, null, null, null, 'categories'); $table->add_field('triggeroperator', XMLDB_TYPE_INTEGER, '2', null, null, null, null, 'triggerconditions'); - $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'triggeroperator'); + $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null, 'triggeroperator'); $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); $table->add_key('unique', XMLDB_KEY_UNIQUE, array('instanceid')); @@ -198,12 +198,39 @@ function xmldb_pulse_upgrade($oldversion) { $reference = new xmldb_field('reference', XMLDB_TYPE_CHAR, '100', null, null, null, null); // Verify field exists. if ($dbman->field_exists($instable, $reference)) { - // Rename the field. + // Change the field. $dbman->rename_field($instable, $reference, 'insreference'); } upgrade_mod_savepoint(true, 2023051825, 'pulse'); } + if ($oldversion < 2023051830) { + // Auto templates instance. + $instable = new xmldb_table('pulse_autotemplates_ins'); + $timemodified = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '11', null, null, null, null); + // Verify field exists. + if ($dbman->field_exists($instable, $timemodified)) { + // Change the field. + $dbman->change_field_precision($instable, $timemodified); + } + + // Update the templates table timemodified. + $temptable = new xmldb_table('pulse_autotemplates'); + if ($dbman->field_exists($temptable, $timemodified)) { + // Change the field. + $dbman->change_field_precision($temptable, $timemodified); + } + + // Update the pulse_autoinstances table timemodified. + $autoinstable = new xmldb_table('pulse_autoinstances'); + if ($dbman->field_exists($autoinstable, $timemodified)) { + // Change the field. + $dbman->change_field_precision($autoinstable, $timemodified); + } + + upgrade_mod_savepoint(true, 2023051830, 'pulse'); + } + return true; } diff --git a/version.php b/version.php index b98f027..d95d377 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_pulse'; -$plugin->version = 2023051828; +$plugin->version = 2023051830; $plugin->requires = 2020061500; // Requires Moodle 3.90. $plugin->release = 'v2.0'; $plugin->maturity = MATURITY_STABLE;