-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functionality for AdminSettingsSubscriber
- Loading branch information
Showing
3 changed files
with
95 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,74 @@ | ||
<?php | ||
Check failure on line 1 in src/EventSubscriber/AdminSettingsSubscriber.php GitHub Actions / Qodana for PHPMissing strict types declaration
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\GenericDataIndexBundle\EventSubscriber; | ||
|
||
use Exception; | ||
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateServiceInterface; | ||
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageServiceInterface; | ||
use Pimcore\Event\SystemEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\EventDispatcher\GenericEvent; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AdminSettingsSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private readonly IndexUpdateServiceInterface $indexUpdateService, | ||
private readonly LanguageServiceInterface $languageService | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
SystemEvents::SAVE_ACTION_SYSTEM_SETTINGS => 'updateSearchIndex', | ||
]; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function updateSearchIndex(GenericEvent $event): void | ||
{ | ||
$arguments = $event->getArguments(); | ||
$currentLanguages = $arguments['existingValues']['general']['valid_languages']; | ||
$newLanguages = $this->languageService->getNewLanguages( | ||
explode(',', $arguments['values']['general.validLanguages']) | ||
); | ||
|
||
if (empty($currentLanguages) && !empty($newLanguages)) { | ||
$this->setLanguagesAndUpdate($newLanguages); | ||
|
||
return; | ||
} | ||
|
||
sort($currentLanguages); | ||
sort($newLanguages); | ||
|
||
if ($currentLanguages !== $newLanguages) { | ||
$this->setLanguagesAndUpdate($newLanguages); | ||
} | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
private function setLanguagesAndUpdate( | ||
array $newLanguages | ||
): void | ||
{ | ||
$this->languageService->setValidLanguages($newLanguages); | ||
$this->indexUpdateService->updateAll(); | ||
} | ||
} |
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
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