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 function delete($con = null) { try { $con = Propel::getConnection(); $con->begin(); Document::getGenericDocument($this)->delete(); parent::delete(); $con->commit(); Document::deleteObjCache($this); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function save($con = null) { try { $con = Propel::getConnection(); $con->begin(); if (!$this->getId()) { $this->setId(Document::getGenericDocument($this)->getId()); } parent::save($con); $con->commit(); Document::cacheObj($this, get_class($this)); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function delete($con = null) { try { $con = Propel::getConnection(); $con->begin(); //deletes generic document $genericDocument = Document::getGenericDocument($this); $genericDocument->delete(); parent::delete(); $con->commit(); Document::deleteObjCache($this); // remove list cache Lists::deleteListCache($this->getListId()); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function executeSetPublicationStatus() { $items = explode(",", $this->getRequestParameter('items')); $status = $this->getRequestParameter('status'); try { foreach ($items as $item) { $genericDocument = Document::getGenericDocument($item); $item = Document::getDocumentInstance($item); if ($genericDocument) { $genericDocument->setPublicationStatus($status); $genericDocument->save(); Document::cacheObj($item, null, true); } } } catch (Exception $e) { exit("A probleme occured: " . $e->getMessage()); } exit("OK"); }
</td> </tr> <div id="actionDiv"> <div id="actionDivHead"> <a onclick="$('#actionDiv').fadeOut();">close <img align="absmiddle" src="/images/icons/delete.png"></a> </div> <div id="actionDivContent"></div> </div> <?php foreach ($children as $child) { //if($filter && (!Document::checkOwner($child->getId()))) continue; $label = $child->getLabel(); $id = $child->getId(); $modelUp = get_class($child); $model = strtolower($modelUp); $status = strtolower(Document::getGenericDocument($child)->getPublicationStatus()); $i18nEls = BackendService::getLanguageBar($id, $sf_params->get("modulename")); ?> <tr> <td class="noborder"> <img src="/images/icons/status_<?php echo $status; ?> .png" border="0"> </td> <td> <?php echo $id; ?> </td> <td onclick="addToSelected(<?php
public static function indexDocument($id) { ini_set("memory_limit", "2048M"); try { $search_config_file = SF_ROOT_DIR . '/config/search.xml'; $documents = simplexml_load_file($search_config_file); $document_instance = Document::getDocumentInstance($id); $document_name = get_class($document_instance); $search_index_path = SF_ROOT_DIR . '/cache/search/' . strtolower($document_name); $search_index = Zend_Search_Lucene::open($search_index_path); $common_field_val = ""; $search_doc = new Zend_Search_Lucene_Document(); $genDoc = Document::getGenericDocument($id); if ($genDoc) { $date = $genDoc->getCreatedAt(); } foreach ($documents as $document) { $docClass = $document->attributes(); if ($document_name == $docClass) { $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_id', $id, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_date', $date, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Text('document_label', $document_instance->getLabel(), 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_type', $document_name, 'utf-8')); /* if(substr($document_name, -4) == "I18n") { $search_doc->addField(Zend_Search_Lucene_Field::Keyword('Culture', $document_instance->getCulture(), 'utf-8')); }*/ foreach ($document as $field_name) { $attr = get_object_vars($field_name); $attributes = $attr['@attributes']; $getFunction = 'get' . $attributes['name']; $fieldContent = ""; if ($attributes['linked']) { $getFunctionLinked = 'get' . $attributes['linked']; $linkedObj = Document::getDocumentInstance($document_instance->{$getFunction}()); if ($linkedObj) { $fieldContent = $linkedObj->{$getFunctionLinked}(); } } else { $fieldContent = $document_instance->{$getFunction}(); } $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['name'], $fieldContent, 'utf-8')); } $search_index->addDocument($search_doc); $search_index->commit(); //$search_index->optimize(); } } } catch (Exception $e) { FileHelper::Log("INDEXING > Error wile adding document " . $id . " | " . $e->getMessage(), UtilsHelper::MSG_ERROR); throw $e; } /* try { $doc = Document::getDocumentInstance($id); $docClass = get_class($doc); $search_config_file = sfConfig::get('sf_root_dir').'/config/search.xml'; $documents = simplexml_load_file($search_config_file); $index_path = sfConfig::get('sf_root_dir').'/cache/search/'.strtolower($docClass); $search_index = Zend_Search_Lucene::open($index_path); //if($doc && ($doc->getPublicationStatus() == UtilsHelper::STATUS_ACTIVE) && ($docClass == "User" && in_array($docFrontType, $userArr))) { foreach ($documents as $document) { $document_name = $document->attributes(); if($document_name == $docClass) { $common_field_val = null; $profile = $profiles[$docFrontType]; $search_doc = new Zend_Search_Lucene_Document(); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_id', $id,'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_label', $doc->getLabel(),'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_type', $document_name,'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Text('Description', $doc->getDescription(), 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::Keyword('document_url', "")); foreach ($document as $field_name) { $attr = get_object_vars($field_name); $attributes = $attr['@attributes']; $getFunction = 'get'.$attributes['name']; $fieldContent = null; if($attributes['linked']) { $getFunctionLinked = 'get'.$attributes['linked']; $linkedObj = self::getDocumentInstance($doc->$getFunction()); if($linkedObj) $fieldContent = $linkedObj->$getFunctionLinked(); } else { $fieldContent = $doc->$getFunction(); } if($attributes['setTo']) { $common_field_val .= $fieldContent; } else { $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['name'], $fieldContent, 'utf-8')); } } if($attributes['setTo']) { $pattern1 = '/[^a-zA-Z0-9 ]/'; $pattern2 = '/ .{1,2} /'; $replacement = ''; $replacement2 = ' '; $common_field_val = preg_replace($pattern1, $replacement, $common_field_val); $common_field_val = preg_replace($pattern2, $replacement2, $common_field_val); $search_doc->addField(Zend_Search_Lucene_Field::Text($attributes['setTo'], $common_field_val, 'utf-8')); } $search_index->addDocument($search_doc); } } } $search_index->commit(); } catch (Exception $e) { FileHelper::Log("INDEXING -> Error wile adding document ".$id." | ".$e->getMessage(), UtilsHelper::MSG_ERROR ); }*/ }
public function setRewriteUrl($value) { try { if (!$this->getId()) { $this->setId(Document::getGenericDocument($this)->getId()); } $con = Propel::getConnection(); $con->begin(); // $rewriteUrl = UrlrewritePeer::retrieveByPk($value); $c = new Criteria(); $c->add(UrlrewritePeer::PAGE_ID, $this->getId()); $rewriteUrl = UrlrewritePeer::doSelectOne($c); //$rewriteUrl = Document::getDocumentInstance($value); $value = trim($value); if ($rewriteUrl) { if ($value != '') { $value = Urlrewrite::checkRewriteUrl($value, $this->getId()); $rewriteUrl->setLabel($value); $rewriteUrl->save(null, $this); } else { if ($value == '') { $rewriteUrl->delete(); } } } else { if ($value) { $value = Urlrewrite::checkRewriteUrl($value, $this->getId()); $rewriteUrl = new Urlrewrite(); $rewriteUrl->setLabel($value); $rewriteUrl->setPageId($this->getId()); $rewriteUrl->save(null, $this); } } $con->commit(); return true; } catch (Exception $e) { $con->rollback(); throw $e; } return true; }
public static function updateTree($moduleName, $document, $action = "UPDATE", $tree = "left") { if ($moduleName == 'admin') { $moduleName = 'tag'; } $moduleName = ucfirst($moduleName); /*if($tree == "right") { $phpFile = sfConfig::get('sf_root_dir')."/cache/backend/".$moduleName."_rightTree.php"; } else*/ if ($tree == "mce") { $phpFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.php"; // TEMPORARY FIX if ($tree == "mce" && $action == "DELETE") { unlink($phpFile); } } else { $phpFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_Tree.php"; } // if Tree cache file doesn't exists -> exit! if (!is_readable($phpFile)) { return; } include $phpFile; $docId = $document->getId(); if ($action == "DOWN" && $contentArray[$docId]) { $docStart = $docEnd = $nextStart = $nextEnd = -1; $docLevel = $contentArray[$docId]['level']; // Finding where DOC block starts $i = 0; foreach ($contentArray as $k => $v) { if ($k == $docId) { $docStart = $i; break; } $i++; } // Finding where NEXT block starts $i = 0; foreach ($contentArray as $k => $v) { if ($nextStart < 0 && $contentArray[$k]['level'] == $docLevel) { if ($i > $docStart) { $nextStart = $i; break; } } $i++; } // Finding where DOC block ends $i = 0; foreach ($contentArray as $k => $v) { if ($docEnd >= 0) { if ($contentArray[$k]['level'] > $docLevel) { $docEnd = $i; } else { break; } } if ($i == $docStart) { $docEnd = $i; } $i++; } // Finding where NEXT block ends $i = 0; foreach ($contentArray as $k => $v) { if ($nextEnd >= 0) { if ($contentArray[$k]['level'] > $docLevel) { $nextEnd = $i; } else { break; } } if ($i == $nextStart) { $nextEnd = $i; } $i++; } //=============================================================== if ($nextEnd >= 0) { $docArr = array_slice($contentArray, $docStart, $docEnd - $docStart + 1); $nextArr = array_slice($contentArray, $nextStart, $nextEnd - $nextStart + 1); $start = array_slice($contentArray, 0, $docStart); $last = array_slice($contentArray, $nextEnd); $contentArray = array_merge($start, array_merge($nextArr, array_merge($docArr, $last))); } } elseif ($action == "UP" && in_array($docId, $contentArray)) { $docStart = $docEnd = $prevStart = $prevEnd = -1; $docLevel = $contentArray[$docId]['level']; // Finding where DOC block starts $i = 0; foreach ($contentArray as $k => $v) { if ($k == $docId) { $docStart = $i; break; } $i++; } // Finding where PREV block starts $i = 0; foreach ($contentArray as $k => $v) { if ($contentArray[$k]['level'] == $docLevel) { if ($i < $docStart) { $prevStart = $i; } } $i++; } // Finding where DOC block ends $i = 0; foreach ($contentArray as $k => $v) { if ($docEnd >= 0) { if ($contentArray[$k]['level'] > $docLevel) { $docEnd = $i; } else { break; } } if ($i == $docStart) { $docEnd = $i; } $i++; } // Finding where PREV block ends $i = 0; foreach ($contentArray as $k => $v) { if ($prevEnd >= 0) { if ($contentArray[$k]['level'] > $docLevel) { $prevEnd = $i; } else { break; } } if ($i == $prevStart) { $prevEnd = $i; } $i++; } //=============================================================== if ($prevStart >= 0) { $docArr = array_slice($contentArray, $docStart, $docEnd - $docStart + 1); $prevArr = array_slice($contentArray, $prevStart, $prevEnd - $prevStart + 1); $start = array_slice($contentArray, 0, $prevStart); $last = array_slice($contentArray, $docEnd); $contentArray = array_merge($start, array_merge($docArr, array_merge($prevArr, $last))); } } elseif ($action == "DELETE") { // if document not in the Tree -> exit! if (!in_array($docId, $contentArray)) { return; } $newArray = array(); $level = $contentArray[$docId]['level']; $deleteRest = false; foreach ($contentArray as $k => $v) { if ($k == $docId) { //unset($contentArray[$k]); $deleteRest = true; } elseif ($deleteRest && $contentArray[$k]['level'] <= $level) { $deleteRest = false; } if (!$deleteRest) { $newArray[$k] = $contentArray[$k]; } } $contentArray = $newArray; } else { if (array_key_exists($docId, $contentArray)) { $contentArray[$docId]['label'] = addslashes($document->getLabel()); $contentArray[$docId]['status'] = Document::getGenericDocument($document)->getPublicationStatus(); } else { $parent = Document::getParentOf($docId, null, true, false); if ($parent) { $parentId = $parent->getId(); } // if document not in the Tree -> exit! $oldContentArray = $contentArray; $first = array_shift($oldContentArray); if (array_key_exists('treeParent', $first) && $first['treeParent'] == $first['id'] && !$contentArray[$parentId]) { return; } else { if (!$contentArray[$parentId]) { $parentId = $first['id']; } } $lmn = strtolower($moduleName); $lmn2 = $lmn; if ($lmn2 == "tag") { $lmn2 = "admin"; } $leftTree = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/modules/" . $lmn2 . "/config/" . $tree . "Tree.xml"); $displayedObjects = array(); foreach ($leftTree as $obj) { if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') { $displayedObjects[] = $obj['value']; } } if (!in_array(get_class($document), $displayedObjects)) { return null; } $docModel = get_class($document); $newItem = array(); $newItem[$docId]['id'] = $docId; $newItem[$docId]['parent'] = $parentId; $newItem[$docId]['model'] = $docModel; $newItem[$docId]['class'] = $lmn . '_' . strtolower($newItem[$docId]['model']); $newItem[$docId]['label'] = addslashes($document->getLabel()); $newItem[$docId]['level'] = $contentArray[$parentId]['level'] + 1; if ($docModel == "Media") { $newItem[$docId]['image'] = $document->isImage(); } $newItem[$docId]['status'] = Document::getGenericDocument($document)->getPublicationStatus(); $position = 0; $level = -1; foreach ($contentArray as $k => $v) { if ($level >= 0) { if ($contentArray[$k]['level'] > $level) { // } else { break; } } if ($k == $parentId) { // get level of the Parent object $level = $contentArray[$k]['level']; } $position++; } $leftArr = array_slice($contentArray, 0, $position); $rightArr = array_slice($contentArray, $position); $contentArray = array_merge($leftArr, array_merge($newItem, $rightArr)); } } /*if($tree == "right") { self::makePhpCache($contentArray, $moduleName, "right"); } else*/ if ($tree == "mce") { self::makePhpCache($contentArray, $moduleName, "mce"); } else { self::makePhpCache($contentArray, $moduleName, "left"); } }
public function delete($con = null) { $file = $this->getServerAbsoluteUrl(); $thumb = $this->getServerAbsoluteThumbUrl(); $filedeleted = true; $thumbdeleted = true; if (file_exists($file)) { $filedeleted = unlink($file); } if (file_exists($thumb)) { $thumbdeleted = unlink($thumb); } if (!$filedeleted) { FileHelper::Log("\tError: file '" . $file . "' could not be deleted!"); } try { $con = Propel::getConnection(); $con->begin(); //deletes generic document $genericDocument = Document::getGenericDocument($this); if ($genericDocument) { $genericDocument->delete(); } $con->commit(); Document::deleteObjCache($this); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }