Skip to content

Commit

Permalink
Technical debt: Remove ousearch - remove ousearch code from mod_oublo…
Browse files Browse the repository at this point in the history
…g #757348
  • Loading branch information
sammarshallou committed May 20, 2024
1 parent eef4f0d commit fd06c3a
Show file tree
Hide file tree
Showing 13 changed files with 1 addition and 566 deletions.
14 changes: 0 additions & 14 deletions allposts.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@
$strolderposts = get_string('olderposts', 'oublog');
$strfeeds = get_string('feeds', 'oublog');

$strblogsearch = get_string('searchblogs', 'oublog');

// Get Posts.
list($posts, $recordcount) = oublog_get_posts($oublog, $context, $offset, $cm, null, -1, null,
$tag, $canaudit, true);
Expand All @@ -109,20 +107,8 @@
$PAGE->navbar->add(get_string('extranavtag', 'oublog', $tag));
}

if (oublog_search_installed()) {
$buttontext=<<<EOF
<form action="search.php" method="get"><div>
<input type="text" name="query" value=""/>
<input type="hidden" name="id" value="{$cm->id}"/>
<input type="submit" value="{$strblogsearch}"/>
</div></form>
EOF;
} else {
$buttontext='';
}
$url = new moodle_url("$CFG->wwwroot/course/mod.php",
array('update' => $cm->id, 'return' => true, 'sesskey' => sesskey()));
$PAGE->set_button($buttontext);

// The right column, BEFORE the middle-column.
if (isloggedin() and !isguestuser()) {
Expand Down
4 changes: 0 additions & 4 deletions deletepost.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ function oublog_do_delete($course, $cm, $oublog, $post) {
array(), $post->visibility)) {
throw new moodle_exception('tagupdatefailed', 'oublog');
}
if (oublog_search_installed() && !local_ousearch_indexingdisabled()) {
$doc = oublog_get_search_document($updatepost, $cm);
$doc->delete();
}
// Inform completion system, if available.
$completion = new completion_info($course);
if ($completion->is_enabled($cm) && ($oublog->completionposts)) {
Expand Down
10 changes: 0 additions & 10 deletions import.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,6 @@ function mod_oublog_import_get_identifier($user): array {
$completion->update_state($cm, COMPLETION_COMPLETE);
}
}
// Update search (add required properties to newpost).
$newpost->id = $newid;
$newpost->userid = $USER->id;
$newpost->tags = array();
if (isset($post->tags)) {
foreach ($post->tags as $tag) {
$newpost->tags[$tag->id] = $tag->tag;
}
}
oublog_search_update($newpost, $cm);
$trans->allow_commit();
$bar->update($cur, count($posts), get_string('import_step2_prog', 'oublog'));
}
Expand Down
1 change: 0 additions & 1 deletion lang/de/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
$string['newcomment'] = 'Neuer Blogkommentar';

$string['searchthisblog'] = 'Dieses Blog suchen';
$string['searchblogs'] = 'Blogs suchen';

$string['url']='Volle Webadresse';

Expand Down
8 changes: 0 additions & 8 deletions lang/en/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@
$string['postmessage'] = 'Post';

$string['searchthisblog'] = 'Search this {$a}';
$string['searchblogs'] = 'Search';
$string['searchblogs_help'] = 'Type your search term and press Enter or click the button.
To search for exact phrases use quote marks.
To exclude a word insert a hyphen immediately before the word.
Example: the search term <tt>picasso -sculpture &quot;early works&quot;</tt> will return results for &lsquo;picasso&rsquo; or the phrase &lsquo;early works&rsquo; but will exclude items containing &lsquo;sculpture&rsquo;.';

$string['url'] = 'Full Web address';

Expand Down
1 change: 0 additions & 1 deletion lang/ja/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
$string['posts'] = '記事';
$string['rss'] = 'RSS';
$string['rssfeed'] = 'RSSフィード';
$string['searchblogs'] = 'ブログを検索する';
$string['searchthisblog'] = 'このブログを検索する';
$string['siteentries'] = 'サイトエントリを表示する';
$string['subscribefeed'] = 'このブログが更新された場合、通知を受け取るには、フィードを購読登録してください (適切なソフトウェアが必要です)。';
Expand Down
1 change: 0 additions & 1 deletion lang/pt_br/oublog.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
$string['re'] = 'Re: {$a}';
$string['rss'] = 'RSS';
$string['rssfeed'] = 'RSS feed';
$string['searchblogs'] = 'Pesquisar nos Blogs';
$string['searchthisblog'] = 'Pesquisar este blog';
$string['separateindividual'] = 'Individual separado';
$string['separateindividualblogs'] = 'Blogs individuais separados';
Expand Down
136 changes: 0 additions & 136 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ function oublog_delete_instance($oublogid) {
throw new moodle_exception('invalidcoursemodule');
}

// Fulltext search data
require_once(dirname(__FILE__).'/locallib.php');
if (oublog_search_installed()) {
local_ousearch_document::delete_module_instance_data($cm);
}

oublog_grade_item_delete($oublog);

Expand Down Expand Up @@ -464,138 +460,6 @@ function oublog_print_recent_mod_activity($activity, $courseid, $detail, $modnam
return;
}


/**
* Obtains a search document given the ousearch parameters.
* @param object $document Object containing fields from the ousearch documents table
* @return mixed False if object can't be found, otherwise object containing the following
* fields: ->content, ->title, ->url, ->activityname, ->activityurl
*/
function oublog_ousearch_get_document($document) {
global $CFG, $DB;
require_once('locallib.php');

// Get data
if (!($cm=$DB->get_record('course_modules', array('id' => $document->coursemoduleid)))) {
return false;
}
if (!($oublog=$DB->get_record('oublog', array('id' => $cm->instance)))) {
return false;
}
if (!($post=$DB->get_record_sql("
SELECT
p.*,bi.userid
FROM
{oublog_posts} p
INNER JOIN {oublog_instances} bi ON p.oubloginstancesid=bi.id
WHERE
p.id= ? ", array($document->intref1)))) {
return false;
}

$result=new StdClass;

// Set up activity name and URL
$result->activityname=$oublog->name;
if ($oublog->global) {
$result->activityurl=$CFG->wwwroot.'/mod/oublog/view.php?user='.
$document->userid;
} else {
$result->activityurl=$CFG->wwwroot.'/mod/oublog/view.php?id='.
$document->coursemoduleid;
}

// Now do the post details
$result->title=$post->title;
$result->content=$post->message;
$result->url=$CFG->wwwroot.'/mod/oublog/viewpost.php?post='.$document->intref1;

// Sort out tags for use as extrastrings
$taglist=oublog_get_post_tags($post, true);
if (count($taglist)!=0) {
$result->extrastrings=$taglist;
}

// Post object is used in filter
$result->data=$post;

return $result;
}

/**
* 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 oublog_ousearch_update_all($feedback=false, $courseid=0) {
global $CFG, $DB;
if (get_config('local_ousearch', 'ousearchindexingdisabled')) {
// Do nothing if the OU Search system is turned off.
return;
}
require_once($CFG->dirroot . '/mod/oublog/locallib.php');

// Get all existing blogs as $cm objects (which we are going to need to
// do the updates). get_records is ok here because we're only taking a
// few fields and there's unlikely to be more than a few thousand blog
// instances [user blogs all use a single course-module]
$coursemodules=$DB->get_records_sql("
SELECT
cm.id,cm.course,cm.instance
FROM
{modules} m
INNER JOIN {course_modules} cm ON m.id=cm.module
WHERE
m.name='oublog'".($courseid ? " AND cm.course= ? " : ""), array($courseid));
if (!$coursemodules) {
$coursemodules = array();
}

// Display info and loop around each coursemodule
if ($feedback) {
print '<li><strong>'.count($coursemodules).'</strong> instances to process.</li>';
$dotcount=0;
}
$posts=0; $instances=0;
foreach ($coursemodules as $coursemodule) {

// Get all the posts that aren't deleted
$rs=$DB->get_recordset_sql("
SELECT
p.id,p.title,p.message,p.groupid,i.userid
FROM
{oublog_instances} i
INNER JOIN {oublog_posts} p ON p.oubloginstancesid=i.id
WHERE
p.deletedby IS NULL AND i.oublogid= ? ", array($coursemodule->instance));

foreach ($rs as $post) {
oublog_search_update($post, $coursemodule);

// Add to count and do user feedback every 100 posts
$posts++;
if ($feedback && ($posts%100)==0) {
if ($dotcount==0) {
print '<li>';
}
print '.';
$dotcount++;
if ($dotcount == 20 || $instances == count($coursemodules)) {
print "done $posts posts ($instances instances)</li>";
$dotcount=0;
}
flush();
}
}
$rs->close();

$instances++;
}
if ($feedback && ($dotcount!=0 || $posts<100)) {
print ($dotcount==0?'<li>':'')."done $posts posts ($instances instances)</li>";
}
}

/**
* Indicates API features that the module supports.
*
Expand Down
Loading

0 comments on commit fd06c3a

Please sign in to comment.