Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 53.11.4 #3922

Merged
merged 18 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"oat-sa/jig": "~0.2",
"oat-sa/composer-npm-bridge": "~0.4.2||dev-master",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.29",
"oat-sa/generis": ">=15.32.0",
"composer/package-versions-deprecated": "^1.11",
"paragonie/random_compat": "^2.0",
"phpdocumentor/reflection-docblock": "^5.2",
Expand Down
38 changes: 4 additions & 34 deletions models/classes/event/DataAccessControlChangedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,18 @@

class DataAccessControlChangedEvent implements Event
{
/** @var string */
private $resourceId;

/** @var ?string */
private $rootResourceId;

/** @var array */
private $addRemove;

/**
* @deprecated Use $applyToNestedResources cause processing recursively causes performance issues
* @var bool
*/
private $isRecursive;

private bool $applyToNestedResources;
private string $resourceId;
private array $addRemove;
private bool $isRecursive;

public function __construct(
string $resourceId,
array $addRemove,
bool $isRecursive = false,
bool $applyToNestedResources = false,
string $rootResourceId = null
bool $isRecursive = false
) {
$this->resourceId = $resourceId;
$this->addRemove = $addRemove;
$this->isRecursive = $isRecursive;
$this->applyToNestedResources = $applyToNestedResources;
$this->rootResourceId = $rootResourceId;
}

public function getName(): string
Expand All @@ -67,26 +50,13 @@ public function getResourceId(): string
return $this->resourceId;
}

public function getRootResourceId(): ?string
{
return $this->rootResourceId;
}

public function getOperations(string $operation): array
{
return array_keys($this->addRemove[$operation] ?? []);
}

/**
* @deprecated Use applyToNestedResources because processing recursively causes performance issues
*/
public function isRecursive(): bool
{
return $this->isRecursive;
}

public function applyToNestedResources(): bool
{
return $this->applyToNestedResources;
}
}
18 changes: 3 additions & 15 deletions models/classes/listener/DataAccessControlChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,12 @@ public function handleEvent(DataAccessControlChangedEvent $event): void
/** @noinspection PhpUnhandledExceptionInspection */
$resource = $this->getResource($event->getResourceId());

if ($event->getResourceId() !== $event->getRootResourceId()) {
if ($resource->isClass() && !$event->isRecursive()) {
return;
}

$this->getLogger()->debug(
sprintf(
'Dispatching UpdateDataAccessControlInIndex for root resource %s [%s]',
$resource->getLabel(),
$resource->getLabel()
)
);

$this->getQueueDispatcher()->createTask(
$queueDispatcher = $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID);
$queueDispatcher->createTask(
new UpdateDataAccessControlInIndex(),
[
$resource->getUri(),
Expand All @@ -70,9 +63,4 @@ public function handleEvent(DataAccessControlChangedEvent $event): void
$taskMessage
);
}

private function getQueueDispatcher(): QueueDispatcherInterface
{
return $this->getServiceLocator()->get(QueueDispatcherInterface::SERVICE_ID);
}
}
3 changes: 2 additions & 1 deletion models/classes/taskQueue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use oat\oatbox\log\LoggerAwareTrait;
use oat\oatbox\mutex\LockTrait;
use oat\oatbox\service\ServiceManager;
use oat\tao\model\taskQueue\Queue\Broker\QueueBrokerInterface;
use oat\tao\model\taskQueue\Queue\Broker\SyncQueueBrokerInterface;
use oat\tao\model\taskQueue\Task\TaskInterface;
Expand Down Expand Up @@ -142,7 +143,7 @@ public function setBroker(QueueBrokerInterface $broker)

public function getBroker(): QueueBrokerInterface
{
$this->broker->setServiceLocator($this->getServiceLocator());
$this->broker->setServiceLocator($this->getServiceLocator() ?? ServiceManager::getServiceManager());

return $this->broker;
}
Expand Down
15 changes: 15 additions & 0 deletions models/classes/taskQueue/QueueDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ public function addQueue(QueueInterface $queue)
return $this;
}

public function removeQueue(string $queueName): self
{
$queues = $this->getQueues();

foreach ($queues as $key => $queue) {
if ($queue->getName() === $queueName) {
unset($queues[$key]);
}
}

$this->setQueues(array_values($queues));

return $this;
}

/**
* @inheritdoc
*/
Expand Down
71 changes: 24 additions & 47 deletions test/unit/model/listener/DataAccessControlChangedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
* 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) 2020-2023 (original work) Open Assessment Technologies SA;
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
*/

declare(strict_types=1);

use oat\generis\model\data\Ontology;
use oat\generis\test\MockObject;
use oat\generis\test\TestCase;
use oat\generis\test\ServiceManagerMockTrait;
use oat\oatbox\log\LoggerService;
use oat\tao\model\AdvancedSearch\AdvancedSearchChecker;
use oat\tao\model\event\DataAccessControlChangedEvent;
use oat\tao\model\listener\DataAccessControlChangedListener;
use oat\tao\model\search\tasks\UpdateDataAccessControlInIndex;
use oat\tao\model\taskQueue\QueueDispatcherInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class DataAccessControlChangedListenerTest extends TestCase
{
use ServiceManagerMockTrait;

/** @var QueueDispatcherInterface|MockObject */
private $queueDispatcher;

Expand All @@ -59,7 +61,7 @@ protected function setUp(): void
$this->advancedSearchChecker = $this->createMock(AdvancedSearchChecker::class);

$this->sut->setServiceLocator(
$this->getServiceLocatorMock(
$this->getServiceManagerMock(
[
QueueDispatcherInterface::SERVICE_ID => $this->queueDispatcher,
LoggerService::SERVICE_ID => $this->logger,
Expand All @@ -71,45 +73,26 @@ protected function setUp(): void
}

/**
* @dataProvider handleEventSuccessfulCasesDataProvider
* @dataProvider provideSuccessfulCases
*/
public function testHandleEventShouldCreateTaskSuccessfully(bool $isRecursive): void
public function testHandleEventShouldCreateTaskSuccessfully(bool $isRecursive, bool $isClass): void
{
$documentUri = 'https://tao.docker.localhost/ontologies/tao.rdf#i5ef45f413088c8e7901a84708e84ec';

$resource = $this->createMock(core_kernel_classes_Resource::class);
$this->advancedSearchChecker->method('isEnabled')->willReturn(true);

$this->advancedSearchChecker
->method('isEnabled')
->willReturn(true);

$resource
->expects($this->once())
->method('getUri')
$resource->expects($this->once())->method('getUri')
->willReturn($documentUri);
$resource
->method('getLabel')
->willReturn('Resource Label');

$this->logger
->expects($this->exactly(2))
->method('debug')
->withConsecutive(
['triggering index update on DataAccessControlChanged event'],
[
$this->stringStartsWith(
'Dispatching UpdateDataAccessControlInIndex for root resource'
)
]
);
$resource->expects($this->once())->method('isClass')
->willReturn($isClass);

$this->logger->expects($this->once())->method('debug')
->with('triggering index update on DataAccessControlChanged event');

$this->ontology
->expects($this->once())
->method('getResource')
$this->ontology->expects($this->once())->method('getResource')
->willReturn($resource);

$this->queueDispatcher
->expects($this->once())
$this->queueDispatcher->expects($this->once())
->method('createTask')
->with(
new UpdateDataAccessControlInIndex(),
Expand All @@ -122,28 +105,20 @@ public function testHandleEventShouldCreateTaskSuccessfully(bool $isRecursive):
false
);

$this->sut->handleEvent(
new DataAccessControlChangedEvent(
$documentUri,
[],
$isRecursive,
$isRecursive,
$documentUri
)
);
$this->sut->handleEvent(new DataAccessControlChangedEvent($documentUri, [], $isRecursive));
}

public function handleEventSuccessfulCasesDataProvider(): array
public function provideSuccessfulCases(): array
{
return [
'case event is recursive and resource is NOT a class' => [
true,
true, false
],
'case event is recursive and resource is a class' => [
true,
true, true
],
'case event is NOT recursive and resource is not a class' => [
false,
false, false
],
];
}
Expand All @@ -155,6 +130,8 @@ public function testHandleEventShouldNotCreateTasks(): void
$this->advancedSearchChecker->method('isEnabled')->willReturn(true);

$resource->expects($this->never())->method('getUri');
$resource->expects($this->once())->method('isClass')
->willReturn(true);

$this->logger->expects($this->once())->method('debug')
->with('triggering index update on DataAccessControlChanged event');
Expand Down
18 changes: 1 addition & 17 deletions test/unit/models/classes/Csv/Service/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,10 @@

namespace oat\tao\test\unit\models\classes\Csv\Service;

use oat\generis\test\TestCase;
use oat\tao\model\Csv\Resource\Reader;
use League\Csv\Reader as LeagueCsvReader;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

// @TODO Test class in the next iteration
class ReaderTest extends TestCase
{
/** @var LeagueCsvReader|MockObject */
private $leaguesCsv;

/** @var Reader */
private $sut;

public function setUp(): void
{
$this->leaguesCsv = $this->createMock(LeagueCsvReader::class);
$this->sut = new Reader($this->leaguesCsv);
}

public function testCreateFromStream(): void
{
$this->markTestIncomplete('Test in the next iteration');
Expand Down
Loading