Skip to content

Commit

Permalink
Fixed time modified issue
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 25, 2023
1 parent 0e18e79 commit 83453fd
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 19 deletions.
4 changes: 2 additions & 2 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Expand Down
12 changes: 11 additions & 1 deletion actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion actions/notification/classes/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion actions/notification/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion classes/automation/instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions classes/automation/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions classes/table/auto_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<FIELD NAME="categories" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="triggerconditions" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="triggeroperator" TYPE="int" LENGTH="9" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="id" TYPE="primary" FIELDS="id"/>
Expand All @@ -105,7 +105,7 @@
<FIELD NAME="templateid" TYPE="int" LENGTH="9" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="9" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="status" TYPE="int" LENGTH="9" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="id" TYPE="primary" FIELDS="id"/>
Expand All @@ -123,7 +123,7 @@
<FIELD NAME="categories" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="triggerconditions" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="triggeroperator" TYPE="int" LENGTH="2" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="11" NOTNULL="false" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="id" TYPE="primary" FIELDS="id"/>
Expand Down
35 changes: 31 additions & 4 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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'));

Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 83453fd

Please sign in to comment.