/** * Clear Nodes related cache after bulk operation * * @param CakeEvent $event * @return void */ public function onAfterBulkProcess($event) { Cache::clearGroup('nodes', 'nodes'); Cache::clearGroup('nodes', 'nodes_view'); Cache::clearGroup('nodes', 'nodes_promoted'); Cache::clearGroup('nodes', 'nodes_term'); Cache::clearGroup('nodes', 'nodes_index'); }
/** * Delete cache files matching prefix * * @param object $model * @return void */ protected function _deleteCachedFiles(Model $model) { foreach ($this->settings[$model->alias]['groups'] as $group) { $configs = CroogoCache::groupConfigs($group); foreach ($configs[$group] as $config) { Cache::clearGroup($group, $config); } } }
/** * testLinkIsAllowedByUserId */ public function testLinkIsAllowedByUserId() { Cache::clearGroup('acl', 'permissions'); $resetUrl = 'controllers/Users/reset'; $nodeViewUrl = 'controllers/Nodes/view'; $result = $this->AclHelper->linkIsAllowedByUserId(3, $nodeViewUrl); $this->assertTrue($result); $result = $this->AclHelper->linkIsAllowedByUserId(3, $resetUrl); $this->assertTrue($result); $result = $this->AclHelper->linkIsAllowedByUserId(2, $nodeViewUrl); $this->assertTrue($result); $result = $this->AclHelper->linkIsAllowedByUserId(2, $resetUrl); $this->assertTrue($result); }
/** * Test clearing a cache group * * @return void */ public function testGroupClear() { Cache::config('redis_groups', array('engine' => 'Redis', 'duration' => 3600, 'groups' => array('group_a', 'group_b'))); $this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups')); $this->assertTrue(Cache::clearGroup('group_a', 'redis_groups')); $this->assertFalse(Cache::read('test_groups', 'redis_groups')); $this->assertTrue(Cache::write('test_groups', 'value2', 'redis_groups')); $this->assertTrue(Cache::clearGroup('group_b', 'redis_groups')); $this->assertFalse(Cache::read('test_groups', 'redis_groups')); }
/** * Test clearing a cache group * * @return void */ public function testGroupClear() { Cache::config('wincache_groups', array('engine' => 'Wincache', 'duration' => 0, 'groups' => array('group_a', 'group_b'), 'prefix' => 'test_')); $this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); $this->assertTrue(Cache::clearGroup('group_a', 'wincache_groups')); $this->assertFalse(Cache::read('test_groups', 'wincache_groups')); $this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups')); $this->assertTrue(Cache::clearGroup('group_b', 'wincache_groups')); $this->assertFalse(Cache::read('test_groups', 'wincache_groups')); }
/** * Test that clearGroup works with no prefix. * * @return void */ public function testGroupClearNoPrefix() { Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'prefix' => '', 'groups' => array('group_a', 'group_b'))); Cache::write('key_1', 'value', 'file_groups'); Cache::write('key_2', 'value', 'file_groups'); Cache::clearGroup('group_a', 'file_groups'); $this->assertFalse(Cache::read('key_1', 'file_groups'), 'Did not delete'); $this->assertFalse(Cache::read('key_2', 'file_groups'), 'Did not delete'); }
/** * * @param AclNode $aro_nodes The Aro model hierarchy * @param string $aco_path The Aco path to check for * @param string $permission_type 'deny' or 'allow', 'grant', depending on what permission (grant or deny) is being set */ public function save_permission($aro_nodes, $aco_path, $permission_type) { //debug($aro_nodes);debug($aco_path);debug($permission_type); if (isset($aro_nodes[0])) { $aco_path = 'controllers/' . $aco_path; $pk_name = 'id'; if ($aro_nodes[0]['Aro']['model'] == Configure::read('acl.aro.role.model')) { $pk_name = $this->controller->_get_role_primary_key_name(); } elseif ($aro_nodes[0]['Aro']['model'] == Configure::read('acl.aro.user.model')) { $pk_name = $this->controller->_get_user_primary_key_name(); } //clear acl cache Cache::clearGroup('acl', Configure::read('CacheDbAclConfig')); $aro_model_data = array($aro_nodes[0]['Aro']['model'] => array($pk_name => $aro_nodes[0]['Aro']['foreign_key'])); $aro_id = $aro_nodes[0]['Aro']['id']; $specific_permission_right = $this->get_specific_permission_right($aro_nodes[0], $aco_path); $inherited_permission_right = $this->get_first_parent_permission_right($aro_nodes[0], $aco_path); if (!isset($inherited_permission_right) && count($aro_nodes) > 1) { /* * Get the permission inherited by the parent ARO */ $specific_parent_aro_permission_right = $this->get_specific_permission_right($aro_nodes[1], $aco_path); if (isset($specific_parent_aro_permission_right)) { /* * If there is a specific permission for the parent ARO on the ACO, the child ARO inheritates this permission */ $inherited_permission_right = $specific_parent_aro_permission_right; } else { $inherited_permission_right = $this->get_first_parent_permission_right($aro_nodes[1], $aco_path); } } /* * Check if the specific permission is necessary to get the correct permission */ if (!isset($inherited_permission_right)) { $specific_permission_needed = true; } else { if ($permission_type == 'allow' || $permission_type == 'grant') { $specific_permission_needed = $inherited_permission_right != 1; } else { $specific_permission_needed = $inherited_permission_right == 1; } } if ($specific_permission_needed) { if ($permission_type == 'allow' || $permission_type == 'grant') { if ($this->Acl->allow($aro_model_data, $aco_path)) { return true; } else { trigger_error(__d('acl', 'An error occured while saving the specific permission'), E_USER_NOTICE); return false; } } else { if ($this->Acl->deny($aro_model_data, $aco_path)) { return true; } else { trigger_error(__d('acl', 'An error occured while saving the specific permission'), E_USER_NOTICE); return false; } } } elseif (isset($specific_permission_right)) { $aco_node = $this->Acl->Aco->node($aco_path); if (!empty($aco_node)) { $aco_id = $aco_node[0]['Aco']['id']; $specific_permission = $this->Acl->Aro->Permission->find('first', array('conditions' => array('aro_id' => $aro_id, 'aco_id' => $aco_id))); if (!empty($specific_permission)) { if ($this->Acl->Aro->Permission->delete(array('Permission.id' => $specific_permission['Permission']['id']))) { return true; } else { trigger_error(__d('acl', 'An error occured while deleting the specific permission'), E_USER_NOTICE); return false; } } else { /* * As $specific_permission_right has a value, we should never fall here, but who knows... ;-) */ trigger_error(__d('acl', 'The specific permission id could not be retrieved'), E_USER_NOTICE); return false; } } else { /* * As $specific_permission_right has a value, we should never fall here, but who knows... ;-) */ trigger_error(__d('acl', 'The child ACO id could not be retrieved'), E_USER_NOTICE); return false; } } else { /* * Right can be inherited, and no specific permission exists => there is nothing to do... */ } } else { trigger_error(__d('acl', 'Invalid ARO'), E_USER_NOTICE); return false; } }
/** * Test clearing a cache group * * @return void */ public function testGroupClear() { Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b'))); Cache::config('file_groups2', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_b'))); Cache::config('file_groups3', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a'))); $this->assertTrue(Cache::write('test_groups', 'value', 'file_groups')); $this->assertTrue(Cache::write('test_groups2', 'value', 'file_groups2')); $this->assertTrue(Cache::write('test_groups3', 'value', 'file_groups3')); $this->assertTrue(Cache::clearGroup('group_a', 'file_groups')); $this->assertFalse(Cache::read('test_groups', 'file_groups')); $this->assertEquals('value', Cache::read('test_groups2', 'file_groups2')); $this->assertFalse(Cache::read('test_groups3', 'file_groups3')); $this->assertTrue(Cache::write('test_groups4', 'value', 'file_groups')); $this->assertTrue(Cache::write('test_groups5', 'value', 'file_groups2')); $this->assertTrue(Cache::write('test_groups6', 'value', 'file_groups3')); $this->assertTrue(Cache::clearGroup('group_b', 'file_groups')); $this->assertFalse(Cache::read('test_groups4', 'file_groups')); $this->assertFalse(Cache::read('test_groups5', 'file_groups2')); $this->assertEquals('value', Cache::read('test_groups6', 'file_groups3')); }
/** * Admin movedown * * @param integer $id * @param integer $step * @return void * @access public */ public function admin_movedown($id, $step = 1) { $link = $this->Link->findById($id); if (!isset($link['Link']['id'])) { $this->Session->setFlash(__d('croogo', 'Invalid id for Link'), 'default', array('class' => 'error')); $this->redirect(array('controller' => 'menus', 'action' => 'index')); } $this->__scopeTreeToMenu($link['Link']['menu_id']); if ($this->Link->moveDown($id, $step)) { Cache::clearGroup('menus', 'croogo_menus'); $this->Session->setFlash(__d('croogo', 'Moved down successfully'), 'default', array('class' => 'success')); } else { $this->Session->setFlash(__d('croogo', 'Could not move down'), 'default', array('class' => 'error')); } $this->redirect(array('action' => 'index', '?' => array('menu_id' => $link['Link']['menu_id']))); }
/** * afterDelete */ public function afterDelete(Model $model) { Cache::clearGroup('acl', 'permissions'); }
/** * Updates the Aco Tree with new controller actions. * * @return void **/ public function aco_update($params = array()) { $root = $this->_checkNode($this->rootNode, $this->rootNode, null); if (empty($params['plugin'])) { $controllers = $this->getControllerList(); $this->_updateControllers($root, $controllers); $plugins = CakePlugin::loaded(); } else { $plugin = $params['plugin']; if (!in_array($plugin, App::objects('plugin')) || !CakePlugin::loaded($plugin)) { $this->err(__d('croogo', '<error>Plugin %s not found or not activated</error>', $plugin)); return false; } $plugins = array($params['plugin']); } foreach ($plugins as $plugin) { $controllers = $this->getControllerList($plugin); $path = $this->rootNode . '/' . $plugin; $pluginRoot = $this->_checkNode($path, $plugin, $root['Aco']['id']); $this->_updateControllers($pluginRoot, $controllers, $plugin); $this->_updateApiComponents($controllers, $plugin); } Cache::clearGroup('acl', 'permissions'); if ($this->_clean) { $this->out(__d('croogo', '<success>Aco Sync Complete</success>')); } else { $this->out(__d('croogo', '<success>Aco Update Complete</success>')); } return true; }
public function afterSave($created, $options = array()) { Cache::clearGroup('admin_menus', 'admin_menus'); }
/** * afterSave */ public function afterSave($created, $options = array()) { Cache::clearGroup('acl', 'permissions'); }
/** * Clear Links related cache after bulk operation * * @param CakeEvent $event * @return void */ public function onAfterBulkProcess($event) { Cache::clearGroup('menus', 'croogo_menus'); }
/** * afterDelete Callback * * Invalidates the cache group for this model. * * @param Model $model Model the callback was run on. * @return void */ public function afterDelete(Model $model) { $cacheGroupName = $this->runtime[$model->alias]['default_cache']; $cacheName = $cacheGroupName; Cache::clearGroup($cacheGroupName, $cacheName); }