/**
  * Appends tags to the existing
  *
  * @param mixed $tags
  * @param string $namespace
  * @return null
  */
 public function addContentTags($tags, $namespace)
 {
     $this->getHolder()->add(sfCacheTaggingToolkit::formatTags($tags), $namespace);
 }
 /**
  * Builds tag name by keyFormat and passed values
  *
  * @param string  $keyFormat
  * @param array   $values
  * @return string
  */
 public static function buildTagKey(Doctrine_Template_Cachetaggable $template, $keyFormat, array $values)
 {
     /**
      * First element is object's class name
      */
     $columnValues = array(sfCacheTaggingToolkit::getBaseClassName($template->getTable()->getClassnameToReturn()));
     /**
      * following elements are row's "candidate keys"
      * @link http://databases.about.com/cs/specificproducts/g/candidate.htm
      */
     $columnValues = array_merge($columnValues, $values);
     return call_user_func_array('sprintf', array_merge(array($keyFormat), $columnValues));
 }
예제 #3
0
 /**
  * @see parent::_doFetch()
  * @return mixed
  */
 protected function _doFetch($id, $testCacheValidity = true)
 {
     try {
         $value = $this->getTaggingCache()->get($id);
         return null === $value ? false : $value;
     } catch (sfCacheDisabledException $e) {
         sfCacheTaggingToolkit::notifyApplicationLog(__CLASS__, $e->getMessage(), sfLogger::NOTICE);
     }
     return false;
 }
 /**
  * @see Doctrine_Record::unlink()
  * @return sfCachetaggableDoctrineRecord
  */
 public function unlink($alias, $ids = array(), $now = false)
 {
     $self = parent::unlink($alias, $ids, $now);
     try {
         $taggingCache = sfCacheTaggingToolkit::getTaggingCache();
     } catch (sfException $e) {
         return $self;
     }
     $tagNames = $this->getTagNamesByAlias($alias, $ids);
     if (is_array($tagNames)) {
         $taggingCache->deleteTags($tagNames);
     }
     return $self;
 }
 /**
  * Appends tags to doctrine result cache
  *
  * @param mixed                   $tags
  * @param Doctrine_Query|string   $q        Doctrine_Query or string
  * @param array                   $params   params from $q->getParams()
  *
  * @return sfViewCacheTagManagerBridge
  */
 public function addDoctrineTags($tags, $q, array $params = array())
 {
     $key = null;
     if (is_string($q)) {
         $key = $q;
     } elseif ($q instanceof Doctrine_Query) {
         $key = $q->getResultCacheHash($params);
     } else {
         throw new InvalidArgumentException('Invalid arguments are passed');
     }
     $tags = sfCacheTaggingToolkit::formatTags($tags);
     $this->getTaggingCache()->addTagsToCache($key, $tags);
     return $this;
 }
예제 #6
0
 /**
  * Collection tag with its version
  *
  * @return array
  */
 public function getCollectionTags()
 {
     try {
         $name = sfCacheTaggingToolkit::obtainCollectionName($this->getTable());
         $version = sfCacheTaggingToolkit::obtainCollectionVersion($name);
         return array($name => $version);
     } catch (sfCacheDisabledException $e) {
         $this->notifyApplicationLog($e);
     }
     return array();
 }
 /**
  * Invalidate tags
  *
  * @param array $tags
  * @return null
  */
 public function invalidateTags(array $tags)
 {
     foreach ($tags as $name => $version) {
         $this->setTag($name, sfCacheTaggingToolkit::generateVersion());
     }
 }
예제 #8
0
 /**
  * pre dql delete hook - remove object tags from tagger
  *
  * @param Doctrine_Event $event
  * @return null
  */
 public function preDqlDelete(Doctrine_Event $event)
 {
     $taggingCache = null;
     try {
         $taggingCache = $this->getTaggingCache();
     } catch (sfCacheException $e) {
         return;
     }
     $table = $event->getInvoker()->getTable();
     /* @var $q Doctrine_Query */
     $q = clone $event->getQuery();
     /**
      * This happens, when SoftDelete is declared before Cachetaggable
      */
     if (Doctrine_Query::UPDATE === $q->getType()) {
         $event->getQuery()->set($this->getOption('versionColumn'), sfCacheTaggingToolkit::generateVersion());
         $q->removeDqlQueryPart('set');
     }
     $params = $q->getParams();
     $params['set'] = array();
     $q->setParams($params);
     $objects = $q->select()->execute();
     $unitOfWork = new Doctrine_Connection_CachetaggableUnitOfWork($q->getConnection());
     foreach ($objects as $object) {
         $unitOfWork->collectDeletionsAndInvalidations($object);
         $taggingCache->deleteTags($unitOfWork->getDeletions());
         $taggingCache->invalidateTags($unitOfWork->getInvalidations());
     }
     unset($unitOfWork);
     $taggingCache->setTag(sfCacheTaggingToolkit::getBaseClassName($table->getClassnameToReturn()), sfCacheTaggingToolkit::generateVersion());
 }
예제 #9
0
 public function getTargetSelectorChoices2($first, $second)
 {
     $tagging_cache = sfCacheTaggingToolkit::getTaggingCache();
     $cache_key = 'Petition_TS2_' . $this->getId() . '_' . (is_scalar($first) && is_scalar($second) ? $first . '__' . $second : md5(json_encode(array($first, $second))));
     $cached_ret = $tagging_cache->get($cache_key, null);
     if ($cached_ret !== null) {
         return $cached_ret;
     }
     $contacts = ContactTable::getInstance()->queryByTargetSelector($this, $first, $second)->execute();
     $pledge_table = PledgeTable::getInstance();
     $choices = array();
     $active_pledge_item_ids = $this->getActivePledgeItemIds();
     $pledge_info_columns = $this->getPledgeInfoColumnsArray();
     $pledges = $pledge_table->getPledgesForContacts($contacts, $active_pledge_item_ids);
     $infos = ContactTable::getInstance()->getPledgeInfoColumns($contacts, $pledge_info_columns);
     foreach ($contacts as $contact) {
         /* @var $contact Contact */
         $choices[$contact['id']] = $contact['firstname'] . ' ' . $contact['lastname'];
     }
     $ret = array('choices' => $choices, 'pledges' => $pledges, 'infos' => $infos);
     $tags = $this->getCacheTags();
     if ($this->getMailingListId()) {
         $tags = array_merge($tags, $this->getMailingList()->getCacheTags());
     }
     $tagging_cache->set($cache_key, $ret, 24 * 3600, $tags);
     return $ret;
 }
예제 #10
0
 /**
  * Retrieves sfTaggigCache object
  *
  * @return sfTaggigCache
  */
 protected function getTaggingCache()
 {
     return sfCacheTaggingToolkit::getTaggingCache();
 }
 /**
  * @see Doctrine_Connection_UnitOfWork::_cascadeDelete()
  *      (most part copy&past from)
  *
  * @param Doctrine_Record  The record for which the delete operation will be cascaded.
  * @throws PDOException    If something went wrong at database level
  * @return null
  */
 protected function cascade(Doctrine_Record $record)
 {
     foreach ($record->getTable()->getRelations() as $relation) {
         /* @var $relation Doctrine_Relation_LocalKey */
         # build-in Doctrine cascade mechanism do all the work - skip
         if ($relation->isCascadeDelete()) {
             continue;
         }
         $cascade = $relation->offsetGet('cascade');
         # no instructions, no results - skip
         if (0 == count($cascade)) {
             continue;
         }
         $isCascadeDeleteTags = in_array('deleteTags', $cascade);
         $isCascadeInvalidateTags = in_array('invalidateTags', $cascade);
         # could be only 1 selected, otherwise skip
         if (!($isCascadeDeleteTags xor $isCascadeInvalidateTags)) {
             continue;
         }
         if ($isCascadeDeleteTags) {
             $definitions =& $this->tagNamesToDelete;
         } else {
             $definitions =& $this->tagNamesToInvalidate;
         }
         $fieldName = $relation->getAlias();
         if ($relation->getType() != Doctrine_Relation::ONE || isset($record->{$fieldName})) {
             $record->refreshRelated($relation->getAlias());
         }
         $relatedObjects = $record->get($relation->getAlias());
         if ($relatedObjects instanceof Doctrine_Record && $relatedObjects->exists() && !isset($definitions[$relatedObjects->getOid()])) {
             # invalidate collection version too
             $collectionName = sfCacheTaggingToolkit::obtainCollectionName($relatedObjects->getTable());
             if ($isCascadeDeleteTags) {
                 $this->tagNamesToInvalidate[$collectionName] = $collectionName;
             } elseif ($isCascadeInvalidateTags) {
                 $template = $relatedObjects->getTable()->getTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME);
                 if ($template->getOption('invalidateCollectionVersionOnUpdate')) {
                     $this->tagNamesToInvalidate[$collectionName] = $collectionName;
                 }
             }
             $this->collect($relatedObjects, $definitions);
             continue;
         }
         if (!$relatedObjects instanceof Doctrine_Collection || count($relatedObjects) == 0 || !$relatedObjects->getTable()->hasTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME)) {
             continue;
         }
         # invalidate collection version too
         $collectionName = sfCacheTaggingToolkit::obtainCollectionName($relatedObjects->getTable());
         if ($isCascadeDeleteTags) {
             $this->tagNamesToInvalidate[$collectionName] = $collectionName;
         } elseif ($isCascadeInvalidateTags) {
             $template = $relatedObjects->getTable()->getTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME);
             if ($template->getOption('invalidateCollectionVersionOnUpdate')) {
                 $this->tagNamesToInvalidate[$collectionName] = $collectionName;
             }
         }
         foreach ($relatedObjects as $object) {
             if (isset($definitions[$object->getOid()])) {
                 continue;
             }
             $this->collect($object, $definitions);
         }
     }
 }