Skip to content

Commit

Permalink
#290 Support for DocumentLifecycleListener
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Aug 9, 2022
1 parent 5339e54 commit b7a0e4b
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions library/Opus/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2014-2020, OPUS 4 development team
* @copyright Copyright (c) 2014, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* @category Framework
Expand All @@ -46,6 +46,7 @@
use Opus\Common\Config;
use Opus\Common\Date;
use Opus\Common\DocumentInterface;
use Opus\Common\Model\DocumentLifecycleListener;
use Opus\Common\Model\ModelException;
use Opus\Common\ServerStateConstantsInterface;
use Opus\Common\Storage\FileNotFoundException;
Expand Down Expand Up @@ -227,6 +228,11 @@ class Document extends AbstractDb implements DocumentInterface, ServerStateConst

private static $defaultPlugins;

/**
* @var DocumentLifecycleListener
*/
private $documentLifecycleListener = null;

/**
* Plugins to load
*
Expand Down Expand Up @@ -479,6 +485,8 @@ public function setDefaultPlugins($plugins)
*/
protected function init()
{
$this->documentLifecycleListener = new DocumentLifecycleListener();

$fields = [
'BelongsToBibliography',
'CompletedDate',
Expand Down Expand Up @@ -1025,22 +1033,8 @@ protected function _preStore()
{
$result = parent::_preStore();

$date = new Date();
$date->setNow();
if (true === $this->isNewRecord()) {
if ($this->getServerDateCreated() === null) {
$this->setServerDateCreated($date);
}
}
$this->setServerDateModified($date);

if (true === $this->isNewRecord() || true === $this->isModified()) {
// Initially set ServerDatePublished if ServerState==='published'
if ($this->getServerState() === 'published') {
if ($this->getServerDatePublished() === null) {
$this->setServerDatePublished($date);
}
}
if ($this->documentLifecycleListener !== null) {
$this->documentLifecycleListener->preStore($this);
}

return $result;
Expand Down Expand Up @@ -1403,4 +1397,14 @@ public function getModelType()
{
return 'document';
}

/**
* @param DocumentLifecycleListener $listener
*
* TODO LAMINAS temporary hack to start separating database code from workflow event handling (business logic)
*/
public function setLifecycleListener($listener)
{
$this->documentLifecycleListener = $listener;
}
}

0 comments on commit b7a0e4b

Please sign in to comment.