Skip to content

Commit

Permalink
Merge pull request #10 from pagemachine/typo3v9-deprecations
Browse files Browse the repository at this point in the history
Fix TYPO3v9 deprecations
  • Loading branch information
mbrodala authored Sep 11, 2020
2 parents 301a708 + 3c62032 commit 81e42f2
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 98 deletions.
25 changes: 25 additions & 0 deletions Classes/Command/Index/AbstractIndexCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Index;

use PAGEmachine\Searchable\Service\IndexingService;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

abstract class AbstractIndexCommand extends Command
{
/**
* @var IndexingService
*/
protected $indexingService;

public function __construct(...$arguments)
{
parent::__construct(...$arguments);

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->indexingService = $objectManager->get(IndexingService::class);
}
}
33 changes: 33 additions & 0 deletions Classes/Command/Index/ResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Index;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class ResetCommand extends AbstractIndexCommand
{
/**
* Configures the current command.
*/
protected function configure()
{
$this
->setDescription('Reset search index')
->addArgument('language', InputArgument::OPTIONAL, 'Language of index to reset');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->indexingService->resetIndex(
$input->hasArgument('language') ? (int)$input->getArgument('language') : null
);

return 0;
}
}
30 changes: 30 additions & 0 deletions Classes/Command/Index/SetupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Index;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class SetupCommand extends AbstractIndexCommand
{
/**
* Configures the current command.
*/
protected function configure()
{
$this
->setDescription('Set up everything for search')
->setHelp('Sets up indices and pipelines and verifies the indexer configuration, needs to be run after installation. Can be run multiple times to ensure correct setup.');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->indexingService->setup();

return 0;
}
}
31 changes: 31 additions & 0 deletions Classes/Command/Index/UpdateFullCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Index;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class UpdateFullCommand extends AbstractIndexCommand
{
/**
* Configures the current command.
*/
protected function configure()
{
$this
->setDescription('Process search indexers')
->addArgument('type', InputArgument::OPTIONAL, 'Type to run indexers for');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->indexingService->indexFull($input->getArgument('type'));

return 0;
}
}
31 changes: 31 additions & 0 deletions Classes/Command/Index/UpdatePartialCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Index;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class UpdatePartialCommand extends AbstractIndexCommand
{
/**
* Configures the current command.
*/
protected function configure()
{
$this
->setDescription('Process search indexer updates')
->addArgument('type', InputArgument::OPTIONAL, 'Type to run indexers for');
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->indexingService->indexPartial($input->getArgument('type'));

return 0;
}
}
62 changes: 62 additions & 0 deletions Classes/Command/Legacy/AbstractLegacyCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Legacy;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @deprecated will be removed with Searchable v4
*/
abstract class AbstractLegacyCommand extends Command
{
/**
* The replacement for this deprecated legacy command
*
* @var string
*/
protected $replacementCommand;

/**
* @return string
*/
public function getDescription()
{
return sprintf(
'%s <comment>(deprecated)</>',
$this->getApplication()->find($this->replacementCommand)->getDescription()
);
}

/**
* @return \Symfony\Component\Console\Input\InputDefinition
*/
public function getDefinition()
{
return $this->getApplication()->find($this->replacementCommand)->getDefinition();
}

/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$deprecationMessage = sprintf(
'The CLI command "%s" is deprecated and will be removed with Searchable v4, use "%s" instead',
$this->getName(),
$this->replacementCommand
);

if (!method_exists(GeneralUtility::class, 'deprecationLog')) { // TYPO3v10
trigger_error($deprecationMessage, E_USER_DEPRECATED);
} else {
// @extensionScannerIgnoreLine
GeneralUtility::deprecationLog($deprecationMessage);
}

return $this->getApplication()->find($this->replacementCommand)->run($input, $output);
}
}
12 changes: 12 additions & 0 deletions Classes/Command/Legacy/LegacyResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Legacy;

final class LegacyResetCommand extends AbstractLegacyCommand
{
/**
* @var string
*/
protected $replacementCommand = 'index:reset';
}
12 changes: 12 additions & 0 deletions Classes/Command/Legacy/LegacySetupCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Legacy;

final class LegacySetupCommand extends AbstractLegacyCommand
{
/**
* @var string
*/
protected $replacementCommand = 'index:setup';
}
12 changes: 12 additions & 0 deletions Classes/Command/Legacy/LegacyUpdateFullCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Legacy;

final class LegacyUpdateFullCommand extends AbstractLegacyCommand
{
/**
* @var string
*/
protected $replacementCommand = 'index:update:full';
}
12 changes: 12 additions & 0 deletions Classes/Command/Legacy/LegacyUpdatePartialCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types = 1);

namespace PAGEmachine\Searchable\Command\Legacy;

final class LegacyUpdatePartialCommand extends AbstractLegacyCommand
{
/**
* @var string
*/
protected $replacementCommand = 'index:update:partial';
}
72 changes: 0 additions & 72 deletions Classes/Command/SearchableCommandController.php

This file was deleted.

12 changes: 10 additions & 2 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace PAGEmachine\Searchable\Controller;

use PAGEmachine\Searchable\Connection;
use PAGEmachine\Searchable\Indexer\IndexerFactory;
use PAGEmachine\Searchable\IndexManager;
use PAGEmachine\Searchable\Search;
use PAGEmachine\Searchable\Service\ExtconfService;
Expand All @@ -17,11 +18,18 @@
class BackendController extends ActionController
{
/**
* @var \PAGEmachine\Searchable\Indexer\IndexerFactory
* @inject
* @var IndexerFactory $indexerFactory
*/
protected $indexerFactory;

/**
* @param IndexerFactory $indexerFactory
*/
public function injectIndexerFactory(IndexerFactory $indexerFactory): void
{
$this->indexerFactory = $indexerFactory;
}

/**
* Backend Template Container
*
Expand Down
Loading

0 comments on commit 81e42f2

Please sign in to comment.