Exemple #1
0
 public function info()
 {
     $backend = Garp_Cache_Manager::getCacheBackend();
     Garp_Cli::lineOut('# Server cache backend');
     $out = $backend ? 'Backend type: ' . get_class($backend) : 'No cache backend found';
     Garp_Cli::lineOut($out);
 }
Exemple #2
0
 /**
  * This updates your database to be compliant with the refactored Translatable behavior.
  * I18n views no longer use fallbacks to the default language records.
  * Therefore an update to existing databases is necessary. This command populates records in
  * non-default languages to provide the data that used to be fallen back on.
  *
  * @param array $args
  * @return bool
  */
 public function populateLocalizedRecords(array $args = array())
 {
     Zend_Registry::get('CacheFrontend')->setOption('caching', false);
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $models = !empty($args) ? array($args[0]) : $this->_getInternationalizedModels();
     array_walk($models, array($this, '_populateRecordsForModel'));
     Zend_Registry::get('CacheFrontend')->setOption('caching', true);
     Garp_Cache_Manager::purge();
     Garp_Cli::lineOut('Done.');
     return true;
 }
Exemple #3
0
 /**
  * @param int $serverId Database id of the current server in the cluster
  * @param string $lastCheckIn MySQL datetime that represents the
  *                            last check-in time of this server
  * @return void
  */
 public function executeDueJobs($serverId, $lastCheckIn)
 {
     //  if the last check-in was more than two hours ago, first clear the cache.
     if (time() - strtotime($lastCheckIn) > 60 * 60 * 2) {
         Garp_Cache_Manager::purge(array(), false);
         $this->clearedTags = array();
     } else {
         $clusterClearCacheJobModel = new Model_ClusterClearCacheJob();
         $jobs = $clusterClearCacheJobModel->fetchDue($serverId, $lastCheckIn);
         if (count($jobs)) {
             if ($this->_containsGeneralClearJob($jobs)) {
                 Garp_Cache_Manager::purge(array(), false);
                 $this->clearedTags = array();
             } else {
                 $tags = $this->_getTagsFromJobs($jobs);
                 Garp_Cache_Manager::purge($tags, false);
                 $this->clearedTags = $tags;
             }
         } else {
             $this->clearedTags = false;
         }
     }
 }
Exemple #4
0
 /**
  * After delete callback, will destroy the existing cache for this model
  * @param Array $args
  * @return Void
  */
 public function afterDelete(&$args)
 {
     $model =& $args[0];
     $where = $args[2];
     Garp_Cache_Manager::purge($model);
 }
 /**
  * Clear all cache system wide.
  * Static Cache is tagged, so a comma-separated list of tags may be given to
  * only clear cache tagged with those tags.
  * Memcache is not tagged.
  *
  * @return Void
  */
 public function clearcacheAction()
 {
     $request = $this->getRequest();
     $tags = array();
     if ($request->getParam('tags')) {
         $tags = explode(',', $request->getParam('tags'));
     }
     $createClusterJob = is_null($request->getParam('createClusterJob')) ? 1 : $request->getParam('createClusterJob');
     $this->view->title = 'Clear that cache';
     Garp_Cache_Manager::purge($tags, $createClusterJob);
 }
Exemple #6
0
 /**
  * After save callback, called by afterInsert and afterUpdate.
  * Sets an `at` job that clears the Static Page cache at the exact moment of the Published date.
  * @param Garp_Model_Db $model
  * @param Array $data
  * @return Void
  */
 public function afterSave($model, $data)
 {
     // Check if the 'published column' is filled...
     if (empty($data[self::PUBLISHED_COLUMN])) {
         return;
     }
     // ...and that it's in the future
     $publishTime = strtotime($data[self::PUBLISHED_COLUMN]);
     if ($publishTime <= time()) {
         return;
     }
     $tags = array(get_class($model));
     $tags = array_merge($tags, $model->getBindableModels());
     $tags = array_unique($tags);
     Garp_Cache_Manager::scheduleClear($publishTime, $tags);
 }
Exemple #7
0
 /**
  * Find friends of logged in user and map to local friends table.
  * @param Array $config
  * @return Bool Success
  */
 public function mapFriends(array $config)
 {
     $config = $config instanceof Garp_Util_Configuration ? $config : new Garp_Util_Configuration($config);
     $config->obligate('bindingModel')->obligate('user_id')->setDefault('accessToken', $this->getAccessToken());
     if (!$config['accessToken']) {
         // Find the auth record
         $authModel = new Model_AuthFacebook();
         $authRow = $authModel->fetchRow($authModel->select()->where('user_id = ?', $config['user_id']));
         if (!$authRow || !$authRow->access_token) {
             return false;
         }
         // Use the stored access token to create a user session. Me() in the FQL ahead will contain the user's Facebook ID.
         // Note that the access token is available for a very limited time. Chances are it's not valid anymore.
         $accessToken = $authRow->access_token;
     }
     try {
         $this->_client->setAccessToken($config['accessToken']);
         // Find the friends' Facebook UIDs
         $friends = $this->_client->api(array('method' => 'fql.query', 'query' => 'SELECT uid2 FROM friend WHERE uid1 = me()'));
         // Find local user records
         $userModel = new Model_User();
         $userTable = $userModel->getName();
         $authFbModel = new Model_AuthFacebook();
         $authFbTable = $authFbModel->getName();
         $fbIds = '';
         $friendCount = count($friends);
         foreach ($friends as $i => $friend) {
             $fbIds .= $userModel->getAdapter()->quote($friend['uid2']);
             if ($i < $friendCount - 1) {
                 $fbIds .= ',';
             }
         }
         $friendQuery = $userModel->select()->setIntegrityCheck(false)->from($userTable, array('id'))->join($authFbTable, $authFbTable . '.user_id = ' . $userTable . '.id', array())->where('facebook_uid IN (' . $fbIds . ')')->order($userTable . '.id');
         $localUsers = $userModel->fetchAll($friendQuery);
         $localUserCount = count($localUsers);
         // Insert new friendships into binding model
         $bindingModel = new $config['bindingModel']();
         $insertSql = 'INSERT IGNORE INTO ' . $bindingModel->getName() . ' (user1_id, user2_id) VALUES ';
         foreach ($localUsers as $i => $localUser) {
             $insertSql .= '(' . $localUser->id . ',' . $config['user_id'] . '),';
             $insertSql .= '(' . $config['user_id'] . ',' . $localUser->id . ')';
             if ($i < $localUserCount - 1) {
                 $insertSql .= ',';
             }
         }
         $result = $bindingModel->getAdapter()->query($insertSql);
         // Clear cache manually, since the table isn't updated thru conventional paths.
         Garp_Cache_Manager::purge($bindingModel);
         return !!$result;
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #8
0
 protected function _spawnDb()
 {
     $modelSet = $this->getModelSet();
     $progress = $this->_getFeedbackInstance();
     $progress->displayHeader("Database");
     $dbManager = Garp_Spawn_MySql_Manager::getInstance($progress);
     $dbManager->setInteractive($this->getFeedback()->isInteractive());
     $dbManager->run($modelSet);
     $cacheDir = $this->_getCacheDir();
     Garp_Cache_Manager::purgeStaticCache(null, $cacheDir);
     Garp_Cache_Manager::purgeMemcachedCache(null);
     if ($this->getFeedback()->isInteractive()) {
         Garp_Cli::lineOut("All cache purged.");
     }
 }