本文整理汇总了PHP中message_move_userfrom_unread2read函数的典型用法代码示例。如果您正苦于以下问题:PHP message_move_userfrom_unread2read函数的具体用法?PHP message_move_userfrom_unread2read怎么用?PHP message_move_userfrom_unread2read使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了message_move_userfrom_unread2read函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
*
* Any plugin that needs to purge user data should register the 'user_deleted' event.
*
* @param stdClass $user full user object before delete
* @return boolean success
* @throws coding_exception if invalid $user parameter detected
*/
function delete_user(stdClass $user)
{
global $CFG, $DB;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
require_once $CFG->dirroot . '/user/lib.php';
// Make sure nobody sends bogus record type as parameter.
if (!property_exists($user, 'id') or !property_exists($user, 'username')) {
throw new coding_exception('Invalid $user parameter in delete_user() detected');
}
// Better not trust the parameter and fetch the latest info this will be very expensive anyway.
if (!($user = $DB->get_record('user', array('id' => $user->id)))) {
debugging('Attempt to delete unknown user account.');
return false;
}
// There must be always exactly one guest record, originally the guest account was identified by username only,
// now we use $CFG->siteguest for performance reasons.
if ($user->username === 'guest' or isguestuser($user)) {
debugging('Guest user account can not be deleted.');
return false;
}
// Admin can be theoretically from different auth plugin, but we want to prevent deletion of internal accoutns only,
// if anything goes wrong ppl may force somebody to be admin via config.php setting $CFG->siteadmins.
if ($user->auth === 'manual' and is_siteadmin($user)) {
debugging('Local administrator accounts can not be deleted.');
return false;
}
// Allow plugins to use this user object before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_user_delete')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($user);
}
}
}
// Keep user record before updating it, as we have to pass this to user_deleted event.
$olduser = clone $user;
// Keep a copy of user context, we need it for event.
$usercontext = context_user::instance($user->id);
// Delete all grades - backup is kept in grade_grades_history table.
grade_user_delete($user->id);
// Move unread messages from this user to read.
message_move_userfrom_unread2read($user->id);
// TODO: remove from cohorts using standard API here.
// Remove user tags.
core_tag_tag::remove_all_item_tags('core', 'user', $user->id);
// Unconditionally unenrol from all courses.
enrol_user_delete($user);
// Unenrol from all roles in all contexts.
// This might be slow but it is really needed - modules might do some extra cleanup!
role_unassign_all(array('userid' => $user->id));
// Now do a brute force cleanup.
// Remove from all cohorts.
$DB->delete_records('cohort_members', array('userid' => $user->id));
// Remove from all groups.
$DB->delete_records('groups_members', array('userid' => $user->id));
// Brute force unenrol from all courses.
$DB->delete_records('user_enrolments', array('userid' => $user->id));
// Purge user preferences.
$DB->delete_records('user_preferences', array('userid' => $user->id));
// Purge user extra profile info.
$DB->delete_records('user_info_data', array('userid' => $user->id));
// Purge log of previous password hashes.
$DB->delete_records('user_password_history', array('userid' => $user->id));
// Last course access not necessary either.
$DB->delete_records('user_lastaccess', array('userid' => $user->id));
// Remove all user tokens.
$DB->delete_records('external_tokens', array('userid' => $user->id));
// Unauthorise the user for all services.
$DB->delete_records('external_services_users', array('userid' => $user->id));
// Remove users private keys.
$DB->delete_records('user_private_key', array('userid' => $user->id));
// Remove users customised pages.
$DB->delete_records('my_pages', array('userid' => $user->id, 'private' => 1));
// Force logout - may fail if file based sessions used, sorry.
\core\session\manager::kill_user_sessions($user->id);
// Generate username from email address, or a fake email.
$delemail = !empty($user->email) ? $user->email : $user->username . '.' . $user->id . '@unknownemail.invalid';
$delname = clean_param($delemail . "." . time(), PARAM_USERNAME);
// Workaround for bulk deletes of users with the same email address.
while ($DB->record_exists('user', array('username' => $delname))) {
// No need to use mnethostid here.
$delname++;
}
// Mark internal user record as "deleted".
$updateuser = new stdClass();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
//.........这里部分代码省略.........
示例2: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($oldversion < 2009040600) {
/// Ensure that $CFG->stringfilters is set.
if (empty($CFG->stringfilters)) {
if (!empty($CFG->filterall)) {
set_config('stringfilters', $CFG->textfilters);
} else {
set_config('stringfilters', '');
}
}
set_config('filterall', !empty($CFG->stringfilters));
unset_config('textfilters');
/// Main savepoint reached
upgrade_main_savepoint(true, 2009040600);
}
if ($oldversion < 2009041700) {
/// To ensure the UI remains consistent with no behaviour change, any
/// 'until' date in an activity condition should have 1 second subtracted
/// (to go from 0:00 on the following day to 23:59 on the previous one).
$DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
require_once $CFG->dirroot . '/course/lib.php';
rebuild_course_cache(0, true);
/// Main savepoint reached
upgrade_main_savepoint(true, 2009041700);
}
if ($oldversion < 2009042600) {
/// Deleting orphaned messages from deleted users.
require_once $CFG->dirroot . '/message/lib.php';
/// Detect deleted users with messages sent(useridfrom) and not read
if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
FROM {user} u
JOIN {message} m ON m.useridfrom = u.id
WHERE u.deleted = ?', array(1))) {
foreach ($deletedusers as $deleteduser) {
message_move_userfrom_unread2read($deleteduser->id);
// move messages
}
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2009042600);
}
/// Dropping all enums/check contraints from core. MDL-18577
if ($oldversion < 2009042700) {
/// Changing list of values (enum) of field stattype on table stats_daily to none
$table = new xmldb_table('stats_daily');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field stattype on table stats_weekly to none
$table = new xmldb_table('stats_weekly');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field stattype on table stats_monthly to none
$table = new xmldb_table('stats_monthly');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field publishstate on table post to none
$table = new xmldb_table('post');
$field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
/// Launch change of list of values for field publishstate
$dbman->drop_enum_from_field($table, $field);
/// Main savepoint reached
upgrade_main_savepoint(true, 2009042700);
}
if ($oldversion < 2009043000) {
示例3: xmldb_main_upgrade
//.........这里部分代码省略.........
if (strpos($CFG->hiddenuserfields, 'firstaccess') === false) {
//firstaccess should not already be listed but just in case
set_config('hiddenuserfields', $CFG->hiddenuserfields . ',firstaccess');
}
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101542);
}
if ($result && $oldversion < 2007101545.01) {
require_once "{$CFG->dirroot}/filter/tex/lib.php";
filter_tex_updatedcallback(null);
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101545.01);
}
if ($result && $oldversion < 2007101546.02) {
if (empty($CFG->gradebook_latest195_upgrade)) {
require_once $CFG->libdir . '/gradelib.php';
// we need constants only
// reset current coef for simple mean items - it may contain some rubbish ;-)
$sql = "UPDATE {$CFG->prefix}grade_items\n SET aggregationcoef = 0\n WHERE categoryid IN (SELECT gc.id\n FROM {$CFG->prefix}grade_categories gc\n WHERE gc.aggregation = " . GRADE_AGGREGATE_WEIGHTED_MEAN2 . ")";
$result = execute_sql($sql);
} else {
// direct upgrade from 1.8.x - no need to reset coef, because it is already ok
unset_config('gradebook_latest195_upgrade');
}
upgrade_main_savepoint($result, 2007101546.02);
}
if ($result && $oldversion < 2007101546.03) {
/// Deleting orphaned messages from deleted users.
require_once $CFG->dirroot . '/message/lib.php';
/// Detect deleted users with messages sent(useridfrom) and not read
if ($deletedusers = get_records_sql("SELECT DISTINCT u.id\n FROM {$CFG->prefix}user u\n JOIN {$CFG->prefix}message m ON m.useridfrom = u.id\n WHERE u.deleted = 1")) {
foreach ($deletedusers as $deleteduser) {
message_move_userfrom_unread2read($deleteduser->id);
// move messages
}
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2007101546.03);
}
if ($result && $oldversion < 2007101546.05) {
// force full regrading - the max grade for sum aggregation was not correct when scales involved,
// extra credit grade is not dropped anymore in aggregations if drop low or keep high specified
// sum aggragetion respects drop low and keep high when calculation max value
set_field('grade_items', 'needsupdate', 1, 'needsupdate', 0);
}
if ($result && $oldversion < 2007101546.06) {
unset_config('grade_report_showgroups');
upgrade_main_savepoint($result, 2007101546.06);
}
if ($result && $oldversion < 2007101547) {
// Let's check the status of mandatory mnet_host records, fixing them
// and moving "orphan" users to default localhost record. MDL-16879
notify('Fixing mnet records, this may take a while...', 'notifysuccess');
$db->debug = false;
// Can output too much. Disabling
upgrade_fix_incorrect_mnethostids();
$db->debug = true;
// Restoring debug level
upgrade_main_savepoint($result, 2007101547);
}
if ($result && $oldversion < 2007101551) {
//insert new record for log_display table
//used to record tag update.
if (!record_exists("log_display", "action", "update", "module", "tag")) {
$log_action = new stdClass();
示例4: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
* @param object $user Userobject before delete (without system magic quotes)
* @return boolean success
*/
function delete_user($user)
{
global $CFG;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
begin_sql();
// delete all grades - backup is kept in grade_grades_history table
if ($grades = grade_grade::fetch_all(array('userid' => $user->id))) {
foreach ($grades as $grade) {
$grade->delete('userdelete');
}
}
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
// remove from all groups
delete_records('groups_members', 'userid', $user->id);
// unenrol from all roles in all contexts
role_unassign(0, $user->id);
// this might be slow but it is really needed - modules might do some extra cleanup!
// now do a final accesslib cleanup - removes all role assingments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
require_once $CFG->dirroot . '/tag/lib.php';
tag_set('user', $user->id, array());
// workaround for bulk deletes of users with the same email address
$delname = addslashes("{$user->email}." . time());
while (record_exists('user', 'username', $delname)) {
// no need to use mnethostid here
$delname++;
}
// mark internal user record as "deleted"
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
// Remember it just in case
$updateuser->email = md5($user->username);
// Store hash of username, useful importing/restoring users
$updateuser->idnumber = '';
// Clear this field to free it up
$updateuser->timemodified = time();
if (update_record('user', $updateuser)) {
commit_sql();
// notify auth plugin - do not block the delete even when plugin fails
$authplugin = get_auth_plugin($user->auth);
$authplugin->user_delete($user);
events_trigger('user_deleted', $user);
return true;
} else {
rollback_sql();
return false;
}
}
示例5: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
*
* Any plugin that needs to purge user data should register the 'user_deleted' event.
*
* @param object $user User object before delete
* @return boolean always true
*/
function delete_user($user)
{
global $CFG, $DB;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
require_once $CFG->dirroot . '/tag/lib.php';
// delete all grades - backup is kept in grade_grades_history table
grade_user_delete($user->id);
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
// TODO: remove from cohorts using standard API here
// remove user tags
tag_set('user', $user->id, array());
// unconditionally unenrol from all courses
enrol_user_delete($user);
// unenrol from all roles in all contexts
role_unassign_all(array('userid' => $user->id));
// this might be slow but it is really needed - modules might do some extra cleanup!
//now do a brute force cleanup
// remove from all cohorts
$DB->delete_records('cohort_members', array('userid' => $user->id));
// remove from all groups
$DB->delete_records('groups_members', array('userid' => $user->id));
// brute force unenrol from all courses
$DB->delete_records('user_enrolments', array('userid' => $user->id));
// purge user preferences
$DB->delete_records('user_preferences', array('userid' => $user->id));
// purge user extra profile info
$DB->delete_records('user_info_data', array('userid' => $user->id));
// last course access not necessary either
$DB->delete_records('user_lastaccess', array('userid' => $user->id));
// now do a final accesslib cleanup - removes all role assignments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
// workaround for bulk deletes of users with the same email address
$delname = "{$user->email}." . time();
while ($DB->record_exists('user', array('username' => $delname))) {
// no need to use mnethostid here
$delname++;
}
// mark internal user record as "deleted"
$updateuser = new stdClass();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
// Remember it just in case
$updateuser->email = md5($user->username);
// Store hash of username, useful importing/restoring users
$updateuser->idnumber = '';
// Clear this field to free it up
$updateuser->timemodified = time();
$DB->update_record('user', $updateuser);
// notify auth plugin - do not block the delete even when plugin fails
$authplugin = get_auth_plugin($user->auth);
$authplugin->user_delete($user);
// any plugin that needs to cleanup should register this event
events_trigger('user_deleted', $user);
return true;
}
示例6: delete_user
/**
* Marks user deleted in internal user database and notifies the auth plugin.
* Also unenrols user from all roles and does other cleanup.
*
* Any plugin that needs to purge user data should register the 'user_deleted' event.
*
* @param stdClass $user full user object before delete
* @return boolean success
* @throws coding_exception if invalid $user parameter detected
*/
function delete_user(stdClass $user)
{
global $CFG, $DB;
require_once $CFG->libdir . '/grouplib.php';
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->dirroot . '/message/lib.php';
require_once $CFG->dirroot . '/tag/lib.php';
// Make sure nobody sends bogus record type as parameter.
if (!property_exists($user, 'id') or !property_exists($user, 'username')) {
throw new coding_exception('Invalid $user parameter in delete_user() detected');
}
// Better not trust the parameter and fetch the latest info,
// this will be very expensive anyway.
if (!($user = $DB->get_record('user', array('id' => $user->id)))) {
debugging('Attempt to delete unknown user account.');
return false;
}
// There must be always exactly one guest record,
// originally the guest account was identified by username only,
// now we use $CFG->siteguest for performance reasons.
if ($user->username === 'guest' or isguestuser($user)) {
debugging('Guest user account can not be deleted.');
return false;
}
// Admin can be theoretically from different auth plugin,
// but we want to prevent deletion of internal accoutns only,
// if anything goes wrong ppl may force somebody to be admin via
// config.php setting $CFG->siteadmins.
if ($user->auth === 'manual' and is_siteadmin($user)) {
debugging('Local administrator accounts can not be deleted.');
return false;
}
// delete all grades - backup is kept in grade_grades_history table
grade_user_delete($user->id);
//move unread messages from this user to read
message_move_userfrom_unread2read($user->id);
// TODO: remove from cohorts using standard API here
// remove user tags
tag_set('user', $user->id, array());
// unconditionally unenrol from all courses
enrol_user_delete($user);
// unenrol from all roles in all contexts
role_unassign_all(array('userid' => $user->id));
// this might be slow but it is really needed - modules might do some extra cleanup!
//now do a brute force cleanup
// remove from all cohorts
$DB->delete_records('cohort_members', array('userid' => $user->id));
// remove from all groups
$DB->delete_records('groups_members', array('userid' => $user->id));
// brute force unenrol from all courses
$DB->delete_records('user_enrolments', array('userid' => $user->id));
// purge user preferences
$DB->delete_records('user_preferences', array('userid' => $user->id));
// purge user extra profile info
$DB->delete_records('user_info_data', array('userid' => $user->id));
// last course access not necessary either
$DB->delete_records('user_lastaccess', array('userid' => $user->id));
// remove all user tokens
$DB->delete_records('external_tokens', array('userid' => $user->id));
// unauthorise the user for all services
$DB->delete_records('external_services_users', array('userid' => $user->id));
// Remove users private keys.
$DB->delete_records('user_private_key', array('userid' => $user->id));
// Remove users customised pages.
$DB->delete_records('my_pages', array('userid' => $user->id, 'private' => 1));
// force logout - may fail if file based sessions used, sorry
session_kill_user($user->id);
// now do a final accesslib cleanup - removes all role assignments in user context and context itself
delete_context(CONTEXT_USER, $user->id);
// workaround for bulk deletes of users with the same email address
$delname = "{$user->email}." . time();
while ($DB->record_exists('user', array('username' => $delname))) {
// no need to use mnethostid here
$delname++;
}
// mark internal user record as "deleted"
$updateuser = new stdClass();
$updateuser->id = $user->id;
$updateuser->deleted = 1;
$updateuser->username = $delname;
// Remember it just in case
$updateuser->email = md5($user->username);
// Store hash of username, useful importing/restoring users
$updateuser->idnumber = '';
// Clear this field to free it up
$updateuser->picture = 0;
$updateuser->timemodified = time();
$DB->update_record('user', $updateuser);
// Add this action to log
add_to_log(SITEID, 'user', 'delete', "view.php?id={$user->id}", $user->firstname . ' ' . $user->lastname);
//.........这里部分代码省略.........
示例7: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($result && $oldversion < 2009040600) {
/// Ensure that $CFG->stringfilters is set.
if (empty($CFG->stringfilters)) {
if (!empty($CFG->filterall)) {
set_config('stringfilters', $CFG->textfilters);
} else {
set_config('stringfilters', '');
}
}
set_config('filterall', !empty($CFG->stringfilters));
unset_config('textfilters');
/// Main savepoint reached
upgrade_main_savepoint($result, 2009040600);
}
if ($result && $oldversion < 2009041700) {
/// To ensure the UI remains consistent with no behaviour change, any
/// 'until' date in an activity condition should have 1 second subtracted
/// (to go from 0:00 on the following day to 23:59 on the previous one).
$DB->execute('UPDATE {course_modules} SET availableuntil = availableuntil - 1 WHERE availableuntil <> 0');
require_once $CFG->dirroot . '/course/lib.php';
rebuild_course_cache(0, true);
/// Main savepoint reached
upgrade_main_savepoint($result, 2009041700);
}
if ($result && $oldversion < 2009042600) {
/// Deleting orphaned messages from deleted users.
require_once $CFG->dirroot . '/message/lib.php';
/// Detect deleted users with messages sent(useridfrom) and not read
if ($deletedusers = $DB->get_records_sql('SELECT DISTINCT u.id
FROM {user} u
JOIN {message} m ON m.useridfrom = u.id
WHERE u.deleted = ?', array(1))) {
foreach ($deletedusers as $deleteduser) {
message_move_userfrom_unread2read($deleteduser->id);
// move messages
}
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2009042600);
}
/// Dropping all enums/check contraints from core. MDL-18577
if ($result && $oldversion < 2009042700) {
/// Changing list of values (enum) of field stattype on table stats_daily to none
$table = new xmldb_table('stats_daily');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field stattype on table stats_weekly to none
$table = new xmldb_table('stats_weekly');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field stattype on table stats_monthly to none
$table = new xmldb_table('stats_monthly');
$field = new xmldb_field('stattype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'activity', 'roleid');
/// Launch change of list of values for field stattype
$dbman->drop_enum_from_field($table, $field);
/// Changing list of values (enum) of field publishstate on table post to none
$table = new xmldb_table('post');
$field = new xmldb_field('publishstate', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, 'draft', 'attachment');
/// Launch change of list of values for field publishstate
$dbman->drop_enum_from_field($table, $field);
/// Main savepoint reached
upgrade_main_savepoint($result, 2009042700);
}
if ($result && $oldversion < 2009043000) {