protected function after_execute() { global $DB, $CFG; // Add forumng related files, no need to match by // itemname (just internally handled context) $this->add_related_files('mod_forumng', 'intro', null); // Add post related files, matching by itemname = 'forumng_post' $this->add_related_files('mod_forumng', 'message', 'forumng_post'); $this->add_related_files('mod_forumng', 'attachment', 'forumng_post'); $this->add_related_files('mod_forumng', 'draft', 'forumng_draft'); // Now fix the lastpostid for each discussion // TODO Does this work on MySQL? No idea. $DB->execute("\nUPDATE {forumng_discussions} SET lastpostid=(\n SELECT\n MAX(id)\n FROM\n {forumng_posts} fp\n WHERE\n fp.discussionid = {forumng_discussions}.id\n AND fp.oldversion=0\n AND fp.deleted=0\n) WHERE forumngid = ?", array($this->forumngid)); require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php'; // Create search index if user data restored. if ($this->get_setting_value('userinfo') && mod_forumng::search_installed()) { mod_forumng::search_update_all(false, $this->get_courseid(), $this->task->get_moduleid()); } }
/** * Update all documents for ousearch. * @param bool $feedback If true, prints feedback as HTML list items * @param int $courseid If specified, restricts to particular courseid */ function forumng_ousearch_update_all($feedback = false, $courseid = 0) { require_once dirname(__FILE__) . '/mod_forumng.php'; mod_forumng::search_update_all($feedback, $courseid); }
// 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/>. /** * This script is for use only temporarily to respond to a glitch in the * forum -> ForumNG conversion script where it didn't build search indexes. * This file lets the search index be manually rebuilt. We should probably * delete it later. * @package mod * @subpackage forumng * @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once '../../config.php'; require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php'; $cmid = required_param('id', PARAM_INT); $cloneid = optional_param('clone', 0, PARAM_INT); $forum = mod_forumng::get_from_cmid($cmid, $cloneid); $cm = $forum->get_course_module(); require_login($cm->course, false, $cm); require_capability('moodle/restore:restoreactivity', $cm->context); mod_forumng::search_installed(); $PAGE->set_url('/mod/forumng/rebuildsearchindex.php', array('id' => $cmid, 'clone' => $cloneid)); // This script is not very user friendly. Once it finishes, it's done... echo $OUTPUT->header(); mod_forumng::search_update_all(true, $cm->course, $cm->id); echo $OUTPUT->footer();
protected function after_execute() { global $DB, $CFG; // Add forumng related files, no need to match by // itemname (just internally handled context) $this->add_related_files('mod_forumng', 'intro', null); // Add post related files, matching by itemname = 'forumng_post' $this->add_related_files('mod_forumng', 'message', 'forumng_post'); $this->add_related_files('mod_forumng', 'attachment', 'forumng_post'); $this->add_related_files('mod_forumng', 'draft', 'forumng_draft'); // Now fix the lastpostid for each discussion // TODO Does this work on MySQL? No idea. $DB->execute("\nUPDATE {forumng_discussions} SET lastpostid=(\n SELECT\n MAX(id)\n FROM\n {forumng_posts} fp\n WHERE\n fp.discussionid = {forumng_discussions}.id\n AND fp.oldversion=0\n AND fp.deleted=0\n) WHERE forumngid = ?", array($this->forumngid)); require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php'; // Create search index if user data restored. if ($this->get_setting_value('userinfo') && mod_forumng::search_installed()) { mod_forumng::search_update_all(false, $this->get_courseid(), $this->task->get_moduleid(), $this->get_task()->get_progress()); } // See what $this->task->get_moduleid() contains, then check master|clone. // If we have the module id we can use that to get the cm. if ($cmid = $this->task->get_moduleid()) { // Check to see whether forum is shared or a clone. if ($this->shared) { // Master. // Get the ID number - probably from the course_modules table using $this->task->get_moduleid() in a query. $cm = $DB->get_record('course_modules', array('id' => $cmid), '*', MUST_EXIST); $idnumber = $cm->idnumber; // Check for any other forumng module instances using the same ID number - . // if any then add _1 to end (if already has _number at end then increment that number e.g. _2). $newidnumber = $this->get_new_idnumber($idnumber); // Set new idnumber. $cm->idnumber = $newidnumber; $DB->update_record('course_modules', $cm); } else { if ($this->type === 'clone') { // Clone. $cm = $DB->get_record('course_modules', array('id' => $cmid), '*', MUST_EXIST); $forumng = $DB->get_record('forumng', array('id' => $cm->instance), '*', MUST_EXIST); // If clone get original cmid ID number, if exists and has AUTO_ prefix, // If exists and has AUTO_ prefix. if (!empty($forumng->originalcmid)) { $originalcm = $DB->get_record_sql('select * from {course_modules} where module = (select id from {modules} where name = ?) and id = ?', array('forumng', $forumng->originalcmid)); $strippedidnumber = $originalcm->idnumber; // If exists and has AUTO_ prefix. $idnumber = $this->strip_auto_from_idnumber($originalcm->idnumber); if ($idnumber != $originalcm->idnumber) { $strippedidnumber = $idnumber; // We have an AUTO_ prefix. // Do we have a valid suffix. $suffix = $this->get_possible_suffix($originalcm->idnumber, '_'); if ($suffix != 0) { // We have a valid suffix. // Remove the suffix from the idnumber by getting the last '_' . $strippedidnumber = $this->remove_suffix($idnumber, '_'); } // Place auto back in. $strippedidnumber = 'AUTO_' . $strippedidnumber; // Get cmid for all forumng module instances (joining to forumng table to ensure we get only master forums) // that have matching idnumber (regardless of their _number suffix). $cms = $DB->get_records_sql('select cm.id as cmid, cm.idnumber from {course_modules} cm inner join {forumng} f on cm.instance = f.id where cm.idnumber like ? and f.shared = ? and cm.module = (select id from {modules} where name = ?) order by cmid desc', array($strippedidnumber . '%', 1, 'forumng')); // Set originalcmid field. $forumng->originalcmid = $this->get_cmid_for_forumng_idnumbers($strippedidnumber, $cms); if ($forumng->originalcmid) { $DB->update_record('forumng', $forumng); } } } } } } if (!empty($this->grouptags)) { foreach ($this->grouptags as $groupid => $tags) { mod_forumng::set_group_tags($this->forumngid, $groupid, $tags); } } }