Example #1
1
 protected function _postDelete()
 {
     //find related docs and delete them
     $tblRelatedItem = new App_Model_Db_Table_RelatedItem();
     $rowsetRelatedDocs = $tblRelatedItem->fetchAll("relatedGuid='{$this->guid}' AND relateAs IN ('RELATED_FILE','RELATED_IMAGE','RELATED_VIDEO')");
     if (count($rowsetRelatedDocs)) {
         foreach ($rowsetRelatedDocs as $rowRelatedDoc) {
             $tblCatalog = new App_Model_Db_Table_Catalog();
             $rowCatalog = $tblCatalog->find($rowRelatedDoc->itemGuid)->current();
             if ($rowCatalog) {
                 $rowCatalog->delete();
             }
         }
     }
     $registry = Zend_Registry::getInstance();
     $config = $registry->get(Pandamp_Keys::REGISTRY_APP_OBJECT);
     $cdn = $config->getOption('cdn');
     if ($this->profileGuid == 'kutu_doc') {
         //get parentGuid
         $tblRelatedItem = new App_Model_Db_Table_RelatedItem();
         $rowsetRelatedItem = $tblRelatedItem->fetchAll("itemGuid='{$this->guid}' AND relateAs IN ('RELATED_FILE','RELATED_IMAGE','RELATED_VIDEO')");
         if (count($rowsetRelatedItem)) {
             foreach ($rowsetRelatedItem as $rowRelatedItem) {
                 //must delete the physical files
                 $rowsetCatAtt = $this->findDependentRowsetCatalogAttribute();
                 $systemname = $rowsetCatAtt->findByAttributeGuid('docSystemName')->value;
                 $parentGuid = $rowRelatedItem->relatedGuid;
                 $sDir1 = $cdn['static']['dir']['files'] . DIRECTORY_SEPARATOR . $systemname;
                 $sDir2 = $cdn['static']['dir']['files'] . DIRECTORY_SEPARATOR . $parentGuid . DIRECTORY_SEPARATOR . $systemname;
                 //$sDir1 = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.$systemname;
                 //$sDir2 = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.$parentGuid.DIRECTORY_SEPARATOR.$systemname;
                 if (file_exists($sDir1)) {
                     //delete file
                     unlink($sDir1);
                 } else {
                     if (file_exists($sDir2)) {
                         //delete file
                         unlink($sDir2);
                     }
                 }
             }
         }
     }
     //delete from table CatalogAttribute
     $tblCatalogAttribute = new App_Model_Db_Table_CatalogAttribute();
     $tblCatalogAttribute->delete("catalogGuid='{$this->guid}'");
     //delete catalogGuid from table CatalogFolder
     $tblCatalogFolder = new App_Model_Db_Table_CatalogFolder();
     $tblCatalogFolder->delete("catalogGuid='{$this->guid}'");
     //delete guid from table AssetSetting
     $tblAssetSetting = new App_Model_Db_Table_AssetSetting();
     $tblAssetSetting->delete("guid='{$this->guid}'");
     //delete from table relatedItem
     $tblRelatedItem = new App_Model_Db_Table_RelatedItem();
     $tblRelatedItem->delete("itemGuid='{$this->guid}'");
     $tblRelatedItem->delete("relatedGuid='{$this->guid}'");
     $indexingEngine = Pandamp_Search::manager();
     try {
         $hits = $indexingEngine->deleteCatalogFromIndex($this->guid);
     } catch (Exception $e) {
     }
     //delete physical catalog folder from uploads/files/[catalogGuid]
     $sDir = $cdn['static']['dir']['files'] . DIRECTORY_SEPARATOR . $this->guid;
     //$sDir = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.$this->guid;
     try {
         if (is_dir($sDir)) {
             rmdir($sDir);
         }
     } catch (Exception $e) {
     }
     $sDir = $cdn['static']['dir']['images'];
     //$sDir = ROOT_DIR.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'images';
     try {
         if (file_exists($sDir . "/" . $this->guid . ".gif")) {
             unlink($sDir . "/" . $this->guid . ".gif");
         }
         if (file_exists($sDir . "/tn_" . $this->guid . ".gif")) {
             unlink($sDir . "/tn_" . $this->guid . ".gif");
         }
         if (file_exists($sDir . "/" . $this->guid . ".jpg")) {
             unlink($sDir . "/" . $this->guid . ".jpg");
         }
         if (file_exists($sDir . "/tn_" . $this->guid . ".jpg")) {
             unlink($sDir . "/tn_" . $this->guid . ".jpg");
         }
         if (file_exists($sDir . "/" . $this->guid . ".jpeg")) {
             unlink($sDir . "/" . $this->guid . ".jpeg");
         }
         if (file_exists($sDir . "/tn_" . $this->guid . ".jpeg")) {
             unlink($sDir . "/tn_" . $this->guid . ".jpeg");
         }
         if (file_exists($sDir . "/" . $this->guid . ".png")) {
             unlink($sDir . "/" . $this->guid . ".png");
         }
         if (file_exists($sDir . "/tn_" . $this->guid . ".png")) {
             unlink($sDir . "/tn_" . $this->guid . ".png");
         }
     } catch (Exception $e) {
     }
 }