Skip to content

Commit

Permalink
feat: added BeforeResourceDeleted event
Browse files Browse the repository at this point in the history
  • Loading branch information
peetya committed Sep 14, 2023
1 parent 8647c2d commit eec4e5a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
48 changes: 48 additions & 0 deletions core/data/event/BeforeResourceDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
*/

namespace oat\generis\model\data\event;

use oat\oatbox\event\Event;

class BeforeResourceDeleted implements Event
{
private string $uri;

public function __construct(string $uri)
{
$this->uri = $uri;
}

public function getUri(): string
{
return $this->uri;
}

/**
* {@inheritdoc}
*/
public function getName(): string
{
return __CLASS__;
}
}
4 changes: 4 additions & 0 deletions core/resource/Repository/ResourceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace oat\generis\model\resource\Repository;

use oat\generis\model\data\event\BeforeResourceDeleted;
use RuntimeException;
use BadMethodCallException;
use InvalidArgumentException;
Expand Down Expand Up @@ -68,6 +69,9 @@ public function delete(ContextInterface $context): void
false
);

$beforeResourceDeletedEvent = new BeforeResourceDeleted($resource->getUri());
$this->eventManager->trigger($beforeResourceDeletedEvent);

if (!$this->getImplementation()->delete($resource, $deleteReference)) {
throw new RuntimeException(
sprintf(
Expand Down

0 comments on commit eec4e5a

Please sign in to comment.