From fbad651ebd31d09406ef141e61ea396ad1eda710 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 21 Oct 2014 15:14:19 +0200 Subject: Make config.ini editable in the admin interface --- controller/admincontroller.php | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 controller/admincontroller.php (limited to 'controller') diff --git a/controller/admincontroller.php b/controller/admincontroller.php new file mode 100644 index 000000000..2b876c394 --- /dev/null +++ b/controller/admincontroller.php @@ -0,0 +1,76 @@ + + * @author Bernhard Posselt + * @copyright Alessandro Cosentino 2012 + * @copyright Bernhard Posselt 2012, 2014 + */ + +namespace OCA\News\Controller; + +use \OCP\AppFramework\Http\TemplateResponse; +use \OCP\IRequest; +use \OCP\AppFramework\Controller; + +use \OCA\News\Config\Config; + +class AdminController extends Controller { + + private $config; + private $configPath; + + public function __construct($appName, IRequest $request, Config $config, + $configPath){ + parent::__construct($appName, $request); + $this->config = $config; + $this->configPath = $configPath; + } + + // There are no checks for the index method since the output is rendered + // in admin/admin.php + public function index() { + $data = [ + 'autoPurgeMinimumInterval' => $this->config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->config->getAutoPurgeCount(), + 'cacheDuration' => $this->config->getSimplePieCacheDuration(), + 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->config->getUseCronUpdates(), + ]; + return new TemplateResponse($this->appName, 'admin', $data, 'blank'); + } + + + /** + * @param int $autoPurgeMinimumInterval + * @param int $autoPurgeCount + * @param int $cacheDuration + * @param int $feedFetcherTimeout + * @param bool $useCronUpdates + * @return array with the updated values + */ + public function update($autoPurgeMinimumInterval, $autoPurgeCount, + $cacheDuration, $feedFetcherTimeout, + $useCronUpdates) { + $this->config->setAutoPurgeMinimumInterval($autoPurgeMinimumInterval); + $this->config->setAutoPurgeCount($autoPurgeCount); + $this->config->setSimplePieCacheDuration($cacheDuration); + $this->config->setFeedFetcherTimeout($feedFetcherTimeout); + $this->config->setUseCronUpdates($useCronUpdates); + $this->config->write($this->configPath); + + return [ + 'autoPurgeMinimumInterval' => $this->config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->config->getAutoPurgeCount(), + 'cacheDuration' => $this->config->getSimplePieCacheDuration(), + 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->config->getUseCronUpdates(), + ]; + } + + +} \ No newline at end of file -- cgit v1.2.3