Skip to content

Commit

Permalink
Merge branch 'garbast-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Sep 24, 2023
2 parents b109e0b + 285e2a8 commit 19c1ccf
Show file tree
Hide file tree
Showing 190 changed files with 3,980 additions and 6,393 deletions.
64 changes: 37 additions & 27 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
# EditorConfig is awesome: http://EditorConfig.org

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true

[**.css]
indent_style = tab
indent_size = 2

[**.php]
indent_style = space
indent_size = 4

[**.html]
indent_style = tab
# TS/JS-Files
[*.{ts,js}]
indent_size = 2

[**.ics]
insert_final_newline = false

# JSON-Files
[*.json]
indent_style = tab

[{*.rst,*.rst.txt}]
indent_style = space
indent_size = 3
# ReST-Files
[*.{rst,rst.txt}]
indent_size = 4
max_line_length = 80

# MD-Files
# Markdown-Files
[*.md]
indent_style = space
indent_size = 4
max_line_length = 80

# TS/JS-Files
[*.{ts,js}]
# YAML-Files
[*.{yaml,yml}]
indent_size = 2

# NEON-Files
[*.neon]
indent_size = 2
indent_style = tab

#.eslintrc.json
[.eslintrc.json]
indent_size = 2
indent_style = space

# stylelint
[.stylelintrc]
indent_size = 2

# package.json
[package.json]
indent_size = 2

# TypoScript
Expand All @@ -51,6 +56,11 @@ indent_size = 2
[*.xlf]
indent_style = tab

# YAML-Files
[*.{yaml,yml}]
# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.travis.yml export-ignore
/.php_cs export-ignore
/.php_cs.cache export-ignore
/depfile.yaml
Expand Down
64 changes: 0 additions & 64 deletions .travis.yml

This file was deleted.

130 changes: 30 additions & 100 deletions Classes/Command/CleanupCommandController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

/**
* Cleanup the event models.
*/
declare(strict_types=1);

namespace HDNET\Calendarize\Command;

use HDNET\Calendarize\Domain\Model\Event;
use HDNET\Calendarize\Domain\Repository\EventRepository;
use HDNET\Calendarize\Domain\Repository\RawIndexRepository;
use HDNET\Calendarize\Event\CleanupEvent;
Expand All @@ -30,79 +26,24 @@
*/
class CleanupCommandController extends Command
{
public const MODUS_HIDDEN = 'hide';
public const MODUS_DELETED = 'delete';
public const MODE_HIDDEN = 'hide';
public const MODE_DELETED = 'delete';
public const DEFAULT_WAIT_PERIOD = 14;
public const DEFAULT_CLEANUP_REPOSITORY = \HDNET\Calendarize\Domain\Repository\EventRepository::class;

/**
* @var PersistenceManager
*/
protected $persistenceManager;

/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;

/**
* @var RawIndexRepository
*/
protected $rawIndexRepository;

/**
* @var DataMapper
*/
protected $dataMapper;

/**
* @var IndexerService
*/
protected $indexerService;

/**
* @param PersistenceManager $persistenceManager
*/
public function injectPersistenceManager(PersistenceManager $persistenceManager): void
{
$this->persistenceManager = $persistenceManager;
}

/**
* @param EventDispatcherInterface $eventDispatcher
*/
public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}

/**
* @param DataMapper $dataMapper
*/
public function injectDataMapper(DataMapper $dataMapper): void
{
$this->dataMapper = $dataMapper;
}

/**
* @param RawIndexRepository $rawIndexRepository
*/
public function injectRawIndexRepository(RawIndexRepository $rawIndexRepository): void
{
$this->rawIndexRepository = $rawIndexRepository;
}

/**
* @param IndexerService $indexerService
*/
public function injectIndexerService(IndexerService $indexerService): void
{
$this->indexerService = $indexerService;
public const DEFAULT_CLEANUP_REPOSITORY = EventRepository::class;

public function __construct(
protected PersistenceManager $persistenceManager,
protected EventDispatcherInterface $eventDispatcher,
protected RawIndexRepository $rawIndexRepository,
protected IndexerService $indexerService,
protected DataMapper $dataMapper
) {
parent::__construct();
}

protected function configure()
{
$this->setDescription('Remove outdated events to keep a small footprint')
$this
->addOption(
'repositoryName',
'r',
Expand All @@ -115,7 +56,7 @@ protected function configure()
'm',
InputOption::VALUE_REQUIRED,
'What to do with cleaned Events? Set them \'hide\' or \'delete\'',
self::MODUS_HIDDEN
self::MODE_HIDDEN
)
->addOption(
'waitingPeriod',
Expand All @@ -134,19 +75,14 @@ protected function configure()
/**
* Cleanup the event models.
* Remove outdated events to keep a small footprint. This gain maybe a little more performance.
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int 0 if everything went fine, or an exit code
*/
protected function execute(InputInterface $input, OutputInterface $output): int
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Cleanup outdated events');

$repositoryName = $input->getOption('repositoryName');
$modus = $input->getOption('modus');
$mode = $input->getOption('modus');
$waitingPeriod = (int)$input->getOption('waitingPeriod');

/** @var Repository $repository */
Expand All @@ -163,32 +99,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$io->text('Tablename ' . $tableName);

if (self::MODUS_HIDDEN === $modus
if (
self::MODE_HIDDEN === $mode
&& !isset($GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['disabled'])
) {
$io->error('Cannot hide events due to missing hidden/disabled field.');

return 3;
return self::FAILURE;
}

// events uid, to be precise
$events = $this->rawIndexRepository->findOutdatedEvents($tableName, $waitingPeriod);

$io->text('Found ' . \count($events) . ' Events ready to process.');
$io->text('Found ' . count($events) . ' Events ready to process.');

if (0 === \count($events) || true === $input->getOption('dry-run')) {
return 0;
if (0 === count($events) || true === $input->getOption('dry-run')) {
return self::SUCCESS;
}

$io->section('Cleanup outdated events now');
// climb through the events and hide/delete them
foreach ($events as $event) {
$uid = (int)$event['foreign_uid'];

/** @var AbstractEntity $model */
$model = $repository->findByUid($uid);

$this->processEvent($repository, $model, $modus);
$model = $repository->findByUid((int)$event['foreign_uid']);
$this->processEvent($repository, $model, $mode);
}
$io->text('Events processed.');

Expand All @@ -198,36 +132,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// after all this deleting ... reindex!
$this->indexerService->reindexAll();

return 0;
return self::SUCCESS;
}

/**
* Process the found Event and delete or hide it.
*
* @param EventRepository $repository
* @param Event $model
* @param string $modus
*/
protected function processEvent(Repository $repository, AbstractEntity $model, string $modus)
protected function processEvent(Repository $repository, AbstractEntity $model, string $mode): void
{
// define the function for the delete-modus.
// define the function for the delete-mode.
$delete = static function ($repository, $model) {
$repository->remove($model);
};

// define the function for the hide-modus.
// define the function for the hide-mode.
$hide = static function ($repository, $model) {
$model->setHidden(true);
$repository->update($model);
};

if (self::MODUS_DELETED === $modus) {
if (self::MODE_DELETED === $mode) {
$function = $delete;
} else {
$function = $hide;
}

$event = new CleanupEvent($modus, $repository, $model, $function);
$event = new CleanupEvent($mode, $repository, $model, $function);
$this->eventDispatcher->dispatch($event);

$myFunction = $event->getFunction();
Expand Down
Loading

0 comments on commit 19c1ccf

Please sign in to comment.