Skip to content

Commit

Permalink
feat: schedule update job when creating/deleting entities
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed May 16, 2024
1 parent 3e9b5a5 commit fdcb408
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/Command/CreateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2021 Anna Larch <anna.larch@nextcloud.com>
*
* @author 2021 Anna Larch <anna.larch@nextcloud.com>
* @author 2024 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,7 +28,9 @@

use OCA\CalendarResourceManagement\Db\ResourceMapper;
use OCA\CalendarResourceManagement\Db\ResourceModel;
use OCA\DAV\Events\ScheduleResourcesRoomsUpdateEvent;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -49,11 +52,15 @@ class CreateResource extends Command {
/** @var ResourceMapper */
private $resourceMapper;

private IEventDispatcher $eventDispatcher;

public function __construct(LoggerInterface $logger,
ResourceMapper $resourceMapper) {
ResourceMapper $resourceMapper,
IEventDispatcher $eventDispatcher) {
parent::__construct();
$this->logger = $logger;
$this->resourceMapper = $resourceMapper;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -100,6 +107,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (class_exists(ScheduleResourcesRoomsUpdateEvent::class)) {
$this->eventDispatcher->dispatchTyped(new ScheduleResourcesRoomsUpdateEvent());
}

return 0;
}
}
13 changes: 12 additions & 1 deletion lib/Command/CreateRestriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2021 Anna Larch <anna.larch@nextcloud.com>
*
* @author 2021 Anna Larch <anna.larch@nextcloud.com>
* @author 2024 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,7 +28,9 @@

use OCA\CalendarResourceManagement\Db\RestrictionMapper;
use OCA\CalendarResourceManagement\Db\RestrictionModel;
use OCA\DAV\Events\ScheduleResourcesRoomsUpdateEvent;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -45,11 +48,15 @@ class CreateRestriction extends Command {
/** @var RestrictionMapper */
private $restrictionMapper;

private IEventDispatcher $eventDispatcher;

public function __construct(LoggerInterface $logger,
RestrictionMapper $restrictionMapper) {
RestrictionMapper $restrictionMapper,
IEventDispatcher $eventDispatcher) {
parent::__construct();
$this->logger = $logger;
$this->restrictionMapper = $restrictionMapper;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -86,6 +93,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (class_exists(ScheduleResourcesRoomsUpdateEvent::class)) {
$this->eventDispatcher->dispatchTyped(new ScheduleResourcesRoomsUpdateEvent());
}

return 0;
}
}
12 changes: 11 additions & 1 deletion lib/Command/CreateRoom.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2021 Anna Larch <anna.larch@nextcloud.com>
*
* @author 2021 Anna Larch <anna.larch@nextcloud.com>
* @author 2024 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,7 +28,9 @@

use OCA\CalendarResourceManagement\Db\RoomMapper;
use OCA\CalendarResourceManagement\Db\RoomModel;
use OCA\DAV\Events\ScheduleResourcesRoomsUpdateEvent;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -57,10 +60,13 @@ class CreateRoom extends Command {
/** @var RoomMapper */
private $roomMapper;

public function __construct(LoggerInterface $logger, RoomMapper $roomMapper) {
private IEventDispatcher $eventDispatcher;

public function __construct(LoggerInterface $logger, RoomMapper $roomMapper, IEventDispatcher $eventDispatcher) {
parent::__construct();
$this->logger = $logger;
$this->roomMapper = $roomMapper;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -201,6 +207,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (class_exists(ScheduleResourcesRoomsUpdateEvent::class)) {
$this->eventDispatcher->dispatchTyped(new ScheduleResourcesRoomsUpdateEvent());
}

return 0;
}
}
12 changes: 11 additions & 1 deletion lib/Command/CreateVehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2021 Anna Larch <anna.larch@nextcloud.com>
*
* @author 2021 Anna Larch <anna.larch@nextcloud.com>
* @author 2024 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -27,6 +28,8 @@

use OCA\CalendarResourceManagement\Db\VehicleMapper;
use OCA\CalendarResourceManagement\Db\VehicleModel;
use OCA\DAV\Events\ScheduleResourcesRoomsUpdateEvent;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -53,10 +56,13 @@ class CreateVehicle extends Command {
/** @var VehicleMapper */
private $vehicleMapper;

public function __construct(LoggerInterface $logger, VehicleMapper $vehicleMapper) {
private IEventDispatcher $eventDispatcher;

public function __construct(LoggerInterface $logger, VehicleMapper $vehicleMapper, IEventDispatcher $eventDispatcher) {
parent::__construct();
$this->logger = $logger;
$this->vehicleMapper = $vehicleMapper;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -117,6 +123,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (class_exists(ScheduleResourcesRoomsUpdateEvent::class)) {
$this->eventDispatcher->dispatchTyped(new ScheduleResourcesRoomsUpdateEvent());
}

return 0;
}
}
12 changes: 11 additions & 1 deletion lib/Command/DeleteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright 2021 Anna Larch <anna.larch@nextcloud.com>
*
* @author 2021 Anna Larch <anna.larch@nextcloud.com>
* @author 2024 Richard Steinmetz <richard@steinmetz.cloud>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -26,9 +27,11 @@
namespace OCA\CalendarResourceManagement\Command;

use OCA\CalendarResourceManagement\Db\AMapper;
use OCA\DAV\Events\ScheduleResourcesRoomsUpdateEvent;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
Expand All @@ -46,10 +49,13 @@ class DeleteResource extends Command {
/** @var IDBConnection */
private $connection;

public function __construct(LoggerInterface $logger, IDBConnection $connection) {
private IEventDispatcher $eventDispatcher;

public function __construct(LoggerInterface $logger, IDBConnection $connection, IEventDispatcher $eventDispatcher) {
parent::__construct();
$this->logger = $logger;
$this->connection = $connection;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -101,6 +107,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (class_exists(ScheduleResourcesRoomsUpdateEvent::class)) {
$this->eventDispatcher->dispatchTyped(new ScheduleResourcesRoomsUpdateEvent());
}

return 0;
}
}

0 comments on commit fdcb408

Please sign in to comment.