本文整理汇总了PHP中core\task\manager::clear_static_caches方法的典型用法代码示例。如果您正苦于以下问题:PHP manager::clear_static_caches方法的具体用法?PHP manager::clear_static_caches怎么用?PHP manager::clear_static_caches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\task\manager
的用法示例。
在下文中一共展示了manager::clear_static_caches方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: purge_all_caches
/**
* Invalidates browser caches and cached data in temp.
*
* IMPORTANT - If you are adding anything here to do with the cache directory you should also have a look at
* {@link phpunit_util::reset_dataroot()}
*
* @return void
*/
function purge_all_caches()
{
global $CFG, $DB;
reset_text_filters_cache();
js_reset_all_caches();
theme_reset_all_caches();
get_string_manager()->reset_caches();
core_text::reset_caches();
if (class_exists('core_plugin_manager')) {
core_plugin_manager::reset_caches();
}
// Bump up cacherev field for all courses.
try {
increment_revision_number('course', 'cacherev', '');
} catch (moodle_exception $e) {
// Ignore exception since this function is also called before upgrade script when field course.cacherev does not exist yet.
}
$DB->reset_caches();
cache_helper::purge_all();
// Purge all other caches: rss, simplepie, etc.
clearstatcache();
remove_dir($CFG->cachedir . '', true);
// Make sure cache dir is writable, throws exception if not.
make_cache_directory('');
// This is the only place where we purge local caches, we are only adding files there.
// The $CFG->localcachedirpurged flag forces local directories to be purged on cluster nodes.
remove_dir($CFG->localcachedir, true);
set_config('localcachedirpurged', time());
make_localcache_directory('', true);
\core\task\manager::clear_static_caches();
}
示例2: execute
/**
* Execute task
*
* @global \moodle_database $DB
* @global \stdClass $CFG
* @return void
* @throws \moodle_exception
*/
public function execute()
{
global $DB, $CFG;
// Not going to work if we're missing settings.
if (!isset($CFG->block_mailchimp_apicode) || !isset($CFG->block_mailchimp_listid) || !isset($CFG->block_mailchimp_linked_profile_field)) {
return;
}
echo '== Beginning synchronization of MailChimp subscribers ==', "\n";
// Get all users in MailChimp and synchronize.
echo 'Getting list of users in MailChimp.', "\n";
$listusers = \block_mailchimp\helper::getMembersSync();
if (!$listusers) {
debugging("ERROR: Failed to get list of all members. Unable to synchronize users.");
return;
}
// If there is an interest specified, filter out users who do not have this interest marked.
if (isset($CFG->block_mailchimp_interest) && !$CFG->block_mailchimp_interest == "0") {
foreach ($listusers['members'] as $key => $externaluser) {
if ($externaluser['interests'][$CFG->block_mailchimp_interest] == false) {
unset($listusers['members'][$key]);
}
}
// Reindex the array
$listusers['members'] = array_values($listusers['members']);
}
$listuserscount = count($listusers['members']);
// Get list of users in Moodle
echo 'Getting list of users in Moodle.', "\n";
$moodleusers = $DB->get_records('user');
$moodleuserscount = count($moodleusers);
// Convert Moodle email addresses to lower case. Mailchimp stores emails in lower case and calculates the MD5 hash on the lower case email.
foreach ($moodleusers as $moodleuser) {
$moodleuser->email = strtolower($moodleuser->email);
}
// Sort MailChimp users list
echo 'Sorting list of MailChimp users.', "\n";
foreach ($listusers['members'] as $key => $row) {
$emails[$key] = $row['email_address'];
}
array_multisort($emails, SORT_ASC, $listusers['members']);
unset($emails);
// Sort Moodle users list
echo 'Sorting list of Moodle users.', "\n";
foreach ($moodleusers as $key => $row) {
$emails[$key] = $row->email;
}
array_multisort($emails, SORT_ASC, $moodleusers);
unset($emails);
// Syncronize the list of users in Moodle with those in Mailchimp
echo '== Starting sync of Moodle users with users in MailChimp ==', "\n";
foreach ($moodleusers as $moodleusersynckey => $moodleuser) {
$statuspercent = round($moodleusersynckey / $moodleuserscount * 100, 1, PHP_ROUND_HALF_UP);
echo $statuspercent, "% \r";
if (isguestuser($moodleuser)) {
continue;
}
$this->synchronize_user($moodleuser, $listusers);
}
echo 'Done.', "\n";
//Iterate through mailchimp list and compare to moodle users' emails. If the email is not found in moodle, delete from mailchimp list.
echo '== Starting MailChimp list cleanup ==', "\n";
foreach ($listusers['members'] as $listuserskey => $externaluser) {
$statuspercent = round($listuserskey / $listuserscount * 100, 1, PHP_ROUND_HALF_UP);
echo $statuspercent, "% \r";
$this->synchronize_mcuser($externaluser, $moodleusers);
}
echo 'Done.', "\n";
echo '== Finished MailChimp syncronization ==', "\n";
// Clean up static caches, since this process runs for a long time and (potentially) changes many DB records. See https://docs.moodle.org/dev/Task_API#Caches
\core\task\manager::clear_static_caches();
}