本文整理匯總了PHP中mod_forum\subscriptions::fill_subscription_cache方法的典型用法代碼示例。如果您正苦於以下問題:PHP subscriptions::fill_subscription_cache方法的具體用法?PHP subscriptions::fill_subscription_cache怎麽用?PHP subscriptions::fill_subscription_cache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mod_forum\subscriptions
的用法示例。
在下文中一共展示了subscriptions::fill_subscription_cache方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_subscription_cache_prefill
/**
* Test that the subscription cache can be pre-filled.
*/
public function test_subscription_cache_prefill()
{
global $DB;
$this->resetAfterTest(true);
// Create a course, with a forum.
$course = $this->getDataGenerator()->create_course();
$options = array('course' => $course->id, 'forcesubscribe' => FORUM_INITIALSUBSCRIBE);
$forum = $this->getDataGenerator()->create_module('forum', $options);
// Create some users.
$users = $this->helper_create_users($course, 20);
// Reset the subscription cache.
\mod_forum\subscriptions::reset_forum_cache();
// Filling the subscription cache should only use a single query.
$startcount = $DB->perf_get_reads();
$this->assertNull(\mod_forum\subscriptions::fill_subscription_cache($forum->id));
$postfillcount = $DB->perf_get_reads();
$this->assertEquals(1, $postfillcount - $startcount);
// Now fetch some subscriptions from that forum - these should use
// the cache and not perform additional queries.
foreach ($users as $user) {
$this->assertTrue(\mod_forum\subscriptions::fetch_subscription_cache($forum->id, $user->id));
}
$finalcount = $DB->perf_get_reads();
$this->assertEquals(0, $finalcount - $postfillcount);
}
示例2: forum_cron
/**
* Function to be run periodically according to the scheduled task.
*
* Finds all posts that have yet to be mailed out, and mails them
* out to all subscribers as well as other maintance tasks.
*
* NOTE: Since 2.7.2 this function is run by scheduled task rather
* than standard cron.
*
* @todo MDL-44734 The function will be split up into seperate tasks.
*/
function forum_cron()
{
global $CFG, $USER, $DB;
$site = get_site();
// All users that are subscribed to any post that needs sending,
// please increase $CFG->extramemorylimit on large sites that
// send notifications to a large number of users.
$users = array();
$userscount = 0;
// Cached user counter - count($users) in PHP is horribly slow!!!
// Status arrays.
$mailcount = array();
$errorcount = array();
// caches
$discussions = array();
$forums = array();
$courses = array();
$coursemodules = array();
$subscribedusers = array();
// Posts older than 2 days will not be mailed. This is to avoid the problem where
// cron has not been running for a long time, and then suddenly people are flooded
// with mail from the past few weeks or months
$timenow = time();
$endtime = $timenow - $CFG->maxeditingtime;
$starttime = $endtime - 48 * 3600;
// Two days earlier
// Get the list of forum subscriptions for per-user per-forum maildigest settings.
$digestsset = $DB->get_recordset('forum_digests', null, '', 'id, userid, forum, maildigest');
$digests = array();
foreach ($digestsset as $thisrow) {
if (!isset($digests[$thisrow->forum])) {
$digests[$thisrow->forum] = array();
}
$digests[$thisrow->forum][$thisrow->userid] = $thisrow->maildigest;
}
$digestsset->close();
if ($posts = forum_get_unmailed_posts($starttime, $endtime, $timenow)) {
// Mark them all now as being mailed. It's unlikely but possible there
// might be an error later so that a post is NOT actually mailed out,
// but since mail isn't crucial, we can accept this risk. Doing it now
// prevents the risk of duplicated mails, which is a worse problem.
if (!forum_mark_old_posts_as_mailed($endtime)) {
mtrace('Errors occurred while trying to mark some posts as being mailed.');
return false;
// Don't continue trying to mail them, in case we are in a cron loop
}
// checking post validity, and adding users to loop through later
foreach ($posts as $pid => $post) {
$discussionid = $post->discussion;
if (!isset($discussions[$discussionid])) {
if ($discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
$discussions[$discussionid] = $discussion;
\mod_forum\subscriptions::fill_subscription_cache($discussion->forum);
\mod_forum\subscriptions::fill_discussion_subscription_cache($discussion->forum);
} else {
mtrace('Could not find discussion ' . $discussionid);
unset($posts[$pid]);
continue;
}
}
$forumid = $discussions[$discussionid]->forum;
if (!isset($forums[$forumid])) {
if ($forum = $DB->get_record('forum', array('id' => $forumid))) {
$forums[$forumid] = $forum;
} else {
mtrace('Could not find forum ' . $forumid);
unset($posts[$pid]);
continue;
}
}
$courseid = $forums[$forumid]->course;
if (!isset($courses[$courseid])) {
if ($course = $DB->get_record('course', array('id' => $courseid))) {
$courses[$courseid] = $course;
} else {
mtrace('Could not find course ' . $courseid);
unset($posts[$pid]);
continue;
}
}
if (!isset($coursemodules[$forumid])) {
if ($cm = get_coursemodule_from_instance('forum', $forumid, $courseid)) {
$coursemodules[$forumid] = $cm;
} else {
mtrace('Could not find course module for forum ' . $forumid);
unset($posts[$pid]);
continue;
}
}
//.........這裏部分代碼省略.........
示例3: print_error
if (!$cmto->uservisible) {
print_error('cannotmovenotvisible', 'forum', $return);
}
$destinationctx = context_module::instance($cmto->id);
require_capability('mod/forum:startdiscussion', $destinationctx);
if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
}
// For each subscribed user in this forum and discussion, copy over per-discussion subscriptions if required.
$discussiongroup = $discussion->groupid == -1 ? 0 : $discussion->groupid;
$potentialsubscribers = \mod_forum\subscriptions::fetch_subscribed_users($forum, $discussiongroup, $modcontext, 'u.id', true);
// Pre-seed the subscribed_discussion caches.
// Firstly for the forum being moved to.
\mod_forum\subscriptions::fill_subscription_cache($forumto->id);
// And also for the discussion being moved.
\mod_forum\subscriptions::fill_subscription_cache($forum->id);
$subscriptionchanges = array();
$subscriptiontime = time();
foreach ($potentialsubscribers as $subuser) {
$userid = $subuser->id;
$targetsubscription = \mod_forum\subscriptions::is_subscribed($userid, $forumto, null, $cmto);
$discussionsubscribed = \mod_forum\subscriptions::is_subscribed($userid, $forum, $discussion->id);
$forumsubscribed = \mod_forum\subscriptions::is_subscribed($userid, $forum);
if ($forumsubscribed && !$discussionsubscribed && $targetsubscription) {
// The user has opted out of this discussion and the move would cause them to receive notifications again.
// Ensure they are unsubscribed from the discussion still.
$subscriptionchanges[$userid] = \mod_forum\subscriptions::FORUM_DISCUSSION_UNSUBSCRIBED;
} else {
if (!$forumsubscribed && $discussionsubscribed && !$targetsubscription) {
// The user has opted into this discussion and would otherwise not receive the subscription after the move.
// Ensure they are subscribed to the discussion still.