Initial Upload

This commit is contained in:
Matt Batchelder
2025-12-02 10:32:59 -05:00
commit 05ce0da296
2240 changed files with 467811 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\ActionFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class ActionListener implements OnUserDeleteInterface
{
/**
* @var ActionFactory
*/
private $actionFactory;
/**
* @var StorageServiceInterface
*/
private $store;
use ListenerLoggerTrait;
public function __construct(StorageServiceInterface $store, ActionFactory $actionFactory)
{
$this->store = $store;
$this->actionFactory = $actionFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/* @inheritDoc */
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// Delete any Actions
foreach ($this->actionFactory->getByOwnerId($user->userId) as $action) {
$action->delete();
}
}
/* @inheritDoc */
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign Actions
$this->store->update('UPDATE `action` SET ownerId = :userId WHERE ownerId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
/* @inheritDoc */
public function countChildren(User $user)
{
$actions = $this->actionFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Actions on User ID %d, there are %d', $user->userId, count($actions)));
return count($actions);
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\CommandDeleteEvent;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\CommandFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class CommandListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var CommandFactory
*/
private $commandFactory;
/**
* @var StorageServiceInterface
*/
private $store;
public function __construct(StorageServiceInterface $store, CommandFactory $commandFactory)
{
$this->store = $store;
$this->commandFactory = $commandFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->commandFactory->getByOwnerId($user->userId) as $command) {
$dispatcher->dispatch(CommandDeleteEvent::$NAME, new CommandDeleteEvent($command));
$command->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
$this->store->update('UPDATE `command` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
public function countChildren(User $user)
{
$commands = $this->commandFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Command on User ID %d, there are %d', $user->userId, count($commands)));
return count($commands);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\DataSetFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class DataSetListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $storageService;
/**
* @var DataSetFactory
*/
private $dataSetFactory;
public function __construct(StorageServiceInterface $storageService, DataSetFactory $dataSetFactory)
{
$this->storageService = $storageService;
$this->dataSetFactory = $dataSetFactory;
}
/**
* @inheritDoc
*/
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/**
* @inheritDoc
*/
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->dataSetFactory->getByOwnerId($user->userId) as $dataSet) {
$dataSet->delete();
}
}
/**
* @inheritDoc
*/
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign datasets
$this->storageService->update('UPDATE `dataset` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
/**
* @inheritDoc
*/
public function countChildren(User $user)
{
$dataSets = $this->dataSetFactory->getByOwnerId($user->userId);
$count = count($dataSets);
$this->getLogger()->debug(sprintf('Counted Children DataSet on User ID %d, there are %d', $user->userId, $count));
return $count;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/*
* Copyright (c) 2022 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\DayPartFactory;
use Xibo\Factory\ScheduleFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Service\DisplayNotifyServiceInterface;
use Xibo\Storage\StorageServiceInterface;
class DayPartListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $storageService;
/**
* @var DayPartFactory
*/
private $dayPartFactory;
/**
* @var ScheduleFactory
*/
private $scheduleFactory;
/** @var DisplayNotifyServiceInterface */
private $displayNotifyService;
public function __construct(
StorageServiceInterface $storageService,
DayPartFactory $dayPartFactory,
ScheduleFactory $scheduleFactory,
DisplayNotifyServiceInterface $displayNotifyService
) {
$this->storageService = $storageService;
$this->dayPartFactory = $dayPartFactory;
$this->scheduleFactory = $scheduleFactory;
$this->displayNotifyService = $displayNotifyService;
}
/**
* @inheritDoc
*/
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/**
* @inheritDoc
*/
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// system dayParts cannot be deleted, if this user owns them reassign to systemUser
foreach ($this->dayPartFactory->getByOwnerId($user->userId) as $dayPart) {
if ($dayPart->isSystemDayPart()) {
$dayPart->setOwner($systemUser->userId);
$dayPart->save(['recalculateHash' => false]);
} else {
$dayPart->setScheduleFactory($this->scheduleFactory, $this->displayNotifyService)->delete();
}
}
}
/**
* @inheritDoc
*/
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign Dayparts
foreach ($this->dayPartFactory->getByOwnerId($user->userId) as $dayPart) {
($dayPart->isSystemDayPart()) ? $dayPart->setOwner($systemUser->userId) : $dayPart->setOwner($newUser->getOwnerId());
$dayPart->save(['recalculateHash' => false]);
}
}
/**
* @inheritDoc
*/
public function countChildren(User $user)
{
$dayParts = $this->dayPartFactory->getByOwnerId($user->userId);
$count = count($dayParts);
$this->getLogger()->debug(sprintf('Counted Children DayParts on User ID %d, there are %d', $user->userId, $count));
return $count;
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\DisplayProfileFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class DisplayProfileListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $store;
/**
* @var DisplayProfileFactory
*/
private $displayProfileFactory;
public function __construct(StorageServiceInterface $store, DisplayProfileFactory $displayProfileFactory)
{
$this->store = $store;
$this->displayProfileFactory = $displayProfileFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// Delete any Display Profiles, reassign any default profiles to systemUser
foreach ($this->displayProfileFactory->getByOwnerId($user->userId) as $displayProfile) {
if ($displayProfile->isDefault === 1) {
$displayProfile->setOwner($systemUser->userId);
$displayProfile->save();
} else {
$displayProfile->delete();
}
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
$this->store->update('UPDATE `displayprofile` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
public function countChildren(User $user)
{
$profiles = $this->displayProfileFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Display Profiles on User ID %d, there are %d', $user->userId, count($profiles)));
return count($profiles);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\MenuBoardFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class MenuBoardListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $storageService;
/**
* @var MenuBoardFactory
*/
private $menuBoardFactory;
public function __construct(StorageServiceInterface $storageService, MenuBoardFactory $menuBoardFactory)
{
$this->storageService = $storageService;
$this->menuBoardFactory = $menuBoardFactory;
}
/**
* @inheritDoc
*/
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/**
* @inheritDoc
*/
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->menuBoardFactory->getByOwnerId($user->userId) as $menuBoard) {
$menuBoard->delete();
}
}
/**
* @inheritDoc
*/
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign Menu Boards
$this->storageService->update('UPDATE `menu_board` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
/**
* @inheritDoc
*/
public function countChildren(User $user)
{
$menuBoards = $this->menuBoardFactory->getByOwnerId($user->userId);
$count = count($menuBoards);
$this->getLogger()->debug(sprintf('Counted Children Menu Board on User ID %d, there are %d', $user->userId, $count));
return $count;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\NotificationFactory;
use Xibo\Listener\ListenerLoggerTrait;
class NotificationListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var NotificationFactory
*/
private $notificationFactory;
public function __construct(NotificationFactory $notificationFactory)
{
$this->notificationFactory = $notificationFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// Delete any Notifications
foreach ($this->notificationFactory->getByOwnerId($user->userId) as $notification) {
$notification->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
foreach ($this->notificationFactory->getByOwnerId($user->userId) as $notification) {
$notification->load();
$notification->userId = $newUser->userId;
$notification->save();
}
}
public function countChildren(User $user)
{
$notifications = $this->notificationFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Notifications on User ID %d, there are %d', $user->userId, count($notifications)));
return count($notifications);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Xibo\Event\UserDeleteEvent;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class OnUserDelete
{
use ListenerLoggerTrait;
/** @var StorageServiceInterface */
private $store;
public function __construct(StorageServiceInterface $store)
{
$this->store = $store;
}
/**
* @inheritDoc
*/
public function __invoke(UserDeleteEvent $event)
{
$user = $event->getUser();
$function = $event->getFunction();
if ($function === 'delete' || $function === 'reassignAll') {
$this->deleteChildren($user);
}
}
// when we delete a User with or without reassign the session and oauth clients should always be removed
// other objects that can be owned by the user are deleted in their respective listeners.
private function deleteChildren($user)
{
// Delete oAuth clients
$this->store->update('DELETE FROM `oauth_clients` WHERE userId = :userId', ['userId' => $user->userId]);
$this->store->update('DELETE FROM `session` WHERE userId = :userId', ['userId' => $user->userId]);
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
interface OnUserDeleteInterface
{
/**
* Listen to the UserDeleteEvent
*
* @param UserDeleteEvent $event
* @return mixed
*/
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher);
/**
* Delete Objects owned by the User we want to delete
*
* @param User $user
* @return mixed
*/
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser);
/**
* Reassign objects to a new User
*
* @param User $user
* @param User $newUser
* @return mixed
*/
public function reassignAllTo(User $user, User $newUser, User $systemUser);
/**
* Count Children, return count of objects owned by the User we want to delete
*
* @param User $user
* @return mixed
*/
public function countChildren(User $user);
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\RegionFactory;
use Xibo\Listener\ListenerLoggerTrait;
class RegionListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var RegionFactory
*/
private $regionFactory;
public function __construct(RegionFactory $regionFactory)
{
$this->regionFactory = $regionFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->regionFactory->getbyOwnerId($user->userId) as $region) {
$region->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
$regions = $this->regionFactory->getbyOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Regions on User ID %d, there are %d', $user->userId, count($regions)));
foreach ($regions as $region) {
$region->setOwner($newUser->userId, true);
$region->save([
'validate' => false,
'audit' => false,
'notify' => false
]);
}
$this->getLogger()->debug(sprintf('Finished reassign Regions, there are %d children', $this->countChildren($user)));
}
public function countChildren(User $user)
{
$regions = $this->regionFactory->getbyOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Regions on User ID %d, there are %d', $user->userId, count($regions)));
return count($regions);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\ReportScheduleFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class ReportScheduleListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $store;
/**
* @var ReportScheduleFactory
*/
private $reportScheduleFactory;
public function __construct(StorageServiceInterface $store, ReportScheduleFactory $reportScheduleFactory)
{
$this->store = $store;
$this->reportScheduleFactory = $reportScheduleFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->reportScheduleFactory->getByOwnerId($user->userId) as $reportSchedule) {
$reportSchedule->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
$this->store->update('UPDATE `reportschedule` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
public function countChildren(User $user)
{
$reportSchedules = $this->reportScheduleFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Report Schedules on User ID %d, there are %d', $user->userId, count($reportSchedules)));
return count($reportSchedules);
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\ResolutionFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class ResolutionListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $store;
/**
* @var ResolutionFactory
*/
private $resolutionFactory;
public function __construct(StorageServiceInterface $store, ResolutionFactory $resolutionFactory)
{
$this->store = $store;
$this->resolutionFactory = $resolutionFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/* @inheritDoc */
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// Delete any Resolutions
foreach ($this->resolutionFactory->getByOwnerId($user->userId) as $resolution) {
$resolution->delete();
}
}
/* @inheritDoc */
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign Resolutions
$this->store->update('UPDATE `resolution` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
/* @inheritDoc */
public function countChildren(User $user)
{
$resolutions = $this->resolutionFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Resolution on User ID %d, there are %d', $user->userId, count($resolutions)));
return count($resolutions);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\SavedReportFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class SavedReportListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var StorageServiceInterface
*/
private $store;
/**
* @var SavedReportFactory
*/
private $savedReportFactory;
public function __construct(StorageServiceInterface $store, SavedReportFactory $savedReportFactory)
{
$this->store = $store;
$this->savedReportFactory = $savedReportFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->savedReportFactory->getByOwnerId($user->userId) as $savedReport) {
$savedReport->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
$this->store->update('UPDATE `saved_report` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
public function countChildren(User $user)
{
$savedReports = $this->savedReportFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Saved Report on User ID %d, there are %d', $user->userId, count($savedReports)));
return count($savedReports);
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\Schedule;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\ScheduleFactory;
use Xibo\Listener\ListenerLoggerTrait;
use Xibo\Storage\StorageServiceInterface;
class ScheduleListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/** @var StorageServiceInterface */
private $storageService;
/** @var ScheduleFactory */
private $scheduleFactory;
public function __construct(StorageServiceInterface $storageService, ScheduleFactory $scheduleFactory)
{
$this->storageService = $storageService;
$this->scheduleFactory = $scheduleFactory;
}
/**
* @inheritDoc
*/
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
/**
* @inheritDoc
*/
public function deleteChildren($user, EventDispatcherInterface $dispatcher, User $systemUser)
{
// Delete any scheduled events
foreach ($this->scheduleFactory->getByOwnerId($user->userId) as $event) {
/* @var Schedule $event */
$event->delete();
}
}
/**
* @inheritDoc
*/
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
// Reassign events
$this->storageService->update('UPDATE `schedule` SET userId = :userId WHERE userId = :oldUserId', [
'userId' => $newUser->userId,
'oldUserId' => $user->userId
]);
}
/**
* @inheritDoc
*/
public function countChildren(User $user)
{
$events = $this->scheduleFactory->getByOwnerId($user->userId);
$count = count($events);
$this->getLogger()->debug(sprintf('Counted Children Event on User ID %d, there are %d', $user->userId, $count));
return $count;
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Copyright (C) 2021 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Xibo\Listener\OnUserDelete;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Xibo\Entity\User;
use Xibo\Event\UserDeleteEvent;
use Xibo\Factory\WidgetFactory;
use Xibo\Listener\ListenerLoggerTrait;
class WidgetListener implements OnUserDeleteInterface
{
use ListenerLoggerTrait;
/**
* @var WidgetFactory
*/
private $widgetFactory;
public function __construct(WidgetFactory $widgetFactory)
{
$this->widgetFactory = $widgetFactory;
}
public function __invoke(UserDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
{
$user = $event->getUser();
$function = $event->getFunction();
$newUser = $event->getNewUser();
$systemUser = $event->getSystemUser();
if ($function === 'delete') {
$this->deleteChildren($user, $dispatcher, $systemUser);
} elseif ($function === 'reassignAll') {
$this->reassignAllTo($user, $newUser, $systemUser);
} elseif ($function === 'countChildren') {
$event->setReturnValue($event->getReturnValue() + $this->countChildren($user));
}
}
public function deleteChildren(User $user, EventDispatcherInterface $dispatcher, User $systemUser)
{
foreach ($this->widgetFactory->getByOwnerId($user->userId) as $widget) {
$widget->delete();
}
}
public function reassignAllTo(User $user, User $newUser, User $systemUser)
{
foreach ($this->widgetFactory->getByOwnerId($user->userId) as $widget) {
$widget->setOwner($newUser->userId);
$widget->save([
'saveWidgetOptions' => false,
'saveWidgetAudio' => false,
'saveWidgetMedia' => false,
'notify' => false,
'notifyPlaylists' => false,
'notifyDisplays' => false,
'audit' => true,
'alwaysUpdate' => true
]);
}
}
public function countChildren(User $user)
{
$widgets = $this->widgetFactory->getByOwnerId($user->userId);
$this->getLogger()->debug(sprintf('Counted Children Widgets on User ID %d, there are %d', $user->userId, count($widgets)));
return count($widgets);
}
}