/** * Format passed tags to the array * * @param mixed $argument false|array|Doctrine_Collection_Cachetaggable| * Doctrine_Record|ArrayIterator|Doctrine_Table * IteratorAggregate|Iterator * @throws InvalidArgumentException * @return array */ public static function formatTags($argument) { $tagsToReturn = null; if (false === $argument) { $tagsToReturn = array(); } elseif ($argument instanceof Doctrine_Table) { $name = sfCacheTaggingToolkit::obtainCollectionName($argument); $version = sfCacheTaggingToolkit::obtainCollectionVersion($name); $tagsToReturn = array($name => $version); } elseif (is_array($argument)) { $tagsToReturn = $argument; } elseif ($argument instanceof Doctrine_Collection_Cachetaggable) { $tagsToReturn = $argument->getCacheTags(); } elseif ($argument instanceof Doctrine_Record) { $table = $argument->getTable(); if (!$table->hasTemplate(self::TEMPLATE_NAME)) { throw new InvalidArgumentException(sprintf('Object "%s" should have the "%s" template', $table->getClassnameToReturn(), self::TEMPLATE_NAME)); } $tagsToReturn = $argument->getCacheTags(); } elseif ($argument instanceof ArrayIterator || $argument instanceof ArrayObject) { $tagsToReturn = $argument->getArrayCopy(); } elseif ($argument instanceof IteratorAggregate || $argument instanceof Iterator) { foreach ($argument as $key => $value) { $tagsToReturn[$key] = $value; } } else { throw new InvalidArgumentException(sprintf('Invalid argument\'s type "%s". ' . 'See acceptable types in the PHPDOC of "%s"', sprintf('%s%s', gettype($argument), is_object($argument) ? '(' . get_class($argument) . ')' : ''), __METHOD__)); } return $tagsToReturn; }
/** * Collections tag name * * @return string */ public function obtainCollectionName() { $invoker = $this->getInvoker(); return sfCacheTaggingToolkit::obtainCollectionName($invoker->getTable()); }
/** * 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(); }
/** * @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); } } }