Commit 88545164 authored by Tino Goratsch's avatar Tino Goratsch

closes #52

- added a new system config option to select, whether the page cache is getting purged automatically or manually
parent 7bb712ee
......@@ -60,6 +60,11 @@ class Configuration extends Core\Controller\AbstractAdminAction
$systemSettings = $this->config->getSettings(System\Installer\Schema::MODULE_NAME);
$pageCachePurgeMode = [
1 => $this->translator->t('system', 'page_cache_purge_mode_automatically'),
2 => $this->translator->t('system', 'page_cache_purge_mode_manually'),
];
$mailerTypes = [
'mail' => $this->translator->t('system', 'mailer_type_php_mail'),
'smtp' => $this->translator->t('system', 'mailer_type_smtp')
......@@ -85,6 +90,11 @@ class Configuration extends Core\Controller\AbstractAdminAction
'page_cache_is_enabled',
$systemSettings['page_cache_is_enabled']
),
'page_cache_purge_mode' => $this->formsHelper->checkboxGenerator(
'page_cache_purge_mode',
$pageCachePurgeMode,
$systemSettings['page_cache_purge_mode']
),
'cache_images' => $this->formsHelper->yesNoCheckboxGenerator(
'cache_images',
$systemSettings['cache_images']
......@@ -140,6 +150,7 @@ class Configuration extends Core\Controller\AbstractAdminAction
'maintenance_message' => $formData['maintenance_message'],
'maintenance_mode' => (int)$formData['maintenance_mode'],
'page_cache_is_enabled' => (int)$formData['page_cache_is_enabled'],
'page_cache_purge_mode' => (int)$formData['page_cache_purge_mode'],
'site_title' => $this->get('core.helpers.secure')->strEncode($formData['site_title']),
'wysiwyg' => $formData['wysiwyg']
];
......
......@@ -7,12 +7,18 @@
namespace ACP3\Modules\ACP3\System\Event\Listener;
use ACP3\Core\Cache\Purge;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Helper\CanUsePageCache;
use ACP3\Modules\ACP3\System\Installer\Schema;
class OnModelAfterSaveListener
class InvalidatePageCacheOnModelAfterSaveListener
{
/**
* @var ApplicationPath
*/
private $applicationPath;
/**
* @var SettingsInterface
*/
......@@ -23,14 +29,17 @@ class OnModelAfterSaveListener
private $canUsePageCache;
/**
* OnModelAfterSaveListener constructor.
* InvalidatePageCacheOnModelAfterSaveListener constructor.
* @param ApplicationPath $applicationPath
* @param SettingsInterface $settings
* @param CanUsePageCache $canUsePageCache
*/
public function __construct(
ApplicationPath $applicationPath,
SettingsInterface $settings,
CanUsePageCache $canUsePageCache)
{
CanUsePageCache $canUsePageCache
) {
$this->applicationPath = $applicationPath;
$this->settings = $settings;
$this->canUsePageCache = $canUsePageCache;
}
......@@ -38,7 +47,11 @@ class OnModelAfterSaveListener
public function invalidatePageCache()
{
if ($this->canUsePageCache->canUsePageCache()) {
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
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);
}
}
}
}
......@@ -6,13 +6,24 @@
namespace ACP3\Modules\ACP3\System\Event\Listener;
use ACP3\Core\Cache\Purge;
use ACP3\Core\Environment\ApplicationPath;
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 OnSettingsSaveBeforeListener
class InvalidatePageCacheOnSettingsSaveBeforeListener
{
/**
* @var ApplicationPath
*/
private $applicationPath;
/**
* @var SettingsInterface
*/
private $settings;
/**
* @var SettingsRepository
*/
......@@ -27,29 +38,39 @@ class OnSettingsSaveBeforeListener
private $canUsePageCache;
/**
* OnModelAfterSaveListener constructor.
* InvalidatePageCacheOnSettingsSaveBeforeListener constructor.
* @param ApplicationPath $applicationPath
* @param SettingsInterface $settings
* @param Modules $modules
* @param SettingsRepository $settingsRepository
* @param CanUsePageCache $canUsePageCache
*/
public function __construct(
ApplicationPath $applicationPath,
SettingsInterface $settings,
Modules $modules,
SettingsRepository $settingsRepository,
CanUsePageCache $canUsePageCache
) {
$this->settingsRepository = $settingsRepository;
$this->applicationPath = $applicationPath;
$this->settings = $settings;
$this->modules = $modules;
$this->settingsRepository = $settingsRepository;
$this->canUsePageCache = $canUsePageCache;
}
public function invalidatePageCache()
{
if ($this->canUsePageCache->canUsePageCache()) {
$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_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']
);
}
}
}
}
......@@ -147,6 +147,9 @@ class Migration extends Modules\Installer\AbstractMigration
64 => [
"INSERT INTO `{pre}settings` (`id`, `module_id`, `name`, `value`) VALUES ('', '{moduleId}', 'site_title', '');",
$this->migrateToVersion64()
],
65 => [
"INSERT INTO `{pre}settings` (`id`, `module_id`, `name`, `value`) VALUES ('', '{moduleId}', 'page_cache_purge_mode', 1);",
]
];
}
......
......@@ -48,7 +48,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 64;
return 65;
}
/**
......@@ -120,6 +120,7 @@ class Schema implements Modules\Installer\SchemaInterface
'mod_rewrite' => false,
'page_cache_is_enabled' => false,
'page_cache_is_valid' => true,
'page_cache_purge_mode' => 1,
'security_secret' => uniqid(mt_rand(), true),
'site_title' => '',
'wysiwyg' => 'core.wysiwyg.textarea'
......
......@@ -57,6 +57,7 @@
</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=$page_cache_purge_mode required=true label={lang t="system|page_cache_purge_mode"}}
{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>
......
services:
system.event.listener.on_model_after_save_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\OnModelAfterSaveListener
system.event.listener.invalidate_page_cache_on_model_after_save_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\InvalidatePageCacheOnModelAfterSaveListener
arguments:
- '@core.environment.application_path'
- '@core.config'
- '@system.helpers.can_use_page_cache'
tags:
- { name: core.eventListener, event: core.model.after_save, method: invalidatePageCache }
- { name: core.eventListener, event: core.model.after_delete, method: invalidatePageCache }
system.event.listener.on_settings_save_before_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\OnSettingsSaveBeforeListener
system.event.listener.invalidate_page_cache_on_settings_save_before_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\InvalidatePageCacheOnSettingsSaveBeforeListener
arguments:
- '@core.environment.application_path'
- '@core.config'
- '@core.modules'
- '@system.model.settingsrepository'
- '@system.helpers.can_use_page_cache'
......
......@@ -237,6 +237,9 @@
<item key="output_as_file">Als Datei</item>
<item key="overview">Übersicht</item>
<item key="page_cache_is_invalid"><![CDATA[Der Seiten-Cache ist nicht aktuell. Bitte klicken Sie <a href="%route%">hier</a> und aktualisieren den Seiten-Cache.]]></item>
<item key="page_cache_purge_mode">Seiten-Cache-Reinigungsmodus</item>
<item key="page_cache_purge_mode_automatically">Automatisch</item>
<item key="page_cache_purge_mode_manually">Manuell</item>
<item key="page_x">Seite %page%</item>
<item key="pagination">Seitenauswahl</item>
<item key="performance">Leistung</item>
......@@ -262,6 +265,7 @@
<item key="select_menu_item">Bitte wählen Sie einen der oben stehenden Menüpunkte aus, um zur gewünschten Aktion zu gelangen.</item>
<item key="select_mod_rewrite">Bitte geben Sie an, ob die suchmaschinenfreundlichen URIs verwendet werden sollen, oder nicht.</item>
<item key="select_online_maintenance">Bitte wählen Sie aus, ob sich die Seite im Wartungsmodus befinden soll oder nicht.</item>
<item key="select_page_cache_purge_mode">Bitte wählen Sie aus, ob der Seiten-Cache automatisch neu generiert werden soll oder ob dies manuell geschehen soll.</item>
<item key="select_records_per_page">Bitte wählen Sie aus, wie viele Datensätze pro Seite angezeigt werden sollen.</item>
<item key="select_sidebar_entries">Bitte wählen Sie aus, wie viele Einträge in der Modul-Sidebar angezeigt werden sollen.</item>
<item key="select_time_zone">Bitte wählen Sie die Zeitzone aus.</item>
......
......@@ -237,6 +237,9 @@
<item key="output_as_file">As file</item>
<item key="overview">Overview</item>
<item key="page_cache_is_invalid"><![CDATA[The page cache is invalid. Please click <a href="%route%">here</a> and refresh the page cache.]]></item>
<item key="page_cache_purge_mode">Page cache purge mode</item>
<item key="page_cache_purge_mode_automatically">Automatically</item>
<item key="page_cache_purge_mode_manually">Manually</item>
<item key="page_x">Page %page%</item>
<item key="pagination">Pagination</item>
<item key="performance">Performance</item>
......@@ -262,6 +265,7 @@
<item key="select_menu_item">Please choose from one of the menu items above to get to the desired action.</item>
<item key="select_mod_rewrite">Please select whether search engine friendly URIs should be used or not.</item>
<item key="select_online_maintenance">Please select whether the maintenance mode should be turned on or off.</item>
<item key="select_page_cache_purge_mode">Please select whether the page cache should be purged automatically or manually.</item>
<item key="select_records_per_page">Please select how many records per page to display.</item>
<item key="select_sidebar_entries">Please select how many entries should be to displayed in the Module-Sidebar.</item>
<item key="select_time_zone">Please select the time zone.</item>
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\System\Test\Event\Listener;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Event\Listener\InvalidatePageCacheOnModelAfterSaveListener;
use ACP3\Modules\ACP3\System\Helper\CanUsePageCache;
class InvalidatePageCacheOnModelAfterSaveListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var InvalidatePageCacheOnModelAfterSaveListener
*/
private $invalidatePageCache;
/**
* @var ApplicationPath
*/
private $applicationPath;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $settingsMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $canUsePageCacheMock;
protected function setUp()
{
$this->setUpMockObjects();
$this->invalidatePageCache = new InvalidatePageCacheOnModelAfterSaveListener(
$this->applicationPath,
$this->settingsMock,
$this->canUsePageCacheMock
);
}
private function setUpMockObjects()
{
$this->applicationPath = new ApplicationPath(ApplicationMode::DEVELOPMENT);
$this->settingsMock = $this->getMockBuilder(SettingsInterface::class)
->setMethods(['getSettings', 'saveSettings'])
->getMock();
$this->canUsePageCacheMock = $this->getMockBuilder(CanUsePageCache::class)
->disableOriginalConstructor()
->getMock();
}
public function testDisabledPageCache()
{
$this->setUpCanUsePageCacheMockExpectations(false);
$this->setUpSettingsMockExpectations();
$this->invalidatePageCache->invalidatePageCache();
}
private function setUpCanUsePageCacheMockExpectations($cacheEnabled = true)
{
$this->canUsePageCacheMock->expects($this->once())
->method('canUsePageCache')
->willReturn($cacheEnabled);
}
private function setUpSettingsMockExpectations($methodCalls = 0, $purgeMode = 1)
{
$this->settingsMock->expects($this->exactly($methodCalls))
->method('getSettings')
->with('system')
->willReturn(['page_cache_purge_mode' => $purgeMode]);
}
public function testManualPageCachePurge()
{
$this->setUpCanUsePageCacheMockExpectations(true);
$this->setUpSettingsMockExpectations(1, 2);
$this->invalidatePageCache->invalidatePageCache();
}
public function testAutomaticPageCachePurge()
{
$this->setUpCanUsePageCacheMockExpectations(true);
$this->setUpSettingsMockExpectations(1, 2);
$this->settingsMock->expects($this->once())
->method('saveSettings')
->with(['page_cache_is_valid' => false], 'system');
$this->invalidatePageCache->invalidatePageCache();
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\System\Test\Event\Listener;
use ACP3\Core\Environment\ApplicationMode;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Modules;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Event\Listener\InvalidatePageCacheOnSettingsSaveBeforeListener;
use ACP3\Modules\ACP3\System\Helper\CanUsePageCache;
use ACP3\Modules\ACP3\System\Model\Repository\SettingsRepository;
class InvalidatePageCacheOnSettingsSaveBeforeListenerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var InvalidatePageCacheOnSettingsSaveBeforeListener
*/
private $invalidatePageCache;
/**
* @var ApplicationPath
*/
private $applicationPath;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $settingsMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $canUsePageCacheMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $modulesMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $settingsRepositoryMock;
protected function setUp()
{
$this->setUpMockObjects();
$this->invalidatePageCache = new InvalidatePageCacheOnSettingsSaveBeforeListener(
$this->applicationPath,
$this->settingsMock,
$this->modulesMock,
$this->settingsRepositoryMock,
$this->canUsePageCacheMock
);
}
private function setUpMockObjects()
{
$this->applicationPath = new ApplicationPath(ApplicationMode::DEVELOPMENT);
$this->settingsMock = $this->getMockBuilder(SettingsInterface::class)
->setMethods(['getSettings', 'saveSettings'])
->getMock();
$this->modulesMock = $this->getMockBuilder(Modules::class)
->disableOriginalConstructor()
->getMock();
$this->settingsRepositoryMock = $this->getMockBuilder(SettingsRepository::class)
->disableOriginalConstructor()
->getMock();
$this->canUsePageCacheMock = $this->getMockBuilder(CanUsePageCache::class)
->disableOriginalConstructor()
->getMock();
}
public function testDisabledPageCache()
{
$this->setUpCanUsePageCacheMockExpectations(false);
$this->setUpSettingsMockExpectations();
$this->invalidatePageCache->invalidatePageCache();
}
private function setUpCanUsePageCacheMockExpectations($cacheEnabled = true)
{
$this->canUsePageCacheMock->expects($this->once())
->method('canUsePageCache')
->willReturn($cacheEnabled);
}
private function setUpSettingsMockExpectations($methodCalls = 0, $purgeMode = 1)
{
$this->settingsMock->expects($this->exactly($methodCalls))
->method('getSettings')
->with('system')
->willReturn(['page_cache_purge_mode' => $purgeMode]);
}
public function testManualPageCachePurge()
{
$this->setUpCanUsePageCacheMockExpectations(true);
$this->setUpSettingsMockExpectations(1, 2);
$this->invalidatePageCache->invalidatePageCache();
}
public function testAutomaticPageCachePurge()
{
$this->setUpCanUsePageCacheMockExpectations(true);
$this->setUpSettingsMockExpectations(1, 2);
$this->modulesMock->expects($this->once())
->method('getModuleId')
->with('system')
->willReturn(1);
$this->settingsRepositoryMock->expects($this->once())
->method('update')
->with(['value' => false], ['module_id' => 1, 'name' => 'page_cache_is_valid']);
$this->invalidatePageCache->invalidatePageCache();
}
}
......@@ -158,6 +158,16 @@ class AdminSettingsFormValidation extends Core\Validation\AbstractFormValidation
'haystack' => [0, 1]
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
'data' => $formData,
'field' => 'page_cache_purge_mode',
'message' => $this->translator->t('system', 'select_page_cache_purge_mode'),
'extra' => [
'haystack' => [1, 2]
]
])
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
......
......@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - 2016-xx-xx
### Added
- [#49](https://github.com/ACP3/cms/issues/49) Added the ability to use a custom menu item title when creating a menu item via the articles module
- [#52](https://github.com/ACP3/cms/issues/52) Added a new system config option to select, whether the page cache is getting purged automatically or manually
- [#8](https://github.com/ACP3/cms/issues/8) Added the foundation to get module specific results per page
### Changed
......
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