Skip to content

Commit

Permalink
[TASK] Update for flow 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kaystrobach committed Jul 20, 2021
1 parent 3e8cc85 commit 25897c3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Neos\Flow\Persistence\QueryInterface;
use Neos\Flow\Persistence\QueryResultInterface;
use Neos\Utility\ObjectAccess;
use Psr\Log\LoggerInterface;

/**
* @Flow\Scope("singleton")
Expand All @@ -31,10 +32,9 @@ class SearchableRepository extends Repository implements SearchableRepositoryInt
protected $mapperUtility;

/**
* @var \Neos\Flow\Log\SystemLoggerInterface
* @Flow\Inject()
* @var LoggerInterface
*/
protected $systemLogger;
protected $logger;

/**
* @var \KayStrobach\VisualSearch\Domain\Session\QueryStorage
Expand Down Expand Up @@ -108,7 +108,12 @@ public function findBySearchTerm($query, $term = '', $facetConfiguration = [], $
/** @var $doctrineQuery \Doctrine\ORM\Query */
$doctrineQuery = $doctrineQueryBuilder->getQuery();

$this->systemLogger->log('findBySearchTerm:'.$doctrineQuery->getSQL(), LOG_ALERT);
$this->logger->info(
'findBySearchTerm',
[
$doctrineQuery->getSQL()
]
);

return $queryObject->execute();
}
Expand Down Expand Up @@ -156,7 +161,12 @@ public function findByQuery($query, $searchName = null)
// merge demands from VisualSearch.yaml and the
$demands = array_merge($demands, $this->mapperUtility->buildQuery($searchName, $query, $queryObject));

$this->systemLogger->log('demands: '.Debugger::renderDump($demands, 2, true));
$this->logger->info(
'demands',
[
Debugger::renderDump($demands, 2, true)
]
);

if (count($demands) > 0) {
$queryObject->matching(
Expand All @@ -170,9 +180,9 @@ public function findByQuery($query, $searchName = null)
$doctrineQueryBuilder = ObjectAccess::getProperty($queryObject, 'queryBuilder', true);
/** @var $doctrineQuery \Doctrine\ORM\Query */
$doctrineQuery = $doctrineQueryBuilder->getQuery();
$this->systemLogger->log(

$this->logger->debug(
'findByQuery:',
LOG_DEBUG,
[
'sql' => $doctrineQuery->getSQL(),
'parameters' => Debugger::renderDump($doctrineQuery->getParameters(), 2, true),
Expand Down
31 changes: 18 additions & 13 deletions Classes/KayStrobach/VisualSearch/Utility/MapperUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
use Neos\Flow\Log\SystemLoggerInterface;
use Neos\Flow\ObjectManagement\Exception\UnknownObjectException;
use Neos\Flow\ObjectManagement\ObjectManager;
use Neos\Flow\Persistence\Doctrine\Query;
use Neos\Flow\Persistence\Doctrine\Repository;
use Psr\Log\LoggerInterface;

class MapperUtility
{
/**
* @var SystemLoggerInterface
* @Flow\Inject
* @var LoggerInterface
*/
protected $systemLogger;
protected $logger;

/**
* @var ObjectManager
Expand Down Expand Up @@ -88,13 +87,19 @@ public function buildQuery($searchName, $query, Query $queryObject)
$repository = $this->objectManager->get($repositoryClassName);
$value = $repository->findByIdentifier($queryEntry['value']);
if (is_object($value)) {
$this->systemLogger->log('Facet: ' . $facet . ' = ' . $queryEntry['value'] . ' as Object ' . get_class($value), LOG_DEBUG);
$this->logger->debug(
'Facet: ' . $facet . ' = ' . $queryEntry['value'] . ' as Object ' . get_class($value)
);
} else {
$this->systemLogger->log('Facet: ' . $facet . ' = ' . $queryEntry['value'] . ' as literal', LOG_DEBUG);
$this->logger->debug(
'Facet: ' . $facet . ' = ' . $queryEntry['value'] . ' as literal'
);
}
} else {
$value = $queryEntry['value'];
$this->systemLogger->log('Facet: '.$facet.' = '.$queryEntry['value'].' as string', LOG_DEBUG);
$this->logger->debug(
'Facet: '.$facet.' = '.$queryEntry['value'].' as string'
);
}

foreach ($searchConfiguration[$facet]['matches'] as $type => $fields) {
Expand All @@ -106,9 +111,8 @@ public function buildQuery($searchName, $query, Query $queryObject)
);

if (!$matcher instanceof SimpleDemandInterface) {
$this->systemLogger->log(
'Ignored "' . $type . '" converted to "' . $matcherClassName . '" as it is not a SimpleDemandInterface, but a ' . get_parent_class($matcherClassName),
LOG_DEBUG
$this->logger->debug(
'Ignored "' . $type . '" converted to "' . $matcherClassName . '" as it is not a SimpleDemandInterface, but a ' . get_parent_class($matcherClassName)
);
continue;
}
Expand All @@ -117,10 +121,11 @@ public function buildQuery($searchName, $query, Query $queryObject)
$subDemands = $matcher->getDemands($value);
if ($subDemands !== null) {
$demands[] = $subDemands;
$this->systemLogger->log(
$this->logger->debug(
'Adding demands',
LOG_DEBUG,
$subDemands
[
$subDemands
]
);
}
}
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ use TYPO3\Flow\Reflection\ObjectAccess;
* @Flow\Scope("singleton")
*/
class StudentRepository extends SearchableRepository {
/**
* @Flow\Inject
* @var \TYPO3\Flow\Log\SystemLoggerInterface
*/
protected $systemLogger;
/**
* @param array $query
* @return \TYPO3\Flow\Persistence\QueryResultInterface
Expand Down Expand Up @@ -153,7 +147,7 @@ In a controller you can then use these lines to filter the resultset:
* @Flow\Inject
*/
protected $queryStorage;
public function indexAction() {
$this->view->assign('students', $this->studentRepository->findByQuery($this->queryStorage->getQuery('students')));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "neos-package",
"description": "package to handle advanced facetted searches",
"require": {
"neos/flow": "~4.0 || ~5.0 || ~6.0"
"neos/flow": "~5.0 || ~6.0"
},
"autoload": {
"psr-0": {
Expand Down

0 comments on commit 25897c3

Please sign in to comment.