-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthias Richter
committed
Aug 31, 2023
0 parents
commit 4b3a522
Showing
9 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Slub\LisztCommon\Common; | ||
|
||
/* | ||
* This file is part of the Liszt Catalog Raisonne project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
*/ | ||
|
||
use Illuminate\Support\Collection; | ||
use Elasticsearch\Client; | ||
use Elasticsearch\ClientBuilder; | ||
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class ElasticClientBuilder extends ClientBuilder { | ||
|
||
protected string $caFilePath; | ||
protected Collection $extConf; | ||
protected array $hosts; | ||
protected string $password; | ||
|
||
public static function getClient(): Client | ||
{ | ||
return parent::create()-> | ||
initialize()-> | ||
autoconfig()-> | ||
build(); | ||
} | ||
|
||
protected function initialize(): ElasticClientBuilder | ||
{ | ||
$this->extConf = new Collection( | ||
GeneralUtility::makeInstance(ExtensionConfiguration::class)-> | ||
get('liszt_common')); | ||
|
||
$this->hosts = [ $this->extConf->get('elasticHostName') ]; | ||
$this->setCaFilePath(); | ||
$this->setPassword(); | ||
|
||
return $this; | ||
} | ||
|
||
protected function autoconfig (): ElasticClientBuilder { | ||
$this->sethosts($this->hosts); | ||
if ($this->password) { | ||
$this->setBasicAuthentication('elastic', $this->password); | ||
} | ||
if ($this->caFilePath) { | ||
$this->setSSLVerification($this->caFilePath); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
private function setCaFilePath(): void | ||
{ | ||
if ($this->extConf->get('elasticCaFileName') == '') { | ||
$this->caFilePath = ''; | ||
return; | ||
} | ||
|
||
$this->caFilePath = $this->extConf-> | ||
only('elastcCredentialsFilePath', 'elasticCaFileName')-> | ||
implode('/'); | ||
} | ||
|
||
private function setPassword(): void | ||
{ | ||
if ($this->extConf->get('elasticPwdFileName') == '') { | ||
$this->password = ''; | ||
return; | ||
} | ||
|
||
$passwordFilePath = $this->extConf-> | ||
only('elasticCredentialsFilePath', 'elasticPwdFileName')-> | ||
implode('/'); | ||
$passwordFile = fopen($passwordFilePath, 'r') or | ||
die($passwordFilePath . ' not found. Check your extension\'s configuration'); | ||
|
||
$this->password = $passwordFile->getContents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace Slub\LisztCommon\Controller; | ||
|
||
use Elasticsearch\ClientBuilder; | ||
use Elasticsearch\Client; | ||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; | ||
|
||
/*** | ||
* | ||
* This file is part of the "Publisher Database" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* (c) 2020 Matthias Richter <[email protected]>, SLUB Dresden | ||
* | ||
***/ | ||
/** | ||
* ClientEnabledController | ||
*/ | ||
abstract class ClientEnabledController extends ActionController | ||
{ | ||
|
||
/** | ||
* elasticClient | ||
* @var Client | ||
*/ | ||
protected $elasticClient = null; | ||
|
||
/** | ||
* initialize show action: firing up client | ||
*/ | ||
public function initializeClient() | ||
{ | ||
$this->elasticClient = ElasticClientBuilder::create()-> | ||
autoconfig()-> | ||
build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
Slub\LisztCommon\: | ||
resource: '../Classes/*' | ||
exclude: '../Classes/Domain/Model/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
page.includeJSFooterlibs.Elasticsearch = EXT:liszt_common/Resources/Public/JavaScript/Src/elasticsearch.min.js | ||
page.includeJSFooter.UrlManager = EXT:liszt_common/Resources/Public/JavaScript/Src/UrlManager.js | ||
page.includeJSFooter.Constants = EXT:liszt_common/Resources/Public/JavaScript/Src/Constants.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const LISZT_COMMON_MAX_SIZE = 10000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class UrlManager { | ||
|
||
#mappings = []; | ||
#body = {}; | ||
#url = new URL(location); | ||
|
||
get body() { | ||
this.updateMappings(); | ||
return this.#body; | ||
} | ||
|
||
updateMappings() { | ||
for (let key in this.#mappings) { | ||
const value = this.#url.searchParams.get(key); | ||
const path = this.#mappings[key].split('.'); | ||
if (value) { | ||
let cursor = this.#body; | ||
for (let pathSegment of path.slice(0, -1)) { | ||
cursor[pathSegment] ??= {}; | ||
cursor = cursor[pathSegment]; | ||
} | ||
cursor[path.slice(-1)[0]] = value; | ||
} else { | ||
this.#body = {}; | ||
} | ||
} | ||
} | ||
|
||
registerMapping(mapping) { | ||
for (let key in mapping) { | ||
this.#mappings[key] = mapping[key]; | ||
} | ||
} | ||
|
||
setParam(key, value) { | ||
if (value) { | ||
this.#url.searchParams.set(key, value); | ||
} else { | ||
this.#url.searchParams.delete(key); | ||
} | ||
window.history.pushState({}, '', this.#url.href); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "slub/liszt-common", | ||
"description": "common tools for the Liszt catalog raisonné", | ||
"type": "typo3-cms-extension", | ||
"license": [ | ||
"GPL-2.0-or-later" | ||
], | ||
"require": { | ||
"typo3/cms-core": "^11.5", | ||
"elasticsearch/elasticsearch": "^7" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slub\\LisztCommon\\": "Classes/" | ||
} | ||
}, | ||
"extra": { | ||
"typo3/cms": { | ||
"extension-key": "liszt_common" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# cat=Elasticsearch; type=string; label=LLL:EXT:liszt_common/Resources/Private/Language/Labels.xml:config.elasticHostName | ||
elasticHostName = https://sdvelasticmusikverlage:9200 | ||
# cat=Elasticsearch; type=string; label=LLL:EXT:liszt_common/Resources/Private/Language/Labels.xml:config.elasticCredentialsFilePath | ||
elasticCredentialsFilePath = http_ca.crt | ||
# cat=Elasticsearch; type=string; label=LLL:EXT:liszt_common/Resources/Private/Language/Labels.xml:config.elasticPwdFileName | ||
elasticPwdFileName = elastic_pwd.txt | ||
# cat=Elasticsearch; type=string; label=LLL:EXT:liszt_common/Resources/Private/Language/Labels.xml:config.elasticCaFileName | ||
elasticCaFileFilePath = http_ca.crt |