Beispiel #1
0
 public function delete($con = null)
 {
     $originalCacheRelations = sfConfig::get('sf_cache_relations');
     sfConfig::set('sf_cache_relations', false);
     try {
         $docId = $this->getId();
         $con = Propel::getConnection();
         $con->begin();
         // delete child relation
         $c = new Criteria();
         $c->add(RelationPeer::ID2, $docId);
         $relations = RelationPeer::doSelect($c);
         foreach ($relations as $relation) {
             $relation->delete(null, sfConfig::get('sf_cache_relations'));
             //$relation->delete();
         }
         // delete parent relations
         $children = Document::getChildrenOf($docId);
         foreach ($children as $child) {
             $relation = new Relation();
             $relation->setId1($docId);
             $relation->setId2($child->getId());
             $child->delete();
             $relation->delete();
         }
         // delete any tags for this document
         $c = new Criteria();
         $c->add(TagrelationPeer::ID, $docId);
         $tagRelations = TagrelationPeer::doSelect($c);
         foreach ($tagRelations as $tag) {
             $tag->delete();
         }
         parent::delete();
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
     // set 'sf_cache_relations' it's original value
     sfConfig::set('sf_cache_relations', $originalCacheRelations);
     if ($originalCacheRelations) {
         Relation::updateRelationCache();
     }
     return true;
 }
Beispiel #2
0
 public function executeDelete()
 {
     if ($user = $this->getUser()->getSubscriber()) {
         $userType = $user->getType();
     }
     if ($selectedDocuments = $this->getRequestParameter("selectedDocuments")) {
         sfConfig::set('sf_cache_relations', false);
         $selectedDocuments = explode(",", $selectedDocuments);
         foreach ($selectedDocuments as $docId) {
             $document = Document::getDocumentInstance($docId);
             if ($document) {
                 if ($userType != "admin") {
                     $class = get_class($document);
                     if ($class == "Lists" && $document->getListType() == "system") {
                         $alert = "no_delete";
                         continue;
                     } else {
                         if ($class == "Listitem") {
                             if ($parent = Document::getParentOf($document->getId())) {
                                 if ($parent->getListType() == "system") {
                                     $alert = "no_delete";
                                     continue;
                                 }
                             }
                         }
                     }
                 }
                 $document->delete();
             }
         }
         sfConfig::set('sf_cache_relations', true);
         Relation::updateRelationCache($this->getRequestParameter("p"));
     } else {
         $document = Document::getDocumentInstance($this->getRequestParameter('id'));
         if ($document) {
             $class = get_class($document);
             if ($userType != "admin") {
                 if ($class == "Lists" && $document->getListType() == "system") {
                     $alert = "no_delete";
                 } else {
                     if ($class == "Listitem") {
                         if ($parent = Document::getParentOf($document->getId())) {
                             if ($parent->getListType() == "system") {
                                 $alert = "no_delete";
                             }
                         }
                     }
                 }
             }
             if ($alert != "no_delete") {
                 $document->delete();
             }
         }
     }
     exit($alert);
 }
Beispiel #3
0
 public function executeChangeOrder()
 {
     exec('rm -fr ' . SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'menus/*');
     $items = $this->getRequestParameter('item');
     $c = new Criteria();
     $c->addAscendingOrderByColumn(RelationPeer::SORT_ORDER);
     $c->add(RelationPeer::ID2, $items, Criteria::IN);
     $arr = RelationPeer::doSelect($c);
     $order = array();
     foreach ($arr as $ind => $obj) {
         $parentId = $obj->getId1();
         $order[$items[$ind]] = $obj->getSortOrder();
     }
     foreach ($arr as &$obj) {
         $obj->setSortOrder($order[$obj->getId2()]);
         $obj->save();
     }
     if ($parentId) {
         Relation::updateRelationCache($parentId);
     }
     exit("OK");
 }