mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-60855 general: Phase 2 in lib/deprecatedlib.php for 3.5 deprecations
This commit is contained in:
parent
6aacd8d6d1
commit
2ead888f45
@ -2620,228 +2620,69 @@ function allow_switch() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Organise categories into a single parent category (called the 'Top' category) per context.
|
||||
*
|
||||
* @param array $categories List of question categories in the format of ["$categoryid,$contextid" => $category].
|
||||
* @param array $pcontexts List of context ids.
|
||||
* @return array
|
||||
* @deprecated since Moodle 3.5. MDL-61132
|
||||
*/
|
||||
function question_add_tops($categories, $pcontexts) {
|
||||
debugging('question_add_tops() has been deprecated. You may want to pass $top = true to get_categories_for_contexts().',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
$topcats = array();
|
||||
foreach ($pcontexts as $contextid) {
|
||||
$topcat = question_get_top_category($contextid, true);
|
||||
$context = context::instance_by_id($contextid);
|
||||
|
||||
$newcat = new stdClass();
|
||||
$newcat->id = "{$topcat->id},$contextid";
|
||||
$newcat->name = get_string('topfor', 'question', $context->get_context_name(false));
|
||||
$newcat->parent = 0;
|
||||
$newcat->contextid = $contextid;
|
||||
$topcats["{$topcat->id},$contextid"] = $newcat;
|
||||
}
|
||||
// Put topcats in at beginning of array - they'll be sorted into different contexts later.
|
||||
return array_merge($topcats, $categories);
|
||||
function question_add_tops() {
|
||||
throw new coding_exception(
|
||||
'question_add_tops() has been removed. You may want to pass $top = true to get_categories_for_contexts().'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the question category is the highest-level category in the context that can be edited, and has no siblings.
|
||||
*
|
||||
* @param int $categoryid a category id.
|
||||
* @return bool
|
||||
* @deprecated since Moodle 3.5. MDL-61132
|
||||
*/
|
||||
function question_is_only_toplevel_category_in_context($categoryid) {
|
||||
debugging('question_is_only_toplevel_category_in_context() has been deprecated. '
|
||||
. 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
return question_is_only_child_of_top_category_in_context($categoryid);
|
||||
function question_is_only_toplevel_category_in_context() {
|
||||
throw new coding_exception('question_is_only_toplevel_category_in_context() has been removed. '
|
||||
. 'Please update your code to use question_is_only_child_of_top_category_in_context() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves messages from a particular user from the message table (unread messages) to message_read
|
||||
* This is typically only used when a user is deleted
|
||||
*
|
||||
* @param object $userid User id
|
||||
* @return boolean success
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_move_userfrom_unread2read($userid) {
|
||||
debugging('message_move_userfrom_unread2read() is deprecated and is no longer used.', DEBUG_DEVELOPER);
|
||||
|
||||
global $DB;
|
||||
|
||||
// Move all unread messages from message table to message_read.
|
||||
if ($messages = $DB->get_records_select('message', 'useridfrom = ?', array($userid), 'timecreated')) {
|
||||
foreach ($messages as $message) {
|
||||
message_mark_message_read($message, 0); // Set timeread to 0 as the message was never read.
|
||||
}
|
||||
}
|
||||
return true;
|
||||
function message_move_userfrom_unread2read() {
|
||||
throw new coding_exception('message_move_userfrom_unread2read() has been removed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve users blocked by $user1
|
||||
*
|
||||
* @param object $user1 the user whose messages are being viewed
|
||||
* @param object $user2 the user $user1 is talking to. If they are being blocked
|
||||
* they will have a variable called 'isblocked' added to their user object
|
||||
* @return array the users blocked by $user1
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_get_blocked_users($user1=null, $user2=null) {
|
||||
debugging('message_get_blocked_users() is deprecated, please use \core_message\api::get_blocked_users() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
global $USER;
|
||||
|
||||
if (empty($user1)) {
|
||||
$user1 = new stdClass();
|
||||
$user1->id = $USER->id;
|
||||
}
|
||||
|
||||
return \core_message\api::get_blocked_users($user1->id);
|
||||
function message_get_blocked_users() {
|
||||
throw new coding_exception(
|
||||
'message_get_blocked_users() has been removed, please use \core_message\api::get_blocked_users() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve $user1's contacts (online, offline and strangers)
|
||||
*
|
||||
* @param object $user1 the user whose messages are being viewed
|
||||
* @param object $user2 the user $user1 is talking to. If they are a contact
|
||||
* they will have a variable called 'iscontact' added to their user object
|
||||
* @return array containing 3 arrays. array($onlinecontacts, $offlinecontacts, $strangers)
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_get_contacts($user1=null, $user2=null) {
|
||||
debugging('message_get_contacts() is deprecated and is no longer used.', DEBUG_DEVELOPER);
|
||||
|
||||
global $DB, $CFG, $USER;
|
||||
|
||||
if (empty($user1)) {
|
||||
$user1 = $USER;
|
||||
}
|
||||
|
||||
if (!empty($user2)) {
|
||||
$user2->iscontact = false;
|
||||
}
|
||||
|
||||
$timetoshowusers = 300; // Seconds default.
|
||||
if (isset($CFG->block_online_users_timetosee)) {
|
||||
$timetoshowusers = $CFG->block_online_users_timetosee * 60;
|
||||
}
|
||||
|
||||
// Rime which a user is counting as being active since.
|
||||
$timefrom = time() - $timetoshowusers;
|
||||
|
||||
// People in our contactlist who are online.
|
||||
$onlinecontacts = array();
|
||||
// People in our contactlist who are offline.
|
||||
$offlinecontacts = array();
|
||||
// People who are not in our contactlist but have sent us a message.
|
||||
$strangers = array();
|
||||
|
||||
// Get all in our contact list who are not blocked in our and count messages we have waiting from each of them.
|
||||
$rs = \core_message\api::get_contacts_with_unread_message_count($user1->id);
|
||||
foreach ($rs as $rd) {
|
||||
if ($rd->lastaccess >= $timefrom) {
|
||||
// They have been active recently, so are counted online.
|
||||
$onlinecontacts[] = $rd;
|
||||
|
||||
} else {
|
||||
$offlinecontacts[] = $rd;
|
||||
}
|
||||
|
||||
if (!empty($user2) && $user2->id == $rd->id) {
|
||||
$user2->iscontact = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Get messages from anyone who isn't in our contact list and count the number of messages we have from each of them.
|
||||
$rs = \core_message\api::get_non_contacts_with_unread_message_count($user1->id);
|
||||
// Add user id as array index, so supportuser and noreply user don't get duplicated (if they are real users).
|
||||
foreach ($rs as $rd) {
|
||||
$strangers[$rd->id] = $rd;
|
||||
}
|
||||
|
||||
// Add noreply user and support user to the list, if they don't exist.
|
||||
$supportuser = core_user::get_support_user();
|
||||
if (!isset($strangers[$supportuser->id]) && !$supportuser->deleted) {
|
||||
$supportuser->messagecount = message_count_unread_messages($USER, $supportuser);
|
||||
if ($supportuser->messagecount > 0) {
|
||||
$strangers[$supportuser->id] = $supportuser;
|
||||
}
|
||||
}
|
||||
|
||||
$noreplyuser = core_user::get_noreply_user();
|
||||
if (!isset($strangers[$noreplyuser->id]) && !$noreplyuser->deleted) {
|
||||
$noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser);
|
||||
if ($noreplyuser->messagecount > 0) {
|
||||
$strangers[$noreplyuser->id] = $noreplyuser;
|
||||
}
|
||||
}
|
||||
|
||||
return array($onlinecontacts, $offlinecontacts, $strangers);
|
||||
function message_get_contacts() {
|
||||
throw new coding_exception('message_get_contacts() has been removed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a single message as read
|
||||
*
|
||||
* @param stdClass $message An object with an object property ie $message->id which is an id in the message table
|
||||
* @param int $timeread the timestamp for when the message should be marked read. Usually time().
|
||||
* @param bool $messageworkingempty Is the message_working table already confirmed empty for this message?
|
||||
* @return int the ID of the message in the messags table
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_mark_message_read($message, $timeread, $messageworkingempty=false) {
|
||||
debugging('message_mark_message_read() is deprecated, please use \core_message\api::mark_message_as_read()
|
||||
or \core_message\api::mark_notification_as_read().', DEBUG_DEVELOPER);
|
||||
|
||||
if (!empty($message->notification)) {
|
||||
\core_message\api::mark_notification_as_read($message, $timeread);
|
||||
} else {
|
||||
\core_message\api::mark_message_as_read($message->useridto, $message, $timeread);
|
||||
}
|
||||
|
||||
return $message->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a user can delete a message.
|
||||
*
|
||||
* @param stdClass $message the message to delete
|
||||
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
|
||||
* but will still seem as if it was by the user)
|
||||
* @return bool Returns true if a user can delete the message, false otherwise.
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_can_delete_message($message, $userid) {
|
||||
debugging('message_can_delete_message() is deprecated, please use \core_message\api::can_delete_message() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
|
||||
return \core_message\api::can_delete_message($userid, $message->id);
|
||||
function message_mark_message_read() {
|
||||
throw new coding_exception('message_mark_message_read() has been removed, please use \core_message\api::mark_message_as_read()
|
||||
or \core_message\api::mark_notification_as_read().');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a message.
|
||||
*
|
||||
* This function does not verify any permissions.
|
||||
*
|
||||
* @param stdClass $message the message to delete
|
||||
* @param string $userid the user id of who we want to delete the message for (this may be done by the admin
|
||||
* but will still seem as if it was by the user)
|
||||
* @return bool
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_delete_message($message, $userid) {
|
||||
debugging('message_delete_message() is deprecated, please use \core_message\api::delete_message() instead.',
|
||||
DEBUG_DEVELOPER);
|
||||
function message_can_delete_message() {
|
||||
throw new coding_exception(
|
||||
'message_can_delete_message() has been removed, please use \core_message\api::can_delete_message() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
return \core_message\api::delete_message($userid, $message->id);
|
||||
/**
|
||||
* @deprecated since Moodle 3.5
|
||||
*/
|
||||
function message_delete_message() {
|
||||
throw new coding_exception(
|
||||
'message_delete_message() has been removed, please use \core_message\api::delete_message() instead.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,11 @@
|
||||
This files describes API changes in core libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.9 ===
|
||||
* Removed the following depecated functions:
|
||||
- question_add_tops
|
||||
- question_is_only_toplevel_category_in_context
|
||||
|
||||
=== 3.8 ===
|
||||
* Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop
|
||||
* The rotate_image function has been added to the stored_file class (MDL-63349)
|
||||
|
@ -122,101 +122,23 @@ class core_message_messagelib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_get_blocked_users.
|
||||
* Test message_get_blocked_users throws an exception because has been removed.
|
||||
*/
|
||||
public function test_message_get_blocked_users() {
|
||||
global $USER;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
\core_message\api::block_user($USER->id, $user2->id);
|
||||
|
||||
$this->assertCount(1, message_get_blocked_users());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Block other user.
|
||||
\core_message\api::block_user($USER->id, $user1->id);
|
||||
$this->assertCount(2, message_get_blocked_users());
|
||||
$this->assertDebuggingCalled();
|
||||
|
||||
// Test deleting users.
|
||||
delete_user($user1);
|
||||
$this->assertCount(1, message_get_blocked_users());
|
||||
$this->assertDebuggingCalled();
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage(
|
||||
'message_get_blocked_users() has been removed, please use \core_message\api::get_blocked_users() instead.'
|
||||
);
|
||||
message_get_blocked_users();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test message_get_contacts.
|
||||
* Test message_get_contacts throws an exception because has been removed.
|
||||
*/
|
||||
public function test_message_get_contacts() {
|
||||
global $USER, $CFG;
|
||||
|
||||
// Set this user as the admin.
|
||||
$this->setAdminUser();
|
||||
|
||||
$noreplyuser = core_user::get_noreply_user();
|
||||
$supportuser = core_user::get_support_user();
|
||||
|
||||
// Create a user to add to the admin's contact list.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user(); // Stranger.
|
||||
|
||||
// Add users to the admin's contact list.
|
||||
\core_message\api::add_contact($USER->id, $user1->id);
|
||||
\core_message\api::add_contact($USER->id, $user2->id);
|
||||
|
||||
// Send some messages.
|
||||
$this->send_fake_message($user1, $USER);
|
||||
$this->send_fake_message($user2, $USER);
|
||||
$this->send_fake_message($user3, $USER);
|
||||
|
||||
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertCount(0, $onlinecontacts);
|
||||
$this->assertCount(2, $offlinecontacts);
|
||||
$this->assertCount(1, $strangers);
|
||||
|
||||
// Send message from noreply and support users.
|
||||
$this->send_fake_message($noreplyuser, $USER);
|
||||
$this->send_fake_message($supportuser, $USER);
|
||||
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertCount(0, $onlinecontacts);
|
||||
$this->assertCount(2, $offlinecontacts);
|
||||
$this->assertCount(3, $strangers);
|
||||
|
||||
// Block 1 user.
|
||||
\core_message\api::block_user($USER->id, $user2->id);
|
||||
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertCount(0, $onlinecontacts);
|
||||
$this->assertCount(1, $offlinecontacts);
|
||||
$this->assertCount(3, $strangers);
|
||||
|
||||
// Noreply user being valid user.
|
||||
core_user::reset_internal_users();
|
||||
$CFG->noreplyuserid = $user3->id;
|
||||
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertCount(0, $onlinecontacts);
|
||||
$this->assertCount(1, $offlinecontacts);
|
||||
$this->assertCount(2, $strangers);
|
||||
|
||||
// Test deleting users.
|
||||
delete_user($user1);
|
||||
delete_user($user3);
|
||||
core_user::reset_internal_users();
|
||||
list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts();
|
||||
$this->assertDebuggingCalled();
|
||||
$this->assertCount(0, $onlinecontacts);
|
||||
$this->assertCount(0, $offlinecontacts);
|
||||
$this->assertCount(1, $strangers);
|
||||
$this->expectException('coding_exception');
|
||||
$this->expectExceptionMessage('message_get_contacts() has been removed.');
|
||||
message_get_contacts();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,15 @@
|
||||
This files describes API changes in /message/ messaging system,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.9 ===
|
||||
* Removed the following depecated functions:
|
||||
- message_move_userfrom_unread2read
|
||||
- message_get_blocked_users
|
||||
- message_get_contacts
|
||||
- message_mark_message_read
|
||||
- message_can_delete_message
|
||||
- message_delete_message
|
||||
|
||||
=== 3.8 ===
|
||||
|
||||
* The following methods have been deprecated and should not be used any more:
|
||||
|
Loading…
x
Reference in New Issue
Block a user