protected function _postDelete() { //find related docs and delete them $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $rowsetRelatedDocs = $tblRelatedItem->fetchAll("relatedGuid='{$this->guid}' AND relateAs='RELATED_FILE'"); if (count($rowsetRelatedDocs)) { foreach ($rowsetRelatedDocs as $rowRelatedDoc) { $tblCatalog = new Kutu_Core_Orm_Table_Catalog(); $rowCatalog = $tblCatalog->find($rowRelatedDoc->itemGuid)->current(); $rowCatalog->delete(); } } if ($this->profileGuid == 'kutu_doc') { //get parentGuid $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $rowsetRelatedItem = $tblRelatedItem->fetchAll("itemGuid='{$this->guid}' AND relateAs='RELATED_FILE'"); if (count($rowsetRelatedItem)) { foreach ($rowsetRelatedItem as $rowRelatedItem) { //must delete the physical files $rowsetCatAtt = $this->findDependentRowsetCatalogAttribute(); $systemname = $rowsetCatAtt->findByAttributeGuid('docSystemName')->value; $parentGuid = $rowRelatedItem->relatedGuid; $sDir1 = KUTU_ROOT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $systemname; $sDir2 = KUTU_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 Kutu_Core_Orm_Table_CatalogAttribute(); $tblCatalogAttribute->delete("catalogGuid='{$this->guid}'"); //delete catalogGuid from table CatalogFolder $tblCatalogFolder = new Kutu_Core_Orm_Table_CatalogFolder(); $tblCatalogFolder->delete("catalogGuid='{$this->guid}'"); //delete guid from table AssetSetting $tblAssetSetting = new Kutu_Core_Orm_Table_AssetSetting(); $tblAssetSetting->delete("guid='{$this->guid}'"); //delete from table relatedItem $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $tblRelatedItem->delete("itemGuid='{$this->guid}'"); $tblRelatedItem->delete("relatedGuid='{$this->guid}'"); //delete from lucene index //check if guid exist in index, then delete // $indexEngine = new Kutu_Search_Index_Engine(); // $indexEngine->deleteCatalogFromIndex($this->guid); $registry = Zend_Registry::getInstance(); $conf = $registry->get('config'); $indexingEngine = Kutu_Search::manager(); try { $hits = $indexingEngine->deleteCatalogFromIndex($this->guid); } catch (Exception $e) { } /* $tblTmpIndex = new Kutu_Core_Orm_Table_TmpIndex(); $rowTmpIndex = $tblTmpIndex->fetchNew(); $rowTmpIndex->catalogGuid = $this->guid; $rowTmpIndex->status = 'delete'; $rowTmpIndex->save(); */ $tblTmpIndex = new Kutu_Core_Orm_Table_TmpIndex(); $tblTmpIndex->delete("catalogGuid='{$this->guid}'"); //delete physical catalog folder from uploads/files/[catalogGuid] $sDir = KUTU_ROOT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $this->guid; try { if (is_dir($sDir)) { rmdir($sDir); } } catch (Exception $e) { } $sDir = KUTU_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) { } //delete from ACL }
protected function _postDelete() { //find related docs and delete them $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $rowsetRelatedDocs = $tblRelatedItem->fetchAll("relatedGuid='{$this->guid}' AND relateAs='RELATED_FILE'"); if (count($rowsetRelatedDocs)) { foreach ($rowsetRelatedDocs as $rowRelatedDoc) { $tblCatalog = new Kutu_Core_Orm_Table_Catalog(); $rowCatalog = $tblCatalog->find($rowRelatedDoc->itemGuid)->current(); $rowCatalog->delete(); } } if ($this->profileGuid == 'kutu_doc') { //get parentGuid $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $rowsetRelatedItem = $tblRelatedItem->fetchAll("itemGuid='{$this->guid}' AND relateAs='RELATED_FILE'"); if (count($rowsetRelatedItem)) { foreach ($rowsetRelatedItem as $rowRelatedItem) { //must delete the physical files $rowsetCatAtt = $this->findDependentRowsetCatalogAttribute(); $systemname = $rowsetCatAtt->findByAttributeGuid('docSystemName')->value; $parentGuid = $rowRelatedItem->relatedGuid; $sDir1 = KUTU_ROOT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $systemname; $sDir2 = KUTU_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 Kutu_Core_Orm_Table_CatalogAttribute(); $tblCatalogAttribute->delete("catalogGuid='{$this->guid}'"); //delete catalogGuid from table CatalogFolder $tblCatalogFolder = new Kutu_Core_Orm_Table_CatalogFolder(); $tblCatalogFolder->delete("catalogGuid='{$this->guid}'"); //delete guid from table AssetSetting $tblAssetSetting = new Kutu_Core_Orm_Table_AssetSetting(); $tblAssetSetting->delete("guid='{$this->guid}'"); //delete from table relatedItem $tblRelatedItem = new Kutu_Core_Orm_Table_RelatedItem(); $tblRelatedItem->delete("itemGuid='{$this->guid}'"); $tblRelatedItem->delete("relatedGuid='{$this->guid}'"); //delete physical catalog folder from uploads/files/[catalogGuid] $sDir = KUTU_ROOT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $this->guid; try { if (is_dir($sDir)) { rmdir($sDir); } } catch (Exception $e) { } //delete from index try { $indexingEngine = Kutu_Search::manager(); $indexingEngine->deleteCatalogFromIndex($this->guid); } catch (Exception $e) { } //delete from ACL }
public function reIndexCatalog() { gc_enable(); $this->emptyIndex(); $time_start = microtime(true); $solr =& $this->_solr; $log = new Kutu_Log(); $formater = new Kutu_Lib_Formater(); $title = new Kutu_View_Helper_GetCatalogTitle(); // $tbl = new Kutu_Core_Orm_Table_Catalog(); // $rowset = $tbl->fetchAll(); //("profileGuid='kutu_peraturan'"); $query = "SELECT * FROM KutuCatalog"; $results = $this->_conn->query($query); $rowset = $results->fetchAll(PDO::FETCH_OBJ); $documents = array(); $rowCount = count($rowset); for ($iCount = 0; $iCount < $rowCount; $iCount++) { $row = $rowset[$iCount]; // if($iCount == 100) // break; // echo 'urutan: '.$iCount .'<br>'; $nextRow = $rowset[$iCount + 1]; // echo 'current guid: '.$row->guid.' '.'next guid: '.$nextRow->guid.'<br>'; if ($row->modifiedBy !== $row->createdBy) { $modified = '<font color=red>[modifiedBy:<i>' . $row->modifiedBy . '</i>]</font> '; } else { $modified = ''; } echo '<li><span style="font:11px verdana,arial,helvetica,sans-serif;">[urutan:' . $iCount . '] indexing:<font color=green>' . $title->getCatalogTitle($row->guid) . '</font>[current guid: ' . $row->guid . ' ' . 'next guid: ' . $nextRow->guid . '][author:<i>' . $row->createdBy . '</i>] ' . $modified . '[createdDate:<i>' . $formater->get_date($row->createdDate) . '</i>]</span></li>'; $documents[] = $this->_createSolrDocument($row); if ($iCount % 500 == 0) { try { $solr->addDocuments($documents); $solr->commit(); // $solr->optimize(); $documents = array(); } catch (Exception $e) { // echo "Error occured when processing record starting from number: ". ($iCount - 1000) . ' to '.$iCount.' '.$row->guid; $log->err($e->getMessage()); throw new Zend_Exception($e->getMessage()); // echo $e->getMessage().'<br>'; } } flush(); } echo '</ul></div></td></tr></table>'; try { $solr->addDocuments($documents); $solr->commit(); // $solr->optimize(); } catch (Exception $e) { $log->err($e->getMessage()); throw new Zend_Exception($e->getMessage()); // echo $e->getMessage().'<br>'; } $time_end = microtime(true); $time = $time_end - $time_start; // echo'<br>WAKTU EKSEKUSI: '. $time; $log->info("WAKTU EKSEKUSI: " . $time . " indexing catalog " . $iCount . " dari " . $rowCount . " " . $username); echo '<br><br><span style="font:11px verdana,arial,helvetica,sans-serif;color:#00FF00">WAKTU EKSEKUSI: ' . $time . '<br>indexing catalog ' . $iCount . ' dari ' . $rowCount . '</span>'; // log to assetSetting $tblAssetSetting = new Kutu_Core_Orm_Table_AssetSetting(); $rowAsset = $tblAssetSetting->fetchRow("application='INDEX CATALOG'"); if ($rowAsset) { $rowAsset->valueText = "Update {$rowCount} indexing-catalog at " . date("Y-m-d H:i:s") . $username; $rowAsset->valueInt = $rowAsset->valueInt + 1; } else { $gman = new Kutu_Core_Guid(); $catalogGuid = $gman->generateGuid(); $rowAsset = $tblAssetSetting->fetchNew(); $rowAsset->guid = $catalogGuid; $rowAsset->application = "INDEX CATALOG"; $rowAsset->part = "KUTU"; $rowAsset->valueType = "INDEX"; $rowAsset->valueInt = 0; $rowAsset->valueText = $rowCount . " Indexing catalog at " . date("Y-m-d H:i:s") . $username; } $rowAsset->save(); }