From 93380ab261c042c6ed128ff47f338bb890f16f1d Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Sat, 24 Jun 2017 07:15:37 +0200 Subject: [PATCH] add hook on(Pre|Post)RemoveContent --- SeedDMS_Core/Core/inc.ClassDocument.php | 44 ++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index d89a3fe9c..423313670 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -1271,7 +1271,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ /* $attribute can be a string or an array */ if($attribute) if(!$content->setAttributeValue($this->_dms->getAttributeDefinition($attrdefid), $attribute)) { - $this->removeContent($content); + $this->_removeContent($content); $db->rollbackTransaction(); return false; } @@ -1285,7 +1285,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ $queryStr = "INSERT INTO `tblDocumentStatus` (`documentID`, `version`) ". "VALUES (". $this->_id .", ". (int) $version .")"; if (!$db->getResult($queryStr)) { - $this->removeContent($content); + $this->_removeContent($content); $db->rollbackTransaction(); return false; } @@ -1512,7 +1512,13 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return $this->_latestContent; } /* }}} */ - function removeContent($version) { /* {{{ */ + /** + * Remove version of document + * + * @param interger $version version number of content + * @return boolean true if successful, otherwise false + */ + private function _removeContent($version) { /* {{{ */ $db = $this->_dms->getDB(); if (file_exists( $this->_dms->contentDir.$version->getPath() )) @@ -1623,6 +1629,36 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ return true; } /* }}} */ + /** + * Call callback onPreRemoveDocument before deleting content + * + * @param integer $version version number of content + */ + function removeContent($version) { /* {{{ */ + /* Check if 'onPreRemoveDocument' callback is set */ + if(isset($this->_dms->callbacks['onPreRemoveContent'])) { + foreach($this->_dms->callbacks['onPreRemoveContent'] as $callback) { + $ret = call_user_func($callback[0], $callback[1], $this, $version); + if(is_bool($ret)) + return $ret; + } + } + + if(false === ($ret = self::_removeContent($version))) { + return false; + } + + /* Check if 'onPostRemoveDocument' callback is set */ + if(isset($this->_dms->callbacks['onPostRemoveContent'])) { + foreach($this->_dms->callbacks['onPostRemoveContent'] as $callback) { + if(!call_user_func($callback[0], $callback[1], $version)) { + } + } + } + + return $ret; + } /* }}} */ + /** * Return a certain document link * @@ -1874,7 +1910,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ // remove content of document foreach ($this->_content as $version) { - if (!$this->removeContent($version)) { + if (!$this->_removeContent($version)) { $db->rollbackTransaction(); return false; }