public function delete($con = null) { try { $con = Propel::getConnection(); $con->begin(); //deletes generic document $genericDocument = Document::getGenericDocument($this); $genericDocument->delete(); //deletes any tags for this document $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $this->getId()); $tagRelations = TagrelationPeer::doSelect($c); foreach ($tagRelations as $tag) { $tag->delete(); } parent::delete(); $con->commit(); if (sfConfig::get('sf_cache_relations')) { Tagrelation::updateTagRelationCache(); } Document::deleteObjCache($this); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
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'); } }
function run_tags_relations($task, $args) { ini_set("memory_limit", "2048M"); define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', false); sfConfig::set("sf_use_relations_cache", false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); echo_cms_title("GENERATING TAGS RELATION CACHE..."); //if(!class_exists("XMLParser")) include sfConfig::get('sf_root_dir')."/lib/tools/XMLParser.class.php"; if (!class_exists("FileHelper")) { include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php"; } //echo_cms_sep(); $tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php"; try { $c = new Criteria(); $allTags = TagPeer::doSelect($c); //echo_cms("Processing tags :"); $i = 0; $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() . ","; $i++; } $content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n"; } } echo " ====> " . $i . " tags cached\n"; $content .= "\n?>"; if (FileHelper::writeFile($tagRelationsFile, $content)) { echo_cms($tagRelationsFile . " Written successfully"); } else { echo_cms_error("Error writing " . $tagRelationsFile . " !"); } //echo_cms_sep(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } sfConfig::set("sf_use_relations_cache", true); //echo_cms_sep(); }
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = TagrelationPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setTagId($arr[$keys[1]]); } }
public static function retrieveByPK($id, $tag_id, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $criteria = new Criteria(); $criteria->add(TagrelationPeer::ID, $id); $criteria->add(TagrelationPeer::TAG_ID, $tag_id); $v = TagrelationPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
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; } }