/** * Lists posts for a category * @param string $slug Category slug * @return \Cake\Network\Response|null|void * @throws RecordNotFoundException */ public function view($slug = null) { //The category can be passed as query string, from a widget if ($this->request->query('q')) { return $this->redirect([$this->request->query('q')]); } $page = $this->request->query('page') ? $this->request->query('page') : 1; //Sets the cache name $cache = sprintf('category_%s_limit_%s_page_%s', md5($slug), $this->paginate['limit'], $page); //Tries to get data from the cache list($posts, $paging) = array_values(Cache::readMany([$cache, sprintf('%s_paging', $cache)], $this->PostsCategories->cache)); //If the data are not available from the cache if (empty($posts) || empty($paging)) { $query = $this->PostsCategories->Posts->find('active')->select(['id', 'title', 'subtitle', 'slug', 'text', 'created'])->contain(['Categories' => function ($q) { return $q->select(['id', 'title', 'slug']); }, 'Tags' => function ($q) { return $q->order(['tag' => 'ASC']); }, 'Users' => function ($q) { return $q->select(['first_name', 'last_name']); }])->where(['Categories.slug' => $slug])->order([sprintf('%s.created', $this->PostsCategories->Posts->alias()) => 'DESC']); if ($query->isEmpty()) { throw new RecordNotFoundException(__d('me_cms', 'Record not found')); } $posts = $this->paginate($query)->toArray(); //Writes on cache Cache::writeMany([$cache => $posts, sprintf('%s_paging', $cache) => $this->request->param('paging')], $this->PostsCategories->cache); //Else, sets the paging parameter } else { $this->request->params['paging'] = $paging; } $this->set(am(['category' => $posts[0]->category], compact('posts'))); }
/** * Prepares some variables used in "default.ctp" layout, such as skin color to use, * pending comments counter, etc. * * @return array Associative array */ function backendLayoutVars() { $layoutOptions = []; $skin = theme()->settings('skin'); $boxClass = 'success'; $pendingComments = Cache::read('pending_comments', 'pending_comments'); if ($pendingComments === false) { $pendingComments = TableRegistry::get('Comment.Comments')->find()->where(['Comments.status' => 'pending', 'Comments.table_alias' => 'contents'])->count(); Cache::write('pending_comments', $pendingComments, 'pending_comments'); } $pendingComments = !$pendingComments ? '' : $pendingComments; if (strpos($skin, 'blue') !== false || strpos($skin, 'black') !== false) { $boxClass = 'info'; } elseif (strpos($skin, 'green') !== false) { $boxClass = 'success'; } elseif (strpos($skin, 'red') !== false || strpos($skin, 'purple') !== false) { $boxClass = 'danger'; } elseif (strpos($skin, 'yellow') !== false) { $boxClass = 'warning'; } if (theme()->settings('fixed_layout')) { $layoutOptions[] = 'fixed'; } if (theme()->settings('boxed_layout')) { $layoutOptions[] = 'layout-boxed'; } if (theme()->settings('collapsed_sidebar')) { $layoutOptions[] = 'sidebar-collapse'; } return compact('skin', 'layoutOptions', 'boxClass', 'pendingComments'); }
public function testInIndexBehavior() { $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestInRelatedIndexBehavior'); $this->Articles->addBehavior('RelatedContent\\Test\\TestCase\\Model\\Behavior\\TestHasRelatedBehavior'); /*$testEntity = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']); $this->Articles->save($testEntity);*/ //<editor-fold desc="Should get two related"> $firstArticle = $this->Articles->get(1, ['getRelated' => true]); $this->assertCount(2, $firstArticle->related); //</editor-fold> //<editor-fold desc="Should save only one"> $firstArticle = $this->Articles->patchEntity($firstArticle, ['related-articles' => [['id' => 3, '_joinData' => ['source_table_name' => 'articles', 'target_table_name' => 'articles']]]]); $this->Articles->save($firstArticle); $firstArticle = $this->Articles->get(1, ['getRelated' => true]); $this->assertCount(1, $firstArticle->related); //</editor-fold> //<editor-fold desc="Test if cache works"> $newArticle = $this->Articles->newEntity(['id' => 5, 'title' => 'Test title five']); $this->Articles->save($newArticle); $attachedTables = Cache::read('Related.attachedTables'); $indexedTables = Cache::read('Related.indexedTables'); $this->assertCount(1, $attachedTables); $this->assertEquals('articles', $attachedTables[0]); $this->assertCount(5, $indexedTables['Articles']); $this->assertEquals('Test title five', $indexedTables['Articles'][5]); $this->Articles->delete($this->Articles->get(3)); $indexedTables = Cache::read('Related.indexedTables'); $this->assertCount(4, $indexedTables['Articles']); //</editor-fold> }
/** * Teardown * * @return void */ public function tearDown() { parent::tearDown(); Cache::drop('orm_cache'); $ds = ConnectionManager::get('test'); $ds->cacheMetadata(false); }
/** * Show a list of all defined cache prefixes. * * @return void */ public function listPrefixes() { $prefixes = Cache::configured(); foreach ($prefixes as $prefix) { $this->out($prefix); } }
/** * Establishes a connection to the salesforce server * * @param array $config configuration to be used for creating connection * @return bool true on success */ protected function _connect(array $config) { $this->config = $config; if (empty($this->config['my_wsdl'])) { throw new \ErrorException("A WSDL needs to be provided"); } else { $wsdl = CONFIG . DS . $this->config['my_wsdl']; } $mySforceConnection = new \SforceEnterpriseClient(); $mySoapClient = $mySforceConnection->createConnection($wsdl); $sflogin = (array) Cache::read('salesforce_login', 'salesforce'); if (!empty($sflogin['sessionId'])) { $mySforceConnection->setSessionHeader($sflogin['sessionId']); $mySforceConnection->setEndPoint($sflogin['serverUrl']); } else { try { $mylogin = $mySforceConnection->login($this->config['username'], $this->config['password']); $sflogin = array('sessionId' => $mylogin->sessionId, 'serverUrl' => $mylogin->serverUrl); Cache::write('salesforce_login', $sflogin, 'salesforce'); } catch (Exception $e) { $this->log("Error logging into salesforce - Salesforce down?"); $this->log("Username: "******"Password: " . $this->config['password']); } } $this->client = $mySforceConnection; $this->connected = true; return $this->connected; }
/** * Setup * * @return void */ public function setUp() { parent::setUp(); Cache::clear(false); $this->apiFolderName = 'NonExistingApiPrefixedFolder'; $this->apiFolderPath = APP . 'Controller' . DS . $this->apiFolderName; }
/** * Get option by key * * @param string $key Option key * @return mixed|null */ public static function get($key) { if (!($options = Cache::read(self::$_config['cache_name']))) { $options = self::getAll(); } return array_key_exists($key, $options) ? $options[$key] : null; }
/** * Execute the ClearCache task. * * @return void */ public function main() { Cache::clear(false, '_cake_core_'); Cache::clear(false, 'database'); Cache::clear(false, 'acl'); $this->out('<info>The</info> "<error>deployer clear_cache</error>" <info>command has been executed successfully !</info>', 2); }
/** * Clear cache group. * * @return void */ protected function _clearCacheGroup() { $cacheGroups = $this->config('groups'); foreach ($cacheGroups as $group) { Cache::clearGroup($group, $this->config('config')); } }
protected function _touch(Request $request) { $key = $this->config('identifier'); if (is_callable($key)) { $key = $key($request); } return Cache::increment($key, static::$cacheConfig); }
/** * Tear down data. * * @return void */ public function tearDown() { parent::tearDown(); Plugin::unload($this->plugin); Cache::drop('permissions'); Cache::drop('permission_roles'); unset($this->Roles, $this->Users, $this->userData); }
public function main() { if (Cache::clear(false)) { $this->success('Cake cache clear complete'); } else { $this->err("Error : Cake cache clear failed"); } }
/** * Clears the cache * * @return void */ public function cleanup() { Cache::clear(false, 'default'); Cache::clear(false, '_cake_model_'); Cache::clear(false, '_cake_core_'); $this->dispatchShell('orm_cache clear'); $this->dispatchShell('orm_cache build'); }
/** * Assign $this->connection to the active task if a connection param is set. * * @return void */ public function startup() { parent::startup(); Configure::write('debug', true); Cache::disable(); if (isset($this->params['connection'])) { $this->connection = $this->params['connection']; } }
/** * @return mixed */ protected function _getIndexedTables() { if (($indexed_tables = Cache::read('Related.indexedTables')) === false) { $InRelatedIndexBehavior = new InRelatedIndexBehavior(TableRegistry::get('')); $InRelatedIndexBehavior->refreshCache(); $indexed_tables = Cache::read('Related.indexedTables'); } return $indexed_tables; }
/** * Clear a named cache. * * @return void * @throws \Cake\Network\Exception\NotFoundException */ public function clearCache() { $this->request->allowMethod('post'); if (!$this->request->data('name')) { throw new NotFoundException('Invalid cache engine name.'); } $result = Cache::clear(false, $this->request->data('name')); $this->set(['_serialize' => ['success'], 'success' => $result]); }
/** * Clears the caches * * @return void */ public function clearCache() { if ($this->request->is('POST')) { \Cake\Cache\Cache::clearAll(); $this->Flash->success(__d('elabs', 'The cache has been cleared')); $this->redirect($this->request->referer()); } else { throw new \Cake\Network\Exception\MethodNotAllowedException(__d('elabs', 'Use the menu to access this functionality')); } }
public function index() { //Just a way to trigger committed migrations from web interface echo "<pre>"; passthru('php ../bin/cake.php migrations migrate -vvv'); echo "</pre>"; //Clear the Model cache so any db updates will re-load \Cake\Cache\Cache::clear(false, '_cake_model_'); exit; }
/** * Ensure that subrequests don't double proxy the cache engine. * * @return void */ public function testInitializeTwiceNoDoubleProxy() { $event = new Event('Sample'); $this->panel->initialize($event); $result = Cache::engine('debug_kit_test'); $this->assertInstanceOf('DebugKit\\Cache\\Engine\\DebugEngine', $result); $this->panel->initialize($event); $result2 = Cache::engine('debug_kit_test'); $this->assertSame($result2, $result); }
/** * Tear down. * * @return void */ public function tearDown() { parent::tearDown(); unset($this->_controller, $this->url, $this->data); Plugin::unload($this->plugin); Plugin::unload('Union/Extensions'); Cache::drop('permissions'); Cache::drop('permission_roles'); Cache::drop('plugins'); }
/** * Called before the controller action. You can use this method to configure and customize components * or perform logic that needs to happen before each controller action. * * @param Event $event An Event instance * @return void * @link http://book.cakephp.org/3.0/en/controllers.html#request-life-cycle-callbacks */ public function beforeFilter(Event $event) { parent::beforeFilter($event); // TODO: Change the autogenerated stub if ($this->request->data) { Cache::drop('settingsFrontend'); Cache::drop('menuParents'); Cache::drop('subMenu'); } }
/** * Test clearing the cache. * * @return void */ public function testClearCache() { $mock = $this->getMock('Cake\\Cache\\CacheEngine'); $mock->expects($this->once())->method('init')->will($this->returnValue(true)); $mock->expects($this->once())->method('clear')->will($this->returnValue(true)); Cache::config('testing', $mock); $this->configRequest(['headers' => ['Accept' => 'application/json']]); $this->post('/debug_kit/toolbar/clear_cache', ['name' => 'testing']); $this->assertResponseOk(); $this->assertResponseContains('success'); }
/** * Write the data into the Cache with the passed key. * * @param int|object|string $data The data to save in the Cache. * @param string $key The key to save the data. * * @return bool */ protected function _writeCache($data, $key) { if (empty($data) || empty($key)) { return true; } $result = Cache::write($key, $data, 'statistics'); if ($result) { return true; } return false; }
/** * Migrate down */ public function down() { $table = $this->table('menus'); $table->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('menu_item_count', 'integer', ['default' => 0, 'null' => false])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('name', ['name' => 'BY_NAME', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); Cache::clear(); }
/** * Tests that schema metadata is cached * * @return void */ public function testDescribeCache() { $schema = $this->connection->schemaCollection(); $table = $this->connection->schemaCollection()->describe('users'); Cache::delete('test_users', '_cake_model_'); $schema->cacheMetadata(true); $result = $schema->describe('users'); $this->assertEquals($table, $result); $result = Cache::read('test_users', '_cake_model_'); $this->assertEquals($table, $result); }
/** * setUp method * * @return void */ public function setUp() { parent::setUp(); Cache::disable(); $this->request = $this->getMock('Cake\\Network\\Request'); $this->response = $this->getMock('Cake\\Network\\Response'); $this->Seobox = new SeoboxCell($this->request, $this->response); $this->Seobox->viewBuilder()->className('View'); $this->Seobox->viewBuilder()->layout('default'); $this->View = $this->Seobox->createView(); }
/** * Internal method to get the latest photos * @param int $limit Limit * @return array * @uses MeInstagram\Utility\Instagram::recent() */ protected function _latest($limit = 15) { //Tries to get data from the cache $photos = Cache::read($cache = sprintf('latest_%s', $limit), 'instagram'); //If the data are not available from the cache if (empty($photos)) { list($photos) = Instagram::recent(null, $limit); Cache::write($cache, $photos, 'instagram'); } return $photos; }
/** * Tests that schema metadata is cached * * @return void */ public function testDescribeCache() { $schema = $this->connection->methodSchemaCollection(); $method = $this->connection->methodSchemaCollection()->describe('CALC.SUM'); Cache::delete('test_CALC_SUM', '_cake_method_'); $this->connection->cacheMetadata(true); $schema = $this->connection->methodSchemaCollection(); $result = $schema->describe('CALC.SUM'); $this->assertEquals($method, $result); $result = Cache::read('test_CALC_SUM', '_cake_method_'); $this->assertEquals($method, $result); }
/** * Migrate down */ public function down() { $table = $this->table('menu_items'); $table->addColumn('menu_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('parent_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => true, 'default' => null])->addColumn('lft', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('rght', 'integer', ['limit' => 11, 'signed' => false, 'null' => false])->addColumn('name', 'string', ['limit' => 255, 'null' => false])->addColumn('type', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('target', 'text', ['null' => true, 'default' => null])->addColumn('external_link', 'text', ['null' => true, 'default' => null])->addColumn('foreign_model', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('foreign_id', 'integer', ['limit' => 11, 'signed' => false, 'null' => true, 'default' => null])->addColumn('plugin', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('controller', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('action', 'string', ['limit' => 255, 'null' => true, 'default' => null])->addColumn('params', 'text', ['null' => true, 'default' => null])->addColumn('query', 'text', ['null' => true, 'default' => null])->addColumn('created', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP'])->addColumn('modified', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']); $table->addIndex('menu_id', ['name' => 'FK_MENU_ID', 'unique' => false]); $table->addIndex('parent_id', ['name' => 'FK_PARENT_ID', 'unique' => false]); $table->create(); $id = new Column(); $id->setIdentity(true)->setType('integer')->setOptions(['limit' => 11, 'signed' => false, 'null' => false]); $table->changeColumn('id', $id)->save(); Cache::clear(); }