当前位置: 首页>>代码示例>>PHP>>正文


PHP context_helper::reset_caches方法代码示例

本文整理汇总了PHP中context_helper::reset_caches方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::reset_caches方法的具体用法?PHP context_helper::reset_caches怎么用?PHP context_helper::reset_caches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context_helper的用法示例。


在下文中一共展示了context_helper::reset_caches方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: accesslib_clear_all_caches

/**
 * Clears accesslib's private caches. ONLY BE USED FROM THIS LIBRARY FILE!
 *
 * This reset does not touch global $USER.
 *
 * @private
 * @param bool $resetcontexts
 * @return void
 */
function accesslib_clear_all_caches($resetcontexts)
{
    global $ACCESSLIB_PRIVATE;
    $ACCESSLIB_PRIVATE->dirtycontexts = null;
    $ACCESSLIB_PRIVATE->accessdatabyuser = array();
    $ACCESSLIB_PRIVATE->rolepermissions = array();
    $ACCESSLIB_PRIVATE->capabilities = null;
    if ($resetcontexts) {
        context_helper::reset_caches();
    }
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:20,代码来源:accesslib.php

示例2: setUp

 /**
  * Perform test setup and reset context caches.
  */
 protected function setUp()
 {
     parent::setUp();
     context_helper::reset_caches();
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:8,代码来源:version1elis_extrafields_test.php

示例3: test_get_url

 public function test_get_url()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     // Force SVG on so that we have predictable URL's.
     $CFG->svgicons = true;
     // verify new install contains expected defaults
     $this->assertEquals('standard', $CFG->theme);
     $this->assertEquals(1, $CFG->slasharguments);
     $this->assertEquals(1, $CFG->themerev);
     $this->assertEquals(0, $CFG->themedesignermode);
     $this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot);
     $this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot);
     $this->assertEquals(0, $CFG->enablegravatar);
     $this->assertEquals('mm', $CFG->gravatardefaulturl);
     // create some users
     $page = new moodle_page();
     $page->set_url('/user/profile.php');
     $page->set_context(context_system::instance());
     $renderer = $page->get_renderer('core');
     $user1 = $this->getDataGenerator()->create_user(array('picture' => 11, 'email' => 'user1@example.com'));
     $context1 = context_user::instance($user1->id);
     $user2 = $this->getDataGenerator()->create_user(array('picture' => 0, 'email' => 'user2@example.com'));
     $context2 = context_user::instance($user2->id);
     $user3 = $this->getDataGenerator()->create_user(array('picture' => 1, 'deleted' => 1, 'email' => 'user3@example.com'));
     $context3 = context_user::instance($user3->id, IGNORE_MISSING);
     $this->assertEquals($user3->picture, 0);
     $this->assertNotEquals($user3->email, 'user3@example.com');
     $this->assertFalse($context3);
     // try legacy picture == 1
     $user1->picture = 1;
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false));
     $user1->picture = 11;
     // try valid user with picture when user context is not cached - 1 query expected
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up1 = new user_picture($user1);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads + 1, $DB->perf_get_reads());
     // try valid user with contextid hint - no queries expected
     $user1->contextid = $context1->id;
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up1 = new user_picture($user1);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try valid user without image - no queries expected
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up2 = new user_picture($user2);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try guessing of deleted users - no queries expected
     unset($user3->deleted);
     context_helper::reset_caches();
     $reads = $DB->perf_get_reads();
     $up3 = new user_picture($user3);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $this->assertEquals($reads, $DB->perf_get_reads());
     // try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected
     $user3->email = 'user3@example.com';
     $user3->picture = 1;
     $reads = $DB->perf_get_reads();
     $up3 = new user_picture($user3);
     $this->assertEquals($reads, $DB->perf_get_reads());
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $this->assertTrue($reads < $DB->perf_get_reads());
     // test gravatar
     set_config('enablegravatar', 1);
     // deleted user can not have gravatar
     $user3->email = 'deleted';
     $user3->picture = 0;
     $up3 = new user_picture($user3);
     $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     // verify defaults to misteryman (mm)
     $up2 = new user_picture($user2);
     $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false));
     // without gravatardefaulturl, verify we pick own file
     set_config('gravatardefaulturl', '');
     $up2 = new user_picture($user2);
     $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // uploaded image takes precedence before gravatar
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     // https version
     $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     $up1 = new user_picture($user1);
     $this->assertEquals($CFG->httpswwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false));
     $up3 = new user_picture($user3);
     $this->assertEquals($CFG->httpswwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false));
     $up2 = new user_picture($user2);
     $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false));
     // now test gravatar with one theme having own images (afterburner)
     $CFG->httpswwwroot = $CFG->wwwroot;
     $this->assertTrue(file_exists("{$CFG->dirroot}/theme/afterburner/config.php"));
//.........这里部分代码省略.........
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:outputcomponents_test.php

示例4: test_everything_in_accesslib


//.........这里部分代码省略.........
            }
            if ($child->contextlevel == CONTEXT_COURSE) {
                $countcourses++;
            }
            if ($child->contextlevel == CONTEXT_BLOCK) {
                $countblocks++;
            }
        }
        $this->assertEquals(count($children), 8);
        $this->assertEquals($countcats, 1);
        $this->assertEquals($countcourses, 6);
        $this->assertEquals($countblocks, 1);

        $context = context_course::instance($testcourses[2]);
        $children = $context->get_child_contexts();
        $this->assertEquals(count($children), 7); // depends on number of default blocks

        $context = context_module::instance($testpages[3]);
        $children = $context->get_child_contexts();
        $this->assertEquals(count($children), 1);

        $context = context_block::instance($testblocks[1]);
        $children = $context->get_child_contexts();
        $this->assertEquals(count($children), 0);

        unset($children);
        unset($countcats);
        unset($countcourses);
        unset($countblocks);


        // ======= context_helper::reset_caches() ============================

        context_helper::reset_caches();
        $this->assertEquals(context_inspection::test_context_cache_size(), 0);
        context_course::instance($SITE->id);
        $this->assertEquals(context_inspection::test_context_cache_size(), 1);


        // ======= context preloading ========================================

        context_helper::reset_caches();
        $sql = "SELECT ".context_helper::get_preload_record_columns_sql('c')."
                  FROM {context} c
                 WHERE c.contextlevel <> ".CONTEXT_SYSTEM;
        $records = $DB->get_records_sql($sql);
        $firstrecord = reset($records);
        $columns = context_helper::get_preload_record_columns('c');
        $firstrecord = (array)$firstrecord;
        $this->assertSame(array_keys($firstrecord), array_values($columns));
        context_helper::reset_caches();
        foreach ($records as $record) {
            context_helper::preload_from_record($record);
            $this->assertEquals($record, new stdClass());
        }
        $this->assertEquals(context_inspection::test_context_cache_size(), count($records));
        unset($records);
        unset($columns);

        context_helper::reset_caches();
        context_helper::preload_course($SITE->id);
        $this->assertEquals(7, context_inspection::test_context_cache_size()); // depends on number of default blocks

        // ====== assign_capability(), unassign_capability() ====================

        $rc = $DB->get_record('role_capabilities', array('contextid'=>$frontpagecontext->id, 'roleid'=>$allroles['teacher'], 'capability'=>'moodle/site:accessallgroups'));
开发者ID:numbas,项目名称:moodle,代码行数:67,代码来源:accesslib_test.php

示例5: test_everything_in_accesslib


//.........这里部分代码省略.........
     $children = $context->get_child_contexts();
     $countcats = 0;
     $countcourses = 0;
     $countblocks = 0;
     foreach ($children as $child) {
         if ($child->contextlevel == CONTEXT_COURSECAT) {
             $countcats++;
         }
         if ($child->contextlevel == CONTEXT_COURSE) {
             $countcourses++;
         }
         if ($child->contextlevel == CONTEXT_BLOCK) {
             $countblocks++;
         }
     }
     $this->assertEqual(count($children), 8);
     $this->assertEqual($countcats, 1);
     $this->assertEqual($countcourses, 6);
     $this->assertEqual($countblocks, 1);
     $context = context_course::instance($testcourses[2]);
     $children = $context->get_child_contexts();
     $this->assertEqual(count($children), 3);
     $context = context_module::instance($testpages[3]);
     $children = $context->get_child_contexts();
     $this->assertEqual(count($children), 1);
     $context = context_block::instance($testblocks[1]);
     $children = $context->get_child_contexts();
     $this->assertEqual(count($children), 0);
     unset($children);
     unset($countcats);
     unset($countcourses);
     unset($countblocks);
     // ======= context_helper::reset_caches() ============================
     context_helper::reset_caches();
     $this->assertEqual(context_inspection::test_context_cache_size(), 0);
     context_course::instance($SITE->id);
     $this->assertEqual(context_inspection::test_context_cache_size(), 1);
     // ======= context preloading ========================================
     context_helper::reset_caches();
     $sql = "SELECT " . context_helper::get_preload_record_columns_sql('c') . "\n                  FROM {context} c\n                 WHERE c.contextlevel <> " . CONTEXT_SYSTEM;
     $records = $DB->get_records_sql($sql);
     $firstrecord = reset($records);
     $columns = context_helper::get_preload_record_columns('c');
     $firstrecord = (array) $firstrecord;
     $this->assertIdentical(array_keys($firstrecord), array_values($columns));
     context_helper::reset_caches();
     foreach ($records as $record) {
         context_helper::preload_from_record($record);
         $this->assertIdentical($record, new stdClass());
     }
     $this->assertEqual(context_inspection::test_context_cache_size(), count($records));
     unset($records);
     unset($columns);
     context_helper::reset_caches();
     context_helper::preload_course($SITE->id);
     $this->assertEqual(context_inspection::test_context_cache_size(), 4);
     // ====== assign_capability(), unassign_capability() ====================
     $rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
     $this->assertFalse($rc);
     assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $allroles['teacher'], $frontpagecontext->id);
     $rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
     $this->assertEqual($rc->permission, CAP_ALLOW);
     assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext->id);
     $rc = $DB->get_record('role_capabilities', array('contextid' => $frontpagecontext->id, 'roleid' => $allroles['teacher'], 'capability' => 'moodle/site:accessallgroups'));
     $this->assertEqual($rc->permission, CAP_ALLOW);
     assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $allroles['teacher'], $frontpagecontext, true);
开发者ID:rolandovanegas,项目名称:moodle,代码行数:67,代码来源:fulltestaccesslib.php

示例6: test_notifications

 /**
  * Test contexts in notifications.
  *
  * Covers:
  * local/elisprogram/lib/notifications.php:616
  * local/elisprogram/lib/notifications.php:617
  */
 public function test_notifications()
 {
     global $DB;
     $this->setup_users();
     context_helper::reset_caches();
     elis::$config->local_elisprogram->notify_classenrol_user = true;
     $rolesctx = $DB->get_records('role_context_levels', array('contextlevel' => CONTEXT_ELIS_PROGRAM));
     foreach ($rolesctx as $rolectx) {
         $roleid = $rolectx->roleid;
         break;
     }
     // Get user to assign role.
     $user = new user(103);
     $muser = $user->get_moodleuser();
     // Get specific context.
     $cur = $this->create_curriculum();
     $context = \local_elisprogram\context\program::instance($cur->id);
     // Assign role.
     $raid = role_assign($roleid, $muser->id, $context);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:27,代码来源:miscellaneouscontexts_test.php

示例7: test_mapping_applied_during_userset_delete

 /**
  * Validate that mappings are applied during the user set delete action
  */
 public function test_mapping_applied_during_userset_delete()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/accesslib.php';
     require_once $CFG->dirroot . '/local/elisprogram/lib/data/userset.class.php';
     $this->init_mapping();
     context_helper::reset_caches();
     $parentuserset = new userset(array('name' => 'testparentusersetname'));
     $parentuserset->save();
     \local_elisprogram\context\userset::instance($parentuserset->id);
     $userset = new userset(array('parent' => $parentuserset->id, 'name' => 'testusersetname'));
     $userset->save();
     \local_elisprogram\context\userset::instance($userset->id);
     // Run the course delete action.
     $record = new stdClass();
     $record->customaction = 'delete';
     $record->customcontext = 'cluster';
     $record->customname = 'testparentusersetname';
     $record->customrecursive = '1';
     $this->run_pmentity_import((array) $record);
     // Validation.
     $this->assertEquals(0, $DB->count_records(userset::TABLE));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:26,代码来源:elis_pmentity_field_mappings_test.php

示例8: fixture_userset

 /**
  * Set up a userset, two sub-usersets, and one sub-sub-userset, with contexts.
  */
 public function fixture_userset()
 {
     global $DB;
     context_helper::reset_caches();
     // Import usersets from CSV.
     $dataset = $this->createCsvDataSet(array(userset::TABLE => elispm::file('tests/fixtures/userset.csv')));
     $this->loadDataSet($dataset);
     // Set up userset contexts.
     $uset1ctx = (object) array('contextlevel' => CONTEXT_ELIS_USERSET, 'instanceid' => 1, 'path' => '', 'depth' => 2);
     $uset1ctx->id = $DB->insert_record('context', $uset1ctx);
     $DB->update_record('context', (object) array('id' => $uset1ctx->id, 'path' => '/1/' . $uset1ctx->id));
     $uset2ctx = (object) array('contextlevel' => CONTEXT_ELIS_USERSET, 'instanceid' => 2, 'path' => '', 'depth' => 3);
     $uset2ctx->id = $DB->insert_record('context', $uset2ctx);
     $DB->update_record('context', (object) array('id' => $uset2ctx->id, 'path' => '/1/' . $uset1ctx->id . '/' . $uset2ctx->id));
     $uset3ctx = (object) array('contextlevel' => CONTEXT_ELIS_USERSET, 'instanceid' => 3, 'path' => '', 'depth' => 3);
     $uset3ctx->id = $DB->insert_record('context', $uset3ctx);
     $DB->update_record('context', (object) array('id' => $uset3ctx->id, 'path' => '/1/' . $uset1ctx->id . '/' . $uset3ctx->id));
     $uset4ctx = (object) array('contextlevel' => CONTEXT_ELIS_USERSET, 'instanceid' => 4, 'path' => '', 'depth' => 4);
     $uset4ctx->id = $DB->insert_record('context', $uset4ctx);
     $path = '/1/' . $uset1ctx->id . '/' . $uset2ctx->id . '/' . $uset4ctx->id;
     $DB->update_record('context', (object) array('id' => $uset4ctx->id, 'path' => $path));
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:25,代码来源:accesslib_test.php


注:本文中的context_helper::reset_caches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。