/** * command.post_command * @param sfEvent $event */ public static function listenToCommandPostCommandEvent(sfEvent $event) { if (aToolkitEvents::$once) { return; } aToolkitEvents::$once = true; $task = $event->getSubject(); if ($task->getFullName() === 'project:permissions') { $writable = aFiles::getWritableDataFolder(); $task->getFilesystem()->chmod($writable, 0777); $dirFinder = sfFinder::type('dir'); $fileFinder = sfFinder::type('file'); $task->getFilesystem()->chmod($dirFinder->in($writable), 0777); $task->getFilesystem()->chmod($fileFinder->in($writable), 0666); } if ($task->getFullName() === 'cache:clear') { aAssets::clearAssetCache($task->getFilesystem()); // Clear the page cache on symfony cc if (sfConfig::get('app_a_page_cache_enabled', false)) { echo "Clearing Apostrophe page cache\n"; $cache = aCacheFilter::getCache(); $cache->clean(); } else { // Cache not enabled for this environment. Too many tasks // invoke symfony cc with no environment, so let's not print // anything needlessly worrying here } } }
/** * Executes the filter chain. * * @param sfFilterChain $filterChain */ public function execute($filterChain) { if (!sfConfig::get('app_a_page_cache_enabled', false)) { $filterChain->execute(); return; } $sfUser = $this->context->getUser(); $uri = $this->context->getRequest()->getUri(); // Check for the aCacheInvalid override both before and after content gets generated if ($sfUser->isAuthenticated() || $this->context->getRequest()->getMethod() !== 'GET' || $sfUser->getFlash('aCacheInvalid', false) || $sfUser->getAttribute('aCacheInvalid', false)) { $filterChain->execute(); return; } $cache = aCacheFilter::getCache(); $content = $cache->get($uri, null); if (!is_null($content)) { $this->context->getResponse()->setContent($content); } else { $filterChain->execute(); $content = $this->context->getResponse()->getContent(); // Check whether aCacheInvalid was set for this user during the current request, don't cache // if it was if ($sfUser->getFlash('aCacheInvalid', false)) { return; } if ($sfUser->getAttribute('aCacheInvalid', false)) { return; } // Never cache anything with a CSRF token as it won't work (you should remove CSRF tokens from // forms that can't do anything negative/embarrassing/privacy-wrecking/spammy without information // a CSRF attacker won't have; for instance you don't need CSRF for a login form because the // spammer doesn't know your password) if (strstr($content, '_csrf_token') !== false) { return; } $cache->set($uri, $this->context->getResponse()->getContent(), sfConfig::get('app_a_page_cache_lifetime', 300)); } }