Commit 6aa740e1 authored by Tino Goratsch's avatar Tino Goratsch

refs #39

- added the new core.settings.save_before event to the ACP3\Core\Settings\Settings::saveSettings() method
parent 74d96dd7
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Settings\Event;
use Symfony\Component\EventDispatcher\Event;
class SettingsSaveEvent extends Event
{
/**
* @var string
*/
private $module;
/**
* @var array
*/
private $data;
public function __construct($module, array $data)
{
$this->data = $data;
$this->module = $module;
}
/**
* @return string
*/
public function getModule()
{
return $this->module;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
}
......@@ -9,7 +9,9 @@ namespace ACP3\Core\Settings;
use ACP3\Core\Cache;
use ACP3\Core\Model\Repository\ModuleAwareRepositoryInterface;
use ACP3\Core\Model\Repository\SettingsAwareRepositoryInterface;
use ACP3\Core\Settings\Event\SettingsSaveEvent;
use ACP3\Modules\ACP3\System;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Manages the various module settings
......@@ -19,6 +21,10 @@ class Settings implements SettingsInterface
{
const CACHE_ID = 'settings';
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var ModuleAwareRepositoryInterface
*/
......@@ -38,11 +44,13 @@ class Settings implements SettingsInterface
/**
* Settings constructor.
* @param EventDispatcherInterface $eventDispatcher
* @param Cache $coreCache
* @param ModuleAwareRepositoryInterface $systemModuleRepository
* @param SettingsAwareRepositoryInterface $systemSettingsRepository
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
Cache $coreCache,
ModuleAwareRepositoryInterface $systemModuleRepository,
SettingsAwareRepositoryInterface $systemSettingsRepository
......@@ -50,6 +58,7 @@ class Settings implements SettingsInterface
$this->coreCache = $coreCache;
$this->systemModuleRepository = $systemModuleRepository;
$this->systemSettingsRepository = $systemSettingsRepository;
$this->eventDispatcher = $eventDispatcher;
}
/**
......@@ -65,6 +74,8 @@ class Settings implements SettingsInterface
$bool = $bool2 = false;
$moduleId = $this->systemModuleRepository->getModuleId($module);
if (!empty($moduleId)) {
$this->eventDispatcher->dispatch('core.settings.save_before', new SettingsSaveEvent($module, $data));
foreach ($data as $key => $value) {
$updateValues = [
'value' => $value
......
......@@ -44,6 +44,7 @@ services:
core.config:
class: ACP3\Core\Settings\Settings
arguments:
- '@core.event_dispatcher'
- '@core.cache.system'
- '@system.model.modulerepository'
- '@system.model.settingsrepository'
......
......@@ -75,8 +75,6 @@ class Settings extends Core\Controller\AbstractAdminAction
'filesize' => (int)$formData['filesize'],
];
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Categories\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -86,8 +86,6 @@ class Settings extends Core\Controller\AbstractAdminAction
'emoticons' => $formData['emoticons'],
];
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Comments\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -79,8 +79,6 @@ class Index extends Core\Controller\AbstractAdminAction
'vat_id' => $this->get('core.helpers.secure')->strEncode($formData['vat_id'], true),
];
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Contact\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -111,8 +111,6 @@ class Settings extends Core\Controller\AbstractAdminAction
$data['comments'] = $formData['comments'];
}
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Files\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -110,8 +110,6 @@ class Settings extends Core\Controller\AbstractAdminAction
$this->get('gallery.cache.core')->getDriver()->deleteAll();
}
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $bool;
});
}
......
......@@ -104,8 +104,6 @@ class Settings extends Core\Controller\AbstractAdminAction
'newsletter_integration' => $formData['newsletter_integration'],
];
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Guestbook\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -98,8 +98,6 @@ class Settings extends Core\Controller\AbstractAdminAction
$data['comments'] = $formData['comments'];
}
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, News\Installer\Schema::MODULE_NAME);
});
}
......
......@@ -72,8 +72,6 @@ class Send extends Core\Controller\AbstractAdminAction
$bool2 = $this->newsletterRepository->update(['status' => '1'], $id);
}
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->redirectMessages()->setMessage(
$bool === true && $bool2 !== false,
$this->translator->t(
......
......@@ -63,8 +63,6 @@ class Order extends Core\Controller\AbstractAdminAction
$this->permissionsCache->getCacheDriver()->deleteAll();
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->redirect()->temporary('acp/permissions');
}
......
......@@ -94,8 +94,6 @@ class Settings extends Core\Controller\AbstractAdminAction
$bool = $this->config->saveSettings($data, Seo\Installer\Schema::MODULE_NAME);
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $bool;
});
}
......
......@@ -141,8 +141,6 @@ class Configuration extends Core\Controller\AbstractAdminAction
$bool = $this->config->saveSettings($data, System\Installer\Schema::MODULE_NAME);
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->redirectMessages()->setMessage(
$bool,
$this->translator->t('system', $bool === true ? 'config_edit_success' : 'config_edit_error'),
......
......@@ -7,27 +7,40 @@
namespace ACP3\Modules\ACP3\System\Event\Listener;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Core\Modules;
use ACP3\Modules\ACP3\System\Installer\Schema;
use ACP3\Modules\ACP3\System\Model\Repository\SettingsRepository;
class OnModelAfterSaveListener
{
/**
* @var SettingsInterface
* @var SettingsRepository
*/
private $settings;
private $settingsRepository;
/**
* @var Modules
*/
private $modules;
/**
* OnModelAfterSaveListener constructor.
* @param SettingsInterface $settings
* @param Modules $modules
* @param SettingsRepository $settingsRepository
*/
public function __construct(SettingsInterface $settings)
public function __construct(
Modules $modules,
SettingsRepository $settingsRepository)
{
$this->settings = $settings;
$this->settingsRepository = $settingsRepository;
$this->modules = $modules;
}
public function invalidatePageCache()
{
$this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
$systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
$this->settingsRepository->update(
['value' => false],
['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']
);
}
}
......@@ -2,10 +2,12 @@ services:
system.event.listener.on_model_after_save_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\OnModelAfterSaveListener
arguments:
- '@core.config'
- '@core.modules'
- '@system.model.settingsrepository'
tags:
- { name: core.eventListener, event: core.model.after_save, method: invalidatePageCache }
- { name: core.eventListener, event: core.model.after_delete, method: invalidatePageCache }
- { name: core.eventListener, event: core.settings.save_before, method: invalidatePageCache }
system.event.listener.on_layout_content_before_listener:
class: ACP3\Modules\ACP3\System\Event\Listener\OnLayoutContentBeforeListener
......
......@@ -95,8 +95,6 @@ class Settings extends Core\Controller\AbstractAdminAction
'mail' => $formData['mail']
];
Core\Cache\Purge::doPurge($this->appPath->getCacheDir() . 'http');
return $this->config->saveSettings($data, Users\Installer\Schema::MODULE_NAME);
});
}
......
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