public static function updateTagRelationCache($manualLock = false) { if (!$manualLock) { self::checkTagRelationCache('lock'); } try { $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php"; $c = new Criteria(); $allTags = TagPeer::doSelect($c); $content = "<?php \n"; foreach ($allTags as $singleTag) { $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $singleTag->getId()); $tagRelations = TagrelationPeer::doSelect($c); if ($tagRelations) { $elementsArr = "array("; foreach ($tagRelations as $tagRelation) { $elementsArr .= $tagRelation->getId() . ","; } $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n"; } } $content .= "\n?>"; if (FileHelper::writeFile($tagRelationsFile, $content)) { BackendService::loadTagsRelations(); } else { echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR); } } catch (Exception $e) { echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR); } if (!$manualLock) { self::checkTagRelationCache('unlock'); } }
public static function getDocumentsByTag($tagId) { try { if (BackendService::loadTagsRelations()) { if (array_key_exists('tagsRelations', $_SESSION) && array_key_exists($tagId, $_SESSION['tagsRelations'])) { $docs = $_SESSION['tagsRelations'][$tagId]; } foreach ($docs as $docId) { $document = self::getDocumentInstance($docId); if ($document) { $documents[] = $document; } } } else { $c = new Criteria(); $c->add(TagPeer::TAG_ID, $tagId); $tag = TagPeer::doSelectOne($c); if (!$tag) { return null; } $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $tag->getId()); $tagRelations = TagrelationPeer::doSelect($c); $documents = array(); foreach ($tagRelations as $tagRelation) { $document = self::getDocumentInstance($tagRelation->getId()); if ($document) { $documents[] = $document; } } } return $documents; } catch (Exception $e) { return null; } }