mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-22 09:36:10 +01:00
Add basic cleanup command
Allows to remove all existing records regarding events. It will search for all pages providing either organizer or events, and will delete both types of records. As DataHandler is used for deletion, there is already logging within TYPO3, as well as recursive deletion for dates and sys_file_references. To speedup for large data sets, truncate organizer and dates, as they don't have recursive deletions, e.g. to sys_file_references. Also add keys to database.
This commit is contained in:
parent
37e83dcfd0
commit
ca4d7d3a01
4 changed files with 81 additions and 41 deletions
|
@ -4,19 +4,17 @@ namespace Wrm\Events\Command;
|
|||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Core\Bootstrap;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
||||
use Wrm\Events\Service\CleanupService;
|
||||
|
||||
class CleanupCommand extends Command {
|
||||
|
||||
class RemoveAllCommand extends Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setDescription('Cleanup Events');
|
||||
$this->setHelp('Events are cleaned up');
|
||||
$this->setDescription('Remove all event data');
|
||||
$this->setHelp('All events and associated data will be removed.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
|
@ -25,6 +23,6 @@ class CleanupCommand extends Command {
|
|||
|
||||
return GeneralUtility::makeInstance(ObjectManager::class)
|
||||
->get(CleanupService::class)
|
||||
->doClean();
|
||||
->deleteAllData();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,39 +2,74 @@
|
|||
|
||||
namespace Wrm\Events\Service;
|
||||
|
||||
use TYPO3\CMS\Core\DataHandling\DataHandler;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Log\LogManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
||||
class CleanupService {
|
||||
class CleanupService
|
||||
{
|
||||
public function deleteAllData()
|
||||
{
|
||||
$this->truncateTables(... [
|
||||
'tx_events_domain_model_date',
|
||||
'tx_events_domain_model_organizer',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Cleanup Service constructor.
|
||||
* @param ConfigurationManager $configurationManager
|
||||
* @param ObjectManager $objectManager
|
||||
*/
|
||||
public function __construct(
|
||||
ConfigurationManager $configurationManager,
|
||||
ObjectManager $objectManager
|
||||
) {
|
||||
|
||||
// Get Typoscript Settings
|
||||
$this->settings = $this->configurationManager->getConfiguration(
|
||||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
|
||||
'Events',
|
||||
'Pi1'
|
||||
);
|
||||
|
||||
|
||||
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
|
||||
$this->logger->info('Event Cleanup Service');
|
||||
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
|
||||
/* @var DataHandler $dataHandler */
|
||||
$dataHandler->start([], $this->getDeletionStructure([
|
||||
'tx_events_domain_model_event',
|
||||
]));
|
||||
$dataHandler->process_cmdmap();
|
||||
}
|
||||
|
||||
public function doCleanup() {
|
||||
|
||||
// To be done
|
||||
// Hmpf
|
||||
private function truncateTables(string ...$tableNames): void
|
||||
{
|
||||
foreach ($tableNames as $tableName) {
|
||||
GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getConnectionForTable($tableName)
|
||||
->truncate($tableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getDeletionStructure(array $tableNames): array
|
||||
{
|
||||
$structure = [];
|
||||
|
||||
foreach ($tableNames as $tableName) {
|
||||
$structure = array_merge($structure, $this->getDeletionStructureForTable($tableName));
|
||||
}
|
||||
|
||||
return $structure;
|
||||
}
|
||||
|
||||
private function getDeletionStructureForTable(string $tableName): array
|
||||
{
|
||||
$dataStructure = [$tableName=> []];
|
||||
|
||||
foreach ($this->getRecordsToDelete($tableName) as $recordToDelete) {
|
||||
$dataStructure[$tableName][$recordToDelete] = ['delete' => 1];
|
||||
}
|
||||
|
||||
return $dataStructure;
|
||||
}
|
||||
|
||||
private function getRecordsToDelete(string $tableName): array
|
||||
{
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getConnectionForTable($tableName)
|
||||
->createQueryBuilder();
|
||||
|
||||
/* @var QueryBuilder $queryBuilder */
|
||||
$records = $queryBuilder->select('uid')
|
||||
->from($tableName)
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
||||
return array_map(function (array $record) {
|
||||
return $record['uid'];
|
||||
}, $records);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,5 +2,8 @@
|
|||
return [
|
||||
'events:destinationdataimport‚' => [
|
||||
'class' => \Wrm\Events\Command\DestinationDataImportCommand::class
|
||||
]
|
||||
];
|
||||
],
|
||||
'events:removeAll' => [
|
||||
'class' => \Wrm\Events\Command\RemoveAllCommand::class
|
||||
],
|
||||
];
|
||||
|
|
|
@ -28,6 +28,7 @@ CREATE TABLE tx_events_domain_model_event (
|
|||
organizer int(11) unsigned DEFAULT '0',
|
||||
region int(11) unsigned DEFAULT '0',
|
||||
|
||||
KEY dataHandler (l10n_parent, t3ver_oid, deleted, t3ver_wsid, t3ver_state)
|
||||
);
|
||||
|
||||
#
|
||||
|
@ -44,6 +45,7 @@ CREATE TABLE tx_events_domain_model_organizer (
|
|||
web varchar(255) DEFAULT '' NOT NULL,
|
||||
email varchar(255) DEFAULT '' NOT NULL,
|
||||
|
||||
KEY dataHandler (l10n_parent, sys_language_uid, deleted)
|
||||
);
|
||||
|
||||
#
|
||||
|
@ -56,6 +58,8 @@ CREATE TABLE tx_events_domain_model_date (
|
|||
start datetime DEFAULT NULL,
|
||||
end datetime DEFAULT NULL,
|
||||
|
||||
KEY event (event),
|
||||
KEY dataHandler (event, t3ver_wsid, pid)
|
||||
);
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue