Commit 0942d00d authored by Tino Goratsch's avatar Tino Goratsch

added a new system config option which lets the user select whether to enable the page cache or not

parent 01863172
......@@ -7,7 +7,8 @@
namespace ACP3\Core\Cache;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Modules\ACP3\Users\Model\UserModel;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
use Symfony\Component\HttpFoundation\Response;
/**
......@@ -16,11 +17,6 @@ use Symfony\Component\HttpFoundation\Response;
*/
trait CacheResponseTrait
{
/**
* @return UserModel
*/
abstract protected function getUser();
/**
* @return Response
*/
......@@ -31,6 +27,11 @@ trait CacheResponseTrait
*/
abstract protected function getApplicationMode();
/**
* @return SettingsInterface
*/
abstract protected function getSettings();
/**
* @param int $lifetime
*/
......@@ -38,15 +39,27 @@ trait CacheResponseTrait
{
$response = $this->getResponse();
if ($this->getApplicationMode() === ApplicationMode::DEVELOPMENT) {
if ($this->disallowPageCache()) {
$response->setPrivate();
$lifetime = null;
} else {
$response->setPublic();
}
$response
->setVary('X-User-Context-Hash')
->setPublic()
->setMaxAge($lifetime)
->setSharedMaxAge($lifetime);
}
/**
* @return bool
*/
protected function disallowPageCache()
{
$systemSettings = $this->getSettings()->getSettings(Schema::MODULE_NAME);
return $this->getApplicationMode() === ApplicationMode::DEVELOPMENT
|| $systemSettings['page_cache_is_enabled'] == 0;
}
}
......@@ -139,19 +139,19 @@ abstract class AbstractWidgetAction implements ActionInterface
}
/**
* @return \ACP3\Modules\ACP3\Users\Model\UserModel
* @return \ACP3\Core\View
*/
protected function getUser()
protected function getView()
{
return $this->user;
return $this->view;
}
/**
* @return \ACP3\Core\View
* @return Core\Settings\SettingsInterface
*/
protected function getView()
protected function getSettings()
{
return $this->view;
return $this->config;
}
/**
......
......@@ -81,6 +81,10 @@ class Configuration extends Core\Controller\AbstractAdminAction
'maintenance_mode',
$systemSettings['maintenance_mode']
),
'page_cache' => $this->formsHelper->yesNoCheckboxGenerator(
'page_cache_is_enabled',
$systemSettings['page_cache_is_enabled']
),
'cache_images' => $this->formsHelper->yesNoCheckboxGenerator(
'cache_images',
$systemSettings['cache_images']
......@@ -136,6 +140,7 @@ class Configuration extends Core\Controller\AbstractAdminAction
'mailer_type' => $formData['mailer_type'],
'maintenance_message' => $formData['maintenance_message'],
'maintenance_mode' => (int)$formData['maintenance_mode'],
'page_cache_is_enabled' => (int)$formData['page_cache_is_enabled'],
'wysiwyg' => $formData['wysiwyg']
];
......
......@@ -21,14 +21,15 @@ class OnModelAfterSaveListener
* OnModelAfterSaveListener constructor.
* @param SettingsInterface $settings
*/
public function __construct(
SettingsInterface $settings)
public function __construct(SettingsInterface $settings)
{
$this->settings = $settings;
}
public function invalidatePageCache()
{
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_is_enabled'] == 1) {
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
}
}
}
......@@ -7,6 +7,7 @@
namespace ACP3\Modules\ACP3\System\Event\Listener;
use ACP3\Core\Modules;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Modules\ACP3\System\Model\Repository\SettingsRepository;
......@@ -20,26 +21,35 @@ class OnSettingsSaveBeforeListener
* @var Modules
*/
private $modules;
/**
* @var SettingsInterface
*/
private $settings;
/**
* OnModelAfterSaveListener constructor.
* @param SettingsInterface $settings
* @param Modules $modules
* @param SettingsRepository $settingsRepository
*/
public function __construct(
SettingsInterface $settings,
Modules $modules,
SettingsRepository $settingsRepository)
{
SettingsRepository $settingsRepository
) {
$this->settingsRepository = $settingsRepository;
$this->modules = $modules;
$this->settings = $settings;
}
public function invalidatePageCache()
{
$systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
$this->settingsRepository->update(
['value' => false],
['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']
);
if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_is_enabled'] == 1) {
$systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
$this->settingsRepository->update(
['value' => false],
['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']
);
}
}
}
......@@ -139,6 +139,9 @@ class Migration extends Modules\Installer\AbstractMigration
],
62 => [
"INSERT INTO `{pre}settings` (`id`, `module_id`, `name`, `value`) VALUES ('', '{moduleId}', 'page_cache_is_valid', 1);",
],
63 => [
"INSERT INTO `{pre}settings` (`id`, `module_id`, `name`, `value`) VALUES ('', '{moduleId}', 'page_cache_is_enabled', 1);",
]
];
}
......
......@@ -48,7 +48,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 62;
return 63;
}
/**
......@@ -118,6 +118,7 @@ class Schema implements Modules\Installer\SchemaInterface
'maintenance_mode' => false,
'maintenance_message' => '',
'mod_rewrite' => false,
'page_cache_is_enabled' => false,
'page_cache_is_valid' => true,
'security_secret' => uniqid(mt_rand(), true),
'wysiwyg' => 'core.wysiwyg.textarea'
......
......@@ -55,6 +55,7 @@
{include file="asset:System/Partials/form_group.textarea.tpl" name="maintenance_message" value=$form.maintenance_message required=true label={lang t="system|maintenance_msg"}}
</div>
<div id="tab-5" class="tab-pane fade">
{include file="asset:System/Partials/form_group.button_group.tpl" options=$page_cache required=true label={lang t="system|enable_page_cache"}}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$cache_images required=true label={lang t="system|cache_images"}}
{include file="asset:System/Partials/form_group.input_number.tpl" name="cache_lifetime" value=$form.cache_lifetime required=true label={lang t="system|cache_lifetime"}}
</div>
......
......@@ -10,6 +10,7 @@ services:
system.event.listener.on_settings_save_before_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\OnSettingsSaveBeforeListener
arguments:
- '@core.config'
- '@core.modules'
- '@system.model.settingsrepository'
tags:
......
......@@ -109,10 +109,11 @@
<item key="email">E-Mail</item>
<item key="email_address">E-Mail-Adresse</item>
<item key="enable">Aktivieren</item>
<item key="enable_module">Modul aktivieren</item>
<item key="enable_following_modules_first">Um das Modul installieren zu können, müssen Sie zunächst folgende
Module aktivieren: %modules%
</item>
<item key="enable_module">Modul aktivieren</item>
<item key="enable_page_cache">Seiten-Cache aktivieren</item>
<item key="end_date">Enddatum</item>
<item key="entries">Einträge</item>
<item key="entry">Eintrag</item>
......@@ -254,6 +255,7 @@
<item key="select_date">Bitte vervollständigen Sie die Angaben zum Veröffentlichungsdatum bzw. dem Enddatum dieses Eintrages.</item>
<item key="select_date_format">Bitte wählen Sie aus, ob das lange oder das kurze Datumsformat verwendet werden soll.</item>
<item key="select_editor">Bitte wählen Sie aus, mit welchem Editor Sie Ihre Einträge erstellen wollen.</item>
<item key="select_enable_page_cache">Bitte wählen Sie aus, ob Seiten-Cache verwendet werden soll oder nicht.</item>
<item key="select_language">Bitte wählen Sie aus, in welcher Sprache Sie die Website angezeigt bekommen möchten.</item>
<item key="select_mailer_type">Bitte wählen Sie den zu verwendenten Mailertyp aus.</item>
<item key="select_menu_item">Bitte wählen Sie einen der oben stehenden Menüpunkte aus, um zur gewünschten Aktion zu gelangen.</item>
......
......@@ -109,10 +109,11 @@
<item key="email">E-mail</item>
<item key="email_address">E-mail address</item>
<item key="enable">Enable</item>
<item key="enable_module">Enable module</item>
<item key="enable_following_modules_first">To install the module you have to enable the following modules first:
%modules%
</item>
<item key="enable_module">Enable module</item>
<item key="enable_page_cache">Enable page cache</item>
<item key="end_date">End date</item>
<item key="entries">Entries</item>
<item key="entry">Entry</item>
......@@ -254,6 +255,7 @@
<item key="select_date">Please complete the details of the release date and end date.</item>
<item key="select_date_format">Please select whether the long or the short date format to be used.</item>
<item key="select_editor">Please select whether you want to use a WYSIWYG editor or a simple textarea.</item>
<item key="select_enable_page_cache">Please select whether you want to enabled the page cache or not.</item>
<item key="select_language">Please select the language in which you want to see the website.</item>
<item key="select_mailer_type">Please select the mailer type.</item>
<item key="select_menu_item">Please choose from one of the menu items above to get to the desired action.</item>
......
......@@ -141,6 +141,16 @@ class AdminSettingsFormValidation extends Core\Validation\AbstractFormValidation
protected function validatePerformanceSettings(array $formData)
{
$this->validator
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
'data' => $formData,
'field' => 'page_cache_is_enabled',
'message' => $this->translator->t('system', 'select_enable_page_cache'),
'extra' => [
'haystack' => [0, 1]
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
......
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