Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rector #114

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use PAGEmachine\Searchable\IndexManager;
use PAGEmachine\Searchable\Search;
use PAGEmachine\Searchable\Service\ExtconfService;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -21,6 +23,11 @@ class BackendController extends ActionController
* @var IndexerFactory $indexerFactory
*/
protected $indexerFactory;
private ModuleTemplateFactory $moduleTemplateFactory;
public function __construct(ModuleTemplateFactory $moduleTemplateFactory)
{
$this->moduleTemplateFactory = $moduleTemplateFactory;
}

/**
* @param IndexerFactory $indexerFactory
Expand All @@ -30,20 +37,12 @@ public function injectIndexerFactory(IndexerFactory $indexerFactory): void
$this->indexerFactory = $indexerFactory;
}

/**
* Backend Template Container
*
* @var string
*/
protected $defaultViewObjectName = BackendTemplateView::class;

/**
* Backend controller overview action to show general information about the elasticsearch instance
*
* @return void
*/
public function startAction()
public function startAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
try {
$this->view->assign("updates", $this->fetchScheduledUpdates());

Expand All @@ -54,6 +53,8 @@ public function startAction()
} catch (\Exception $e) {
$this->addFlashMessage($e->getMessage(), get_class($e), AbstractMessage::ERROR);
}
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
}

/**
Expand Down Expand Up @@ -84,25 +85,27 @@ protected function fetchScheduledUpdates()
* Function to run search tests in the backend.
* @todo remove this when everything works or extend to a debuggig device
* @param string $term
* @return void
*/
public function searchAction($term)
public function searchAction($term): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$result = Search::getInstance()->search($term);

$this->view->assign('result', $result);
$this->view->assign('term', $term);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
}

/**
* Runs a http request directly to elasticsearch (debug)
*
* @param string $url
* @param string $body
* @return void
*/
public function requestAction($url = '', $body = '')
public function requestAction($url = '', $body = ''): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
if ($url != '') {
$result = $this->request($url, $body);

Expand Down Expand Up @@ -131,6 +134,8 @@ public function requestAction($url = '', $body = '')

$this->view->assign("url", $url);
$this->view->assign("body", $body);
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
}

/**
Expand All @@ -142,7 +147,7 @@ public function requestAction($url = '', $body = '')
*/
protected function request($url, $body)
{
$requestFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Http\RequestFactory::class);
$requestFactory = GeneralUtility::makeInstance(RequestFactory::class);

$response = $requestFactory->request(
$url,
Expand Down
14 changes: 7 additions & 7 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace PAGEmachine\Searchable\Controller;

use PAGEmachine\Searchable\Query\SearchQuery;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/*
Expand Down Expand Up @@ -32,32 +33,30 @@ public function initializeObject()
* Renders the search form
*
* @param string $term
* @return void
*/
public function searchbarAction($term = null)
public function searchbarAction($term = null): ResponseInterface
{
$this->view->assign("settings", $this->settings);
$this->view->assign("term", $term);
return $this->htmlResponse();
}

/**
* Renders the search form for a live search
*
* @return void
*/
public function liveSearchbarAction()
public function liveSearchbarAction(): ResponseInterface
{
$this->view->assign("settings", $this->settings);
return $this->htmlResponse();
}

/**
* Performs a search and returns the result
*
* @param string $term
* @param int $page
* @return void
*/
public function resultsAction($term = null, $page = 1)
public function resultsAction($term = null, $page = 1): ResponseInterface
{
$result = [];

Expand All @@ -82,5 +81,6 @@ public function resultsAction($term = null, $page = 1)
'totalPages' => $pagesArray,
'result' => $result,
]);
return $this->htmlResponse();
}
}
2 changes: 1 addition & 1 deletion Classes/DataCollector/FileDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FileDataCollector extends TcaDataCollector implements DataCollectorInterfa
],
'subCollectors' => [
'file' => [
'className' => \PAGEmachine\Searchable\DataCollector\TcaDataCollector::class,
'className' => TcaDataCollector::class,
'config' => [
'field' => 'file',
'fields' => [],
Expand Down
11 changes: 7 additions & 4 deletions Classes/DataCollector/PagesDataCollector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace PAGEmachine\Searchable\DataCollector;

use PAGEmachine\Searchable\DataCollector\RelationResolver\TtContentRelationResolver;
use PAGEmachine\Searchable\DataCollector\Utility\OverlayUtility;
use PAGEmachine\Searchable\Feature\CompletionSuggestFeature;
use PAGEmachine\Searchable\Feature\HtmlStripFeature;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;

Expand All @@ -28,25 +31,25 @@ class PagesDataCollector extends TcaDataCollector implements DataCollectorInterf
],
'features' => [
'completion' => [
'className' => \PAGEmachine\Searchable\Feature\CompletionSuggestFeature::class,
'className' => CompletionSuggestFeature::class,
'config' => [
'fields' => [
'title',
],
],
],
'htmlStrip' => [
'className' => \PAGEmachine\Searchable\Feature\HtmlStripFeature::class,
'className' => HtmlStripFeature::class,
],
],
'subCollectors' => [
'content' => [
'className' => \PAGEmachine\Searchable\DataCollector\TcaDataCollector::class,
'className' => TcaDataCollector::class,
'config' => [
'field' => 'content',
'table' => 'tt_content',
'resolver' => [
'className' => \PAGEmachine\Searchable\DataCollector\RelationResolver\TtContentRelationResolver::class,
'className' => TtContentRelationResolver::class,
],
'fields' => [
'header',
Expand Down
6 changes: 4 additions & 2 deletions Classes/DataCollector/RelationResolver/ResolverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
namespace PAGEmachine\Searchable\DataCollector\RelationResolver;

use PAGEmachine\Searchable\DataCollector\DataCollectorInterface;
use PAGEmachine\Searchable\DataCollector\RelationResolver\FormEngine\InlineRelationResolver;
use PAGEmachine\Searchable\DataCollector\RelationResolver\FormEngine\SelectRelationResolver;
use TYPO3\CMS\Core\SingletonInterface;

/*
Expand All @@ -18,8 +20,8 @@ class ResolverManager implements SingletonInterface
*/
protected $relationResolvers = [
'FormEngine' => [
'select' => \PAGEmachine\Searchable\DataCollector\RelationResolver\FormEngine\SelectRelationResolver::class,
'inline' => \PAGEmachine\Searchable\DataCollector\RelationResolver\FormEngine\InlineRelationResolver::class,
'select' => SelectRelationResolver::class,
'inline' => InlineRelationResolver::class,
],

];
Expand Down
24 changes: 16 additions & 8 deletions Classes/DataCollector/TCA/SearchableRecordGroup.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?php
namespace PAGEmachine\Searchable\DataCollector\TCA;

use PAGEmachine\Searchable\DataCollector\TCA\DataProvider\TcaInlineCopyToDbRecord;
use PAGEmachine\Searchable\DataCollector\TCA\DataProvider\TcaSelectRelations;
use TYPO3\CMS\Backend\Form\FormDataGroupInterface;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessRecordTitle;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessShowitem;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaInline;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaInputPlaceholders;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems;
use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectTreeItems;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -21,26 +29,26 @@ public function __construct()
$dataProvider = $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'];

//Replace TcaSelectItems DataProvider with a custom one that does not fetch all available items for relations
unset($dataProvider[\TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems::class]);
$dataProvider[\PAGEmachine\Searchable\DataCollector\TCA\DataProvider\TcaSelectRelations::class] = [
unset($dataProvider[TcaSelectItems::class]);
$dataProvider[TcaSelectRelations::class] = [
'depends' => [],
'before' => [
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaInputPlaceholders::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectTreeItems::class,
TcaInputPlaceholders::class,
TcaSelectTreeItems::class,
],
];


//Unset DataProvider which determines the items to process. This information will be handed over in the compiler input array
unset($dataProvider[\TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessShowitem::class]);
unset($dataProvider[TcaColumnsProcessShowitem::class]);

//unset record title provider - no need
unset($dataProvider[\TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsProcessRecordTitle::class]);
unset($dataProvider[TcaColumnsProcessRecordTitle::class]);

//Add custom inline provider to copy children to database record
$dataProvider[\PAGEmachine\Searchable\DataCollector\TCA\DataProvider\TcaInlineCopyToDbRecord::class] = [
$dataProvider[TcaInlineCopyToDbRecord::class] = [
'depends' => [
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaInline::class,
TcaInline::class,
],
];

Expand Down
4 changes: 2 additions & 2 deletions Classes/DataCollector/Utility/FieldListUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class FieldListUtility implements SingletonInterface
{
const MODE_WHITELIST = 'whitelist';
const MODE_BLACKLIST = 'blacklist';
public const MODE_WHITELIST = 'whitelist';
public const MODE_BLACKLIST = 'blacklist';

/**
* @return FieldListUtility
Expand Down
27 changes: 14 additions & 13 deletions Classes/Enumeration/TcaType.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php
namespace PAGEmachine\Searchable\Enumeration;

use TYPO3\CMS\Core\Type\Enumeration;

/*
* This file is part of the PAGEmachine Searchable project.
*/

class TcaType extends \TYPO3\CMS\Core\Type\Enumeration
class TcaType extends Enumeration
{
const INPUT = "input";
const TEXT = "text";
const CHECK = "check";
const RADIO = "radio";
const SELECT = "select";
const GROUP = "group";
const NONE = "none";
const PASSTHROUGH = "passthrough";
const USER = "user";
const FLEX = "flex";
const INLINE = "inline";
public const INPUT = "input";
public const TEXT = "text";
public const CHECK = "check";
public const RADIO = "radio";
public const SELECT = "select";
public const GROUP = "group";
public const NONE = "none";
public const PASSTHROUGH = "passthrough";
public const USER = "user";
public const FLEX = "flex";
public const INLINE = "inline";

/**
* Returns true if the type is of plain mapping type (supported type with no relations)
Expand Down
5 changes: 3 additions & 2 deletions Classes/Hook/DynamicFlexFormHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace PAGEmachine\Searchable\Hook;

use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Object\ObjectManager;
Expand Down Expand Up @@ -33,7 +34,7 @@ class DynamicFlexFormHook
public function parseDataStructureByIdentifierPostProcess($dataStructure, $identifier)
{
if ($identifier['tableName'] == 'tt_content' && $identifier['fieldName'] == 'pi_flexform' && in_array($identifier['dataStructureKey'], $this->allowedIdentifiers)) {
list($pluginKey, $listType) = explode(",", $identifier['dataStructureKey']);
[$pluginKey, $listType] = explode(",", $identifier['dataStructureKey']);
$dataStructure['sheets']['features'] = $this->buildFlexSettingsFromTSSettings($pluginKey);
}
return $dataStructure;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function getPluginSettings($pluginName)
$pluginSignature = strtolower('tx_' . $pluginName);
if (is_array($setup['plugin.'][$pluginSignature . '.'])) {
$overruleConfiguration = $typoScriptService->convertTypoScriptArrayToPlainArray($setup['plugin.'][$pluginSignature . '.']);
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
}
}
return $pluginConfiguration;
Expand Down
10 changes: 6 additions & 4 deletions Classes/Indexer/FileIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
/*
* This file is part of the PAGEmachine Searchable project.
*/

use PAGEmachine\Searchable\DataCollector\FileDataCollector;
use PAGEmachine\Searchable\LinkBuilder\FileLinkBuilder;
use PAGEmachine\Searchable\Mapper\DefaultMapper;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -21,13 +23,13 @@ class FileIndexer extends TcaIndexer
'fileField' => 'file',
'bulkSize' => 2,
'collector' => [
'className' => \PAGEmachine\Searchable\DataCollector\FileDataCollector::class,
'className' => FileDataCollector::class,
],
'link' => [
'className' => \PAGEmachine\Searchable\LinkBuilder\FileLinkBuilder::class,
'className' => FileLinkBuilder::class,
],
'mapper' => [
'className' => \PAGEmachine\Searchable\Mapper\DefaultMapper::class,
'className' => DefaultMapper::class,
],
'mapping' => [
'_all' => [
Expand Down
Loading