示例#1
0
 /**
  * pre dql update hook - add updated
  *
  * @param Doctrine_Event $event
  * @return null
  */
 public function preDqlUpdate(Doctrine_Event $event)
 {
     $taggingCache = null;
     try {
         $taggingCache = $this->getTaggingCache();
     } catch (sfCacheException $e) {
         return;
     }
     /* @var $q Doctrine_Query */
     $q = $event->getQuery();
     $columnsToModify = array();
     foreach ($q->getDqlPart('set') as $set) {
         $matches = null;
         /**
          * Replace cases:
          *   Catalogue.is_visible = 1   => is_visible
          *   is_visible = -1            => is_visible
          */
         if (preg_match('/(\\w+)\\ =\\ /', $set, $matches)) {
             $columnsToModify[] = $matches[1];
         }
     }
     if ($this->isModifiedInSkipList($columnsToModify)) {
         return false;
     }
     $table = $event->getInvoker()->getTable();
     $collectionVersionName = sfCacheTaggingToolkit::getBaseClassName($table->getClassnameToReturn());
     /**
      * @todo test, not coveraged (SoftDelete everywhere is after Cachetaggable
      */
     if ($this->isModifiedIsASoftDeleteColumn($columnsToModify, $table)) {
         # invalidate collection, if soft delete sets deleted_at field
         $taggingCache->setTag($collectionVersionName, sfCacheTaggingToolkit::generateVersion());
     }
     $updateVersion = sfCacheTaggingToolkit::generateVersion();
     $q->set($this->getOption('versionColumn'), $updateVersion);
     $selectQuery = $table->createQuery();
     $selectQuery->select();
     $where = trim(implode(' ', $q->getDqlPart('where')));
     if (!empty($where)) {
         $selectQuery->addWhere($where);
     }
     $params = $q->getParams();
     $params['set'] = array();
     $selectQuery->setParams($params);
     $tags = array();
     $template = $table->getTemplate(sfCacheTaggingToolkit::TEMPLATE_NAME);
     foreach ($selectQuery->fetchArray() as $objectArray) {
         $tagName = sfCacheTaggingToolkit::obtainTagName($template, $objectArray);
         $tags[$tagName] = $updateVersion;
     }
     $taggingCache->setTags($tags);
     $isToInvalidateCollectionVersion = (bool) $this->getOption('invalidateCollectionVersionOnUpdate');
     if (!$isToInvalidateCollectionVersion) {
         if ($this->isModifiedAffectsCollectionVersion($columnsToModify)) {
             $isToInvalidateCollectionVersion = true;
         }
     }
     if ($isToInvalidateCollectionVersion) {
         $taggingCache->setTag($collectionVersionName, sfCacheTaggingToolkit::generateVersion());
     }
 }
示例#2
0
 /**
  * Retrieves object unique tag name based on its class
  *
  * @throws InvalidArgumentException
  * @return string
  */
 public function obtainTagName()
 {
     $invoker = $this->getInvoker();
     /**
      * Allow to generete tags for new objects - it could already have required
      * values to generate valid key
      *
      * One difference, getData could returns (objects) inside array
      */
     $objectArray = $invoker->isNew() ? $invoker->getData() : $invoker->toArray(false);
     return sfCacheTaggingToolkit::obtainTagName($this, $objectArray);
 }