Skip to content

Commit

Permalink
Merge pull request #22 from pagemachine/typo3v9-conditions
Browse files Browse the repository at this point in the history
Replaced deprecated TypoScript conditions for TYPO3v9
  • Loading branch information
mbrodala authored Oct 6, 2020
2 parents ea6d121 + 6d3c6aa commit dc1ca03
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 14 deletions.
7 changes: 3 additions & 4 deletions Classes/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public static function getClient()
{
if (self::$client == null) {
self::$client = ClientBuilder::create()
->setHosts(
ExtconfService::getInstance()
->getHostsSettings()
)->build();
->setHosts(ExtconfService::getInstance()->getHostsSettings())
->build();
}
return self::$client;
}
Expand All @@ -46,6 +44,7 @@ public static function getClient()
public static function isHealthy()
{
$ping = self::getClient()->ping();

return $ping;
}
}
4 changes: 3 additions & 1 deletion Classes/Service/IndexingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ protected function applyEnvironment(array $environment): array
protected function assertConnectionHealthy(): void
{
if (!Connection::isHealthy()) {
throw new \RuntimeException('Elasticsearch is offline', 1599662577);
$hosts = ExtconfService::getInstance()->getHostsSettings();

throw new \RuntimeException(sprintf('Elasticsearch at "%s" is offline', implode(', ', $hosts)), 1599662577);
}
}

Expand Down
41 changes: 41 additions & 0 deletions Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugin.tx_searchable {
view {
# cat=plugin.tx_searchable/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:searchable/Resources/Private/Templates/
# cat=plugin.tx_searchable/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:searchable/Resources/Private/Partials/
# cat=plugin.tx_searchable/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:searchable/Resources/Private/Layouts/
}
persistence {
# cat=plugin.tx_searchable//a; type=string; label=Default storage PID
storagePid =
}
settings {
# cat=plugin.tx_searchable/enable/a; type=boolean; label=Include jQuery (disable this if you already have jQuery in your page)
includejQuery = 0

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Include jQuery Autocomplete (used for Autosuggest loading)
includejQueryAutocomplete = 1

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Include Mustache (Used for live search result templating)
includeMustache = 1

# cat=plugin.tx_searchable//a; type=int+; label=Search result page
resultPage =
# cat=plugin.tx_searchable//a; type=int+; label=Results per page
search.resultsPerPage = 10

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Show pre-rendered result preview
result.showPreview = 1

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Show highlighted text snippets in result
result.showHighlighting = 0

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Show Suggestions ("did you mean")
result.showSuggestions = 1

# cat=plugin.tx_searchable/enable/a; type=boolean; label=Load completion suggestions ("autosuggest")
features.completionSuggest = 0
}
}
76 changes: 76 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plugin.tx_searchable {
view {
templateRootPaths.0 = {$plugin.tx_searchable.view.templateRootPath}
partialRootPaths.0 = {$plugin.tx_searchable.view.partialRootPath}
layoutRootPaths.0 = {$plugin.tx_searchable.view.layoutRootPath}

pluginNamespace = tx_searchable
}
persistence {
storagePid = {$plugin.tx_searchable.persistence.storagePid}
}
settings {
includejQuery = {$plugin.tx_searchable.includejQuery}
includejQueryAutocomplete = {$plugin.tx_searchable.includejQueryAutocomplete}

resultPage = {$plugin.tx_searchable.settings.resultPage}

search {
resultsPerPage = {$plugin.tx_searchable.settings.search.resultsPerPage}
}
result {
showPreview = {$plugin.tx_searchable.settings.result.showPreview}
}
}
features {
requireCHashArgumentForActionArguments = 0
}
}

plugin.tx_searchable_searchbar < plugin.tx_searchable
plugin.tx_searchable_searchbar {
settings {
features {
completionSuggest = {$plugin.tx_searchable.settings.features.completionSuggest}
}
}
}

plugin.tx_searchable_results < plugin.tx_searchable
plugin.tx_searchable_results {
settings {
features {
//@todo rename constants in V2
highlighting = {$plugin.tx_searchable.settings.result.showHighlighting}
termSuggest = {$plugin.tx_searchable.settings.result.showSuggestions}
}
}
}


module.tx_searchable {
settings < plugin.tx_searchable.settings
persistence < plugin.tx_searchable.persistence
view < plugin.tx_searchable.view
}

page.includeCSS.searchable = EXT:searchable/Resources/Public/Css/searchable.css

# Include JQuery if activated
[{$plugin.tx_searchable.settings.includejQuery} == 1]
page.includeJSFooterlibs.jQuery = EXT:searchable/Resources/Public/JavaScript/jquery-3.2.1.min.js
[global]

# Include Autocomplete if activated
[{$plugin.tx_searchable.settings.includejQueryAutocomplete} == 1]
page.includeJSFooter.jQueryAutocomplete = EXT:searchable/Resources/Public/JavaScript/jquery.autocomplete.min.js
[global]

# Include mustache if activated
[{$plugin.tx_searchable.settings.includeMustache} == 1]
page.includeJSFooterlibs.mustache = EXT:searchable/Resources/Public/JavaScript/mustache.min.js
[global]

page.includeJSFooter.URI = EXT:searchable/Resources/Public/JavaScript/URI.js
page.includeJSFooter.searchable = EXT:searchable/Resources/Public/JavaScript/searchable.js

32 changes: 25 additions & 7 deletions Tests/Functional/AbstractElasticsearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Page\PageRepository;

Expand Down Expand Up @@ -84,21 +85,38 @@ protected function setUp()
]
);

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->indexingService = $objectManager->get(IndexingService::class);
$this->indexingService->setup();

$this->startWebserver();

$this->getDatabaseConnection()->insertArray('pages', [
'uid' => 1,
'doktype' => PageRepository::DOKTYPE_DEFAULT,
'title' => 'Root',
]);

$typoScriptConstantsFile = 'EXT:searchable/Configuration/TypoScript/constants.typoscript';
$typoScriptSetupFile = 'EXT:searchable/Configuration/TypoScript/setup.typoscript';
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9', '<')) {
$typoScriptConstantsFile = 'EXT:searchable/Configuration/TypoScript/constants.txt';
$typoScriptSetupFile = 'EXT:searchable/Configuration/TypoScript/setup.txt';
}
$this->setUpFrontendRootPage(1, [
__DIR__ . '/Fixtures/TypoScript/page.typoscript',
'EXT:searchable/Configuration/Typoscript/setup.txt',
$typoScriptSetupFile,
]);
$this->getDatabaseConnection()->updateArray(
'sys_template',
[
'pid' => 1,
],
[
'constants' => '<INCLUDE_TYPOSCRIPT: source="FILE:' . $typoScriptConstantsFile . '">',
]
);

$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->indexingService = $objectManager->get(IndexingService::class);
$this->indexingService->setup();

$this->startWebserver();

// Update internally created site to flush all caches
if (class_exists(SiteConfiguration::class)) {
$siteConfiguration = GeneralUtility::makeInstance(
Expand Down
1 change: 0 additions & 1 deletion ext_typoscript_constants.txt

This file was deleted.

1 change: 0 additions & 1 deletion ext_typoscript_setup.txt

This file was deleted.

0 comments on commit dc1ca03

Please sign in to comment.