Merge branch 'MDL-50265-master' of git://github.com/danpoltawski/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2017-06-06 19:27:59 +02:00
commit 6fff2a911a
3 changed files with 24 additions and 353 deletions

View file

@ -2152,347 +2152,87 @@ function get_timezone_record($timezonename) {
/* === Apis deprecated since Moodle 3.0 === */
/**
* Returns the URL of the HTTP_REFERER, less the querystring portion if required.
*
* @deprecated since Moodle 3.0 MDL-49360 - please do not use this function any more.
* @todo MDL-50265 Remove this function in Moodle 3.4.
* @param boolean $stripquery if true, also removes the query part of the url.
* @return string The resulting referer or empty string.
*/
function get_referer($stripquery = true) {
debugging('get_referer() is deprecated. Please use get_local_referer() instead.', DEBUG_DEVELOPER);
if (isset($_SERVER['HTTP_REFERER'])) {
if ($stripquery) {
return strip_querystring($_SERVER['HTTP_REFERER']);
} else {
return $_SERVER['HTTP_REFERER'];
}
} else {
return '';
}
throw new coding_exception('get_referer() can not be used any more. Please use get_local_referer() instead.');
}
/**
* Checks if current user is a web crawler.
*
* This list can not be made complete, this is not a security
* restriction, we make the list only to help these sites
* especially when automatic guest login is disabled.
*
* If admin needs security they should enable forcelogin
* and disable guest access!!
*
* @return bool
* @deprecated since Moodle 3.0 use \core_useragent::is_web_crawler instead.
*/
function is_web_crawler() {
debugging('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.', DEBUG_DEVELOPER);
return core_useragent::is_web_crawler();
throw new coding_exception('is_web_crawler() can not be used any more. Please use core_useragent::is_web_crawler() instead.');
}
/**
* Update user's course completion statuses
*
* First update all criteria completions, then aggregate all criteria completions
* and update overall course completions.
*
* @deprecated since Moodle 3.0 MDL-50287 - please do not use this function any more.
* @todo Remove this function in Moodle 3.2 MDL-51226.
*/
function completion_cron() {
global $CFG;
require_once($CFG->dirroot.'/completion/cron.php');
debugging('completion_cron() is deprecated. Functionality has been moved to scheduled tasks.', DEBUG_DEVELOPER);
completion_cron_mark_started();
completion_cron_criteria();
completion_cron_completions();
throw new coding_exception('completion_cron() can not be used any more. Functionality has been moved to scheduled tasks.');
}
/**
* Returns an ordered array of tags associated with visible courses
* (boosted replacement of get_all_tags() allowing association with user and tagtype).
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param int $courseid A course id. Passing 0 will return all distinct tags for all visible courses
* @param int $userid (optional) the user id, a default of 0 will return all users tags for the course
* @param string $tagtype (optional) The type of tag, empty string returns all types. Currently (Moodle 2.2) there are two
* types of tags which are used within Moodle, they are 'official' and 'default'.
* @param int $numtags (optional) number of tags to display, default of 80 is set in the block, 0 returns all
* @param string $unused (optional) was selected sorting, moved to tag_print_cloud()
* @return array
*/
function coursetag_get_tags($courseid, $userid=0, $tagtype='', $numtags=0, $unused = '') {
debugging('Function coursetag_get_tags() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
global $CFG, $DB;
// get visible course ids
$courselist = array();
if ($courseid === 0) {
if ($courses = $DB->get_records_select('course', 'visible=1 AND category>0', null, '', 'id')) {
foreach ($courses as $key => $value) {
$courselist[] = $key;
}
}
}
// get tags from the db ordered by highest count first
$params = array();
$sql = "SELECT id as tkey, name, id, isstandard, rawname, f.timemodified, flag, count
FROM {tag} t,
(SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
FROM {tag_instance}
WHERE itemtype = 'course' ";
if ($courseid > 0) {
$sql .= " AND itemid = :courseid ";
$params['courseid'] = $courseid;
} else {
if (!empty($courselist)) {
list($usql, $uparams) = $DB->get_in_or_equal($courselist, SQL_PARAMS_NAMED);
$sql .= "AND itemid $usql ";
$params = $params + $uparams;
}
}
if ($userid > 0) {
$sql .= " AND tiuserid = :userid ";
$params['userid'] = $userid;
}
$sql .= " GROUP BY tagid) f
WHERE t.id = f.tagid ";
if ($tagtype != '') {
$sql .= "AND isstandard = :isstandard ";
$params['isstandard'] = ($tagtype === 'official') ? 1 : 0;
}
$sql .= "ORDER BY count DESC, name ASC";
// limit the number of tags for output
if ($numtags == 0) {
$tags = $DB->get_records_sql($sql, $params);
} else {
$tags = $DB->get_records_sql($sql, $params, 0, $numtags);
}
// prepare the return
$return = array();
if ($tags) {
// avoid print_tag_cloud()'s ksort upsetting ordering by setting the key here
foreach ($tags as $value) {
$return[] = $value;
}
}
return $return;
throw new coding_exception('Function coursetag_get_tags() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Returns an ordered array of tags
* (replaces popular_tags_count() allowing sorting).
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param string $unused (optional) was selected sorting - moved to tag_print_cloud()
* @param int $numtags (optional) number of tags to display, default of 20 is set in the block, 0 returns all
* @return array
*/
function coursetag_get_all_tags($unused='', $numtags=0) {
debugging('Function coursetag_get_all_tag() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
global $CFG, $DB;
// note that this selects all tags except for courses that are not visible
$sql = "SELECT id, name, isstandard, rawname, f.timemodified, flag, count
FROM {tag} t,
(SELECT tagid, MAX(timemodified) as timemodified, COUNT(id) as count
FROM {tag_instance} WHERE tagid NOT IN
(SELECT tagid FROM {tag_instance} ti, {course} c
WHERE c.visible = 0
AND ti.itemtype = 'course'
AND ti.itemid = c.id)
GROUP BY tagid) f
WHERE t.id = f.tagid
ORDER BY count DESC, name ASC";
if ($numtags == 0) {
$tags = $DB->get_records_sql($sql);
} else {
$tags = $DB->get_records_sql($sql, null, 0, $numtags);
}
$return = array();
if ($tags) {
foreach ($tags as $value) {
$return[] = $value;
}
}
return $return;
throw new coding_exception('Function coursetag_get_all_tag() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Returns javascript for use in tags block and supporting pages
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @return null
*/
function coursetag_get_jscript() {
debugging('Function coursetag_get_jscript() is deprecated and obsolete.', DEBUG_DEVELOPER);
return '';
throw new coding_exception('Function coursetag_get_jscript() can not be used any more and is obsolete.');
}
/**
* Returns javascript to create the links in the tag block footer.
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param string $elementid the element to attach the footer to
* @param array $coursetagslinks links arrays each consisting of 'title', 'onclick' and 'text' elements
* @return string always returns a blank string
*/
function coursetag_get_jscript_links($elementid, $coursetagslinks) {
debugging('Function coursetag_get_jscript_links() is deprecated and obsolete.', DEBUG_DEVELOPER);
return '';
throw new coding_exception('Function coursetag_get_jscript_links() can not be used any more and is obsolete.');
}
/**
* Returns all tags created by a user for a course
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param int $courseid tags are returned for the course that has this courseid
* @param int $userid return tags which were created by this user
*/
function coursetag_get_records($courseid, $userid) {
debugging('Function coursetag_get_records() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
global $CFG, $DB;
$sql = "SELECT t.id, name, rawname
FROM {tag} t, {tag_instance} ti
WHERE t.id = ti.tagid
AND ti.tiuserid = :userid
AND ti.itemid = :courseid
ORDER BY name ASC";
return $DB->get_records_sql($sql, array('userid'=>$userid, 'courseid'=>$courseid));
throw new coding_exception('Function coursetag_get_records() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Stores a tag for a course for a user
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param array $tags simple array of keywords to be stored
* @param int $courseid the id of the course we wish to store a tag for
* @param int $userid the id of the user we wish to store a tag for
* @param string $tagtype official or default only
* @param string $myurl (optional) for logging creation of course tags
*/
function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='official', $myurl='') {
debugging('Function coursetag_store_keywords() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
global $CFG;
if (is_array($tags) and !empty($tags)) {
if ($tagtype === 'official') {
$tagcoll = core_tag_area::get_collection('core', 'course');
// We don't normally need to create tags, they are created automatically when added to items. but we do here because we want them to be official.
core_tag_tag::create_if_missing($tagcoll, $tags, true);
}
foreach ($tags as $tag) {
$tag = trim($tag);
if (strlen($tag) > 0) {
core_tag_tag::add_item_tag('core', 'course', $courseid, context_course::instance($courseid), $tag, $userid);
}
}
}
throw new coding_exception('Function coursetag_store_keywords() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Deletes a personal tag for a user for a course.
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param int $tagid the tag we wish to delete
* @param int $userid the user that the tag is associated with
* @param int $courseid the course that the tag is associated with
*/
function coursetag_delete_keyword($tagid, $userid, $courseid) {
debugging('Function coursetag_delete_keyword() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
$tag = core_tag_tag::get($tagid);
core_tag_tag::remove_item_tag('core', 'course', $courseid, $tag->rawname, $userid);
throw new coding_exception('Function coursetag_delete_keyword() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Get courses tagged with a tag
*
* @deprecated since 3.0
* @package core_tag
* @category tag
* @param int $tagid
* @return array of course objects
*/
function coursetag_get_tagged_courses($tagid) {
debugging('Function coursetag_get_tagged_courses() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
global $DB;
$courses = array();
$ctxselect = context_helper::get_preload_record_columns_sql('ctx');
$sql = "SELECT c.*, $ctxselect
FROM {course} c
JOIN {tag_instance} t ON t.itemid = c.id
JOIN {context} ctx ON ctx.instanceid = c.id
WHERE t.tagid = :tagid AND
t.itemtype = 'course' AND
ctx.contextlevel = :contextlevel
ORDER BY c.sortorder ASC";
$params = array('tagid' => $tagid, 'contextlevel' => CONTEXT_COURSE);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $course) {
context_helper::preload_from_record($course);
if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
$courses[$course->id] = $course;
}
}
return $courses;
throw new coding_exception('Function coursetag_get_tagged_courses() can not be used any more. Userid is no longer used for tagging courses.');
}
/**
* Course tagging function used only during the deletion of a course (called by lib/moodlelib.php) to clean up associated tags
*
* @package core_tag
* @deprecated since 3.0
* @param int $courseid the course we wish to delete tag instances from
* @param bool $showfeedback if we should output a notification of the delete to the end user
*/
function coursetag_delete_course_tags($courseid, $showfeedback=false) {
debugging('Function coursetag_delete_course_tags() is deprecated. Use core_tag_tag::remove_all_item_tags().', DEBUG_DEVELOPER);
global $OUTPUT;
core_tag_tag::remove_all_item_tags('core', 'course', $courseid);
if ($showfeedback) {
echo $OUTPUT->notification(get_string('deletedcoursetags', 'tag'), 'notifysuccess');
}
throw new coding_exception('Function coursetag_delete_course_tags() is deprecated. Use core_tag_tag::remove_all_item_tags().');
}
/**

View file

@ -1887,61 +1887,4 @@ class core_useragent_testcase extends advanced_testcase {
$expectation = isset($tests['is_web_crawler']) ? $tests['is_web_crawler'] : false;
$this->assertSame($expectation, core_useragent::is_web_crawler());
}
/**
* Regression tests for the deprecated is_web_crawler() function
*/
public function test_deprecated_is_web_crawler() {
$browsers = array(
'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:18.0) Gecko/18.0 Firefox/18.0',
'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10',
'Opera/9.0 (Windows NT 5.1; U; en)',
'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 Nexus',
'Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5',
);
$crawlers = array(
// Google.
'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
'Googlebot/2.1 (+http://www.googlebot.com/bot.html)',
'Googlebot-Image/1.0',
// Yahoo.
'Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)',
// Bing.
'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
'Mozilla/5.0 (compatible; bingbot/2.0 +http://www.bing.com/bingbot.htm)',
// MSN.
'msnbot/2.1',
// Yandex.
'Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)',
'Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)',
// AltaVista.
'AltaVista V2.0B crawler@evreka.com',
// ZoomSpider.
'ZoomSpider - wrensoft.com [ZSEBOT]',
// Baidu.
'Baiduspider+(+http://www.baidu.com/search/spider_jp.html)',
'Baiduspider+(+http://www.baidu.com/search/spider.htm)',
'BaiDuSpider',
// Ask.com.
'User-Agent: Mozilla/2.0 (compatible; Ask Jeeves/Teoma)',
);
foreach ($browsers as $agent) {
core_useragent::instance(true, $agent);
$this->assertSame($agent, core_useragent::get_user_agent_string());
$this->assertFalse(is_web_crawler());
$this->assertDebuggingCalled('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.',
DEBUG_DEVELOPER);
}
foreach ($crawlers as $agent) {
core_useragent::instance(true, $agent);
$this->assertSame($agent, core_useragent::get_user_agent_string());
$this->assertTrue(is_web_crawler(), "$agent should be considered a search engine");
$this->assertDebuggingCalled('is_web_crawler() has been deprecated, please use core_useragent::is_web_crawler() instead.',
DEBUG_DEVELOPER);
}
}
}

View file

@ -163,13 +163,11 @@ class core_tag_events_testcase extends advanced_testcase {
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to a course.
tag_assign('course', $course->id, $tag->id, 1, 2, 'core', context_course::instance($course->id)->id);
$this->assertDebuggingCalled();
core_tag_tag::add_item_tag('core', 'course', $course->id, context_course::instance($course->id), $tag->rawname);
// Trigger and capture the event for untagging a course.
$sink = $this->redirectEvents();
coursetag_delete_keyword($tag->id, 2, $course->id);
$this->assertDebuggingCalled();
core_tag_tag::remove_item_tag('core', 'course', $course->id, $tag->rawname);
$events = $sink->get_events();
$event = reset($events);
@ -182,13 +180,11 @@ class core_tag_events_testcase extends advanced_testcase {
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to a wiki this time.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
$this->assertDebuggingCalled();
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $wikipageid, context_module::instance($wiki->cmid), $tag->rawname);
// Trigger and capture the event for deleting this tag instance.
$sink = $this->redirectEvents();
tag_delete_instance('wiki_pages', $wikipageid, $tag->id);
$this->assertDebuggingCalled();
core_tag_tag::remove_item_tag('mod_wiki', 'wiki_pages', $wikipageid, $tag->rawname);
$events = $sink->get_events();
$event = reset($events);
@ -201,14 +197,12 @@ class core_tag_events_testcase extends advanced_testcase {
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to the wiki again.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
$this->assertDebuggingCalled();
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $wikipageid, context_module::instance($wiki->cmid), $tag->rawname);
// Now we want to delete this tag, and because there is only one tag instance
// associated with it, it should get deleted as well.
$sink = $this->redirectEvents();
tag_delete($tag->id);
$this->assertDebuggingCalled();
core_tag_tag::delete_tags($tag->id);
$events = $sink->get_events();
$event = reset($events);
@ -221,8 +215,7 @@ class core_tag_events_testcase extends advanced_testcase {
$tag = $this->getDataGenerator()->create_tag();
// Assign a tag to the wiki again.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
$this->assertDebuggingCalled();
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $wikipageid, context_module::instance($wiki->cmid), $tag->rawname);
// Delete all tag instances for this wiki instance.
$sink = $this->redirectEvents();
@ -241,10 +234,8 @@ class core_tag_events_testcase extends advanced_testcase {
$wikipageid2 = wiki_create_page($subwikiid2, 'Title', FORMAT_HTML, '2');
// Assign a tag to both wiki pages.
tag_assign('wiki_pages', $wikipageid, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki->cmid)->id);
$this->assertDebuggingCalled();
tag_assign('wiki_pages', $wikipageid2, $tag->id, 1, 2, 'mod_wiki', context_module::instance($wiki2->cmid)->id);
$this->assertDebuggingCalled();
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $wikipageid, context_module::instance($wiki->cmid), $tag->rawname);
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $wikipageid2, context_module::instance($wiki2->cmid), $tag->rawname);
// Now remove all tag_instances associated with all wikis.
$sink = $this->redirectEvents();
@ -495,8 +486,7 @@ class core_tag_events_testcase extends advanced_testcase {
// Trigger and capture the event for deleting a personal tag for a user for a course.
$sink = $this->redirectEvents();
coursetag_delete_keyword($tag->id, 2, $course->id);
$this->assertDebuggingCalled();
core_tag_tag::remove_item_tag('core', 'course', $course->id, $tag->rawname);
$events = $sink->get_events();
$event = $events[1];
@ -514,8 +504,7 @@ class core_tag_events_testcase extends advanced_testcase {
// Trigger and capture the event for deleting all tags in a course.
$sink = $this->redirectEvents();
coursetag_delete_course_tags($course->id);
$this->assertDebuggingCalled();
core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
$events = $sink->get_events();
$event = $events[1];
@ -536,8 +525,7 @@ class core_tag_events_testcase extends advanced_testcase {
// Trigger and capture the event for deleting all tags in a course.
$sink = $this->redirectEvents();
coursetag_delete_course_tags($course->id);
$this->assertDebuggingCalled();
core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
$events = $sink->get_events();
$events = array($events[1], $events[3]);