mirror of
https://github.com/moodle/moodle.git
synced 2025-03-20 07:30:01 +01:00
MDL-66694 mod_forum: Updated adhoc task to requeue until completion
The adhoc task run during upgrade will now be requeued until no more word/char counts require updating. Previously it was only run once, so only the first 5000 posts would be updated.
This commit is contained in:
parent
7d8f604b3c
commit
3c36cdb150
@ -39,10 +39,23 @@ class refresh_forum_post_counts extends \core\task\adhoc_task {
|
||||
* Run the task to refresh calendar events.
|
||||
*/
|
||||
public function execute() {
|
||||
global $CFG;
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
||||
|
||||
mod_forum_update_null_forum_post_counts(5000);
|
||||
$recordsfound = mod_forum_update_null_forum_post_counts(5000);
|
||||
|
||||
// Re-queue this adhoc task if records were found during the current run,
|
||||
// since there may be more records to update.
|
||||
if ($recordsfound) {
|
||||
$record = new \stdClass();
|
||||
$record->classname = '\mod_forum\task\refresh_forum_post_counts';
|
||||
$record->component = 'mod_forum';
|
||||
|
||||
// Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
|
||||
$nextruntime = time() - 1;
|
||||
$record->nextruntime = $nextruntime;
|
||||
$DB->insert_record('task_adhoc', $record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6732,7 +6732,7 @@ function mod_forum_user_preferences() {
|
||||
* Updates null forum post counts according to the post message.
|
||||
*
|
||||
* @param int $limit The number of records to update
|
||||
* @return null
|
||||
* @return bool Whether any records were found and updated
|
||||
*/
|
||||
function mod_forum_update_null_forum_post_counts(int $limit) {
|
||||
global $DB;
|
||||
@ -6741,12 +6741,15 @@ function mod_forum_update_null_forum_post_counts(int $limit) {
|
||||
$recordset = $DB->get_recordset_select('forum_posts', $select, null, 'discussion', 'id, message', 0, $limit);
|
||||
if (!$recordset->valid()) {
|
||||
$recordset->close();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($recordset as $record) {
|
||||
$countsupdate = \mod_forum\local\entities\post::add_message_counts($record);
|
||||
$DB->update_record('forum_posts', $countsupdate);
|
||||
}
|
||||
|
||||
$recordset->close();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user