mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-66694 mod_forum: Upgrade forum post word and char counts
This commit is contained in:
parent
3eb0a82fef
commit
7d8f604b3c
48
mod/forum/classes/task/refresh_forum_post_counts.php
Normal file
48
mod/forum/classes/task/refresh_forum_post_counts.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Adhoc task that updates all of the existing forum_post records with no wordcount or no charcount.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2019 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_forum\task;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Adhoc task that updates all of the existing forum_post records with no wordcount or no charcount.
|
||||
*
|
||||
* @package mod_forum
|
||||
* @copyright 2019 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class refresh_forum_post_counts extends \core\task\adhoc_task {
|
||||
|
||||
/**
|
||||
* Run the task to refresh calendar events.
|
||||
*/
|
||||
public function execute() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/mod/forum/lib.php');
|
||||
|
||||
mod_forum_update_null_forum_post_counts(5000);
|
||||
}
|
||||
}
|
@ -181,5 +181,20 @@ function xmldb_forum_upgrade($oldversion) {
|
||||
upgrade_mod_savepoint(true, 2019071901, 'forum');
|
||||
}
|
||||
|
||||
if ($oldversion < 2019071902) {
|
||||
// Create adhoc task for upgrading of existing forum_posts.
|
||||
$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);
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2019071902, 'forum');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -6727,3 +6727,26 @@ function mod_forum_user_preferences() {
|
||||
|
||||
return $preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates null forum post counts according to the post message.
|
||||
*
|
||||
* @param int $limit The number of records to update
|
||||
* @return null
|
||||
*/
|
||||
function mod_forum_update_null_forum_post_counts(int $limit) {
|
||||
global $DB;
|
||||
|
||||
$select = 'wordcount IS NULL OR charcount IS NULL';
|
||||
$recordset = $DB->get_recordset_select('forum_posts', $select, null, 'discussion', 'id, message', 0, $limit);
|
||||
if (!$recordset->valid()) {
|
||||
$recordset->close();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($recordset as $record) {
|
||||
$countsupdate = \mod_forum\local\entities\post::add_message_counts($record);
|
||||
$DB->update_record('forum_posts', $countsupdate);
|
||||
}
|
||||
$recordset->close();
|
||||
}
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2019071901; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2019071902; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2019051100; // Requires this Moodle version
|
||||
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
|
Loading…
x
Reference in New Issue
Block a user