Skip to content

Commit

Permalink
feat: Install process, return type fix, missing end lines
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejmarszal committed Jul 21, 2021
1 parent 67d5ef8 commit 2f93ccc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
4 changes: 3 additions & 1 deletion manifest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use oat\taoDacSimple\scripts\install\AttachEventHandler;
use oat\taoDacSimple\scripts\update\Updater;

/**
Expand Down Expand Up @@ -40,7 +41,8 @@
'install' => [
'php' => [
SetupDataAccess::class,
RegisterAction::class
RegisterAction::class,
AttachEventHandler::class
],
'rdf' => [
__DIR__ . '/model/ontology/dac.rdf',
Expand Down
50 changes: 50 additions & 0 deletions migrations/Version202107121456123210_taoDacSimple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace oat\taoDacSimple\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\oatbox\event\EventManager;
use oat\tao\model\event\ResourceMovedEvent;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\taoDacSimple\model\eventHandler\ResourceUpdateHandler;

final class Version202107121456123210_taoDacSimple extends AbstractMigration
{

public function getDescription(): string
{
return 'Attach ResourceMovedEvent handler';
}

public function up(Schema $schema): void
{
/** @var EventManager $eventManager */
$eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID);
$eventManager->attach(
ResourceMovedEvent::class,
[
ResourceUpdateHandler::class,
'catchResourceUpdated'
]

);
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager);
}

public function down(Schema $schema): void
{
/** @var EventManager $eventManager */
$eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID);
$eventManager->detach(
ResourceMovedEvent::class,
[
ResourceUpdateHandler::class,
'catchResourceUpdated'
]

);
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager);
}
}
6 changes: 4 additions & 2 deletions model/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public function saveResourcePermissionsRecursive(
$this->saveResourcePermissions($resource, $privilegesToSet, true);
}

private function saveResourcePermissions(core_kernel_classes_Resource $resource, array $privilegesToSet, bool $isRecursive)
{
private function saveResourcePermissions(
core_kernel_classes_Resource $resource,
array $privilegesToSet, bool $isRecursive
): void {
$currentPrivileges = $this->dataBaseAccess->getResourcePermissions($resource->getUri());
$addRemove = $this->strategy->normalizeRequest($currentPrivileges, $privilegesToSet);

Expand Down
46 changes: 46 additions & 0 deletions scripts/install/AttachEventHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* 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) 2021 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoDacSimple\scripts\install;


use oat\oatbox\event\EventManager;
use oat\oatbox\extension\InstallAction;
use oat\tao\model\event\ResourceMovedEvent;
use oat\taoDacSimple\model\eventHandler\ResourceUpdateHandler;

class AttachEventHandler extends InstallAction
{
public function __invoke($params)
{
$eventManager = $this->getServiceManager()->get(EventManager::SERVICE_ID);
$eventManager->attach(
ResourceMovedEvent::class,
[
ResourceUpdateHandler::class,
'catchResourceUpdated'
]

);
$this->getServiceManager()->register(EventManager::SERVICE_ID, $eventManager);
}
}

0 comments on commit 2f93ccc

Please sign in to comment.