Commit 7348d672 authored by Tino Goratsch's avatar Tino Goratsch

fix new installation if the sample data should be installed too

parent 53dbeac6
......@@ -3,11 +3,6 @@ services:
class: ACP3\Core\I18n\Translator
arguments:
- '@core.i18n.dictionary_cache'
configurator: 'core.i18n.translator_configurator:configure'
core.i18n.translator_configurator:
class: ACP3\Core\I18n\TranslatorConfigurator
arguments:
- '@core.config'
core.lang:
......
......@@ -7,6 +7,9 @@
namespace ACP3\Core\I18n;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
class Translator
{
/**
......@@ -14,9 +17,9 @@ class Translator
*/
private $dictionaryCache;
/**
* @var string
* @var string|null
*/
private $locale = '';
private $locale;
/**
* @var array
*/
......@@ -25,11 +28,17 @@ class Translator
* @var array
*/
private $buffer = [];
/**
* @var \ACP3\Core\Settings\SettingsInterface
*/
private $settings;
public function __construct(
DictionaryCacheInterface $dictionaryCache
DictionaryCacheInterface $dictionaryCache,
SettingsInterface $settings
) {
$this->dictionaryCache = $dictionaryCache;
$this->settings = $settings;
}
/**
......@@ -50,6 +59,10 @@ class Translator
public function getLocale(): string
{
if ($this->locale === null) {
$this->locale = $this->settings->getSettings(Schema::MODULE_NAME)['lang'];
}
return $this->locale;
}
......
<?php
/**
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licensing details.
*/
namespace ACP3\Core\I18n;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
class TranslatorConfigurator
{
/**
* @var \ACP3\Core\Settings\SettingsInterface
*/
private $settings;
public function __construct(SettingsInterface $settings)
{
$this->settings = $settings;
}
public function configure(Translator $translator): void
{
$settings = $this->settings->getSettings(Schema::MODULE_NAME);
$translator->setLocale($settings['lang']);
}
}
......@@ -71,7 +71,7 @@ class AddTemplatesVariablesListener
]);
}
private function setLanguage()
private function setLanguage(): void
{
$cookieLocale = $this->request->getCookies()->get('ACP3_INSTALLER_LANG', '');
if ($this->translator->languagePackExists($cookieLocale)) {
......
......@@ -28,6 +28,16 @@ class SettingsRepository implements SettingsAwareRepositoryInterface
public function getAllSettings()
{
return [
[
'module_name' => 'system',
'name' => 'page_cache_is_enabled',
'value' => 0,
],
[
'module_name' => 'system',
'name' => 'page_cache_purge_mode',
'value' => 1,
],
[
'module_name' => 'system',
'name' => 'design',
......
......@@ -43,12 +43,14 @@ class InvalidatePageCacheOnModelAfterSaveListener
public function __invoke()
{
if ($this->canUsePageCache->canUsePageCache()) {
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
} else {
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
}
if (!$this->canUsePageCache->canUsePageCache()) {
return;
}
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
} else {
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
}
}
}
......@@ -9,11 +9,11 @@ namespace ACP3\Modules\ACP3\System\Event\Listener;
use ACP3\Core\Cache\Purge;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Model\Repository\SettingsAwareRepositoryInterface;
use ACP3\Core\Modules;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Helper\CanUsePageCache;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Modules\ACP3\System\Model\Repository\SettingsRepository;
class InvalidatePageCacheOnSettingsSaveBeforeListener
{
......@@ -26,7 +26,7 @@ class InvalidatePageCacheOnSettingsSaveBeforeListener
*/
private $settings;
/**
* @var SettingsRepository
* @var \ACP3\Core\Model\Repository\SettingsAwareRepositoryInterface
*/
private $settingsRepository;
/**
......@@ -38,14 +38,11 @@ class InvalidatePageCacheOnSettingsSaveBeforeListener
*/
private $canUsePageCache;
/**
* InvalidatePageCacheOnSettingsSaveBeforeListener constructor.
*/
public function __construct(
ApplicationPath $applicationPath,
SettingsInterface $settings,
Modules $modules,
SettingsRepository $settingsRepository,
SettingsAwareRepositoryInterface $settingsRepository,
CanUsePageCache $canUsePageCache
) {
$this->applicationPath = $applicationPath;
......@@ -57,16 +54,18 @@ class InvalidatePageCacheOnSettingsSaveBeforeListener
public function __invoke()
{
if ($this->canUsePageCache->canUsePageCache()) {
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
} else {
$systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
$this->settingsRepository->update(
['value' => false],
['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']
);
}
if (!$this->canUsePageCache->canUsePageCache()) {
return;
}
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
} else {
$systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
$this->settingsRepository->update(
['value' => false],
['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']
);
}
}
}
......@@ -114,7 +114,7 @@ class Schema implements Modules\Installer\SchemaInterface
'entries' => '20',
'flood' => '20',
'homepage' => 'news/index/index/',
'lang' => '',
'lang' => 'en_US',
'mailer_smtp_auth' => false,
'mailer_smtp_host' => '',
'mailer_smtp_password' => '',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment