コード例 #1
0
ファイル: I18n.php プロジェクト: grrr-amsterdam/garp3
 /**
  * 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;
 }
コード例 #2
0
ファイル: Cache.php プロジェクト: grrr-amsterdam/garp3
 /**
  * Clear all the cache
  *
  * @param array $args Tags.
  * @return bool
  */
 public function clear(array $args = array())
 {
     $app = Zend_Registry::get('application');
     $bootstrap = $app->getBootstrap();
     $cacheDir = false;
     if ($bootstrap && $bootstrap->getResource('cachemanager')) {
         $cacheManager = $bootstrap->getResource('cachemanager');
         $cache = $cacheManager->getCache(Zend_Cache_Manager::PAGECACHE);
         $cacheDir = $cache->getBackend()->getOption('public_dir');
     }
     Garp_Cache_Manager::purge($args, true, $cacheDir);
     Garp_Cli::lineOut('All cache purged.');
     return true;
 }
コード例 #3
0
ファイル: Cluster.php プロジェクト: grrr-amsterdam/garp3
 /**
  * @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;
         }
     }
 }
コード例 #4
0
ファイル: Cachable.php プロジェクト: grrr-amsterdam/garp3
 /**
  * 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);
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
ファイル: Facebook.php プロジェクト: grrr-amsterdam/garp3
 /**
  * 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;
     }
 }