From 53822bb4bc21cadc135d70d3d099c5fd117424b0 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 13 May 2017 21:31:25 +0200 Subject: add new apis --- Makefile | 1 - admin/admin.php | 23 ------- appinfo/app.php | 2 +- appinfo/info.xml | 27 +++----- lib/Config/AppConfig.php | 139 -------------------------------------- lib/Controller/PageController.php | 51 -------------- lib/Cron/Updater.php | 42 ++++++++---- lib/Settings/Admin.php | 38 +++++++++++ lib/Settings/Section.php | 33 +++++++++ 9 files changed, 108 insertions(+), 248 deletions(-) delete mode 100644 admin/admin.php delete mode 100644 lib/Config/AppConfig.php create mode 100644 lib/Settings/Admin.php create mode 100644 lib/Settings/Section.php diff --git a/Makefile b/Makefile index 4b8793a5e..0947b0240 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,6 @@ appstore: rm -rf $(appstore_build_directory) $(appstore_artifact_directory) mkdir -p $(appstore_build_directory) $(appstore_artifact_directory) cp --parents -r \ - "admin" \ "appinfo" \ "css" \ "img" \ diff --git a/admin/admin.php b/admin/admin.php deleted file mode 100644 index 938123850..000000000 --- a/admin/admin.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Admin; - -use OCA\News\AppInfo\Application; -use OCA\News\Controller\AdminController; - -$app = new Application(); -$container = $app->getContainer(); -$response = $container->query(AdminController::class)->index(); - -return $response->render(); diff --git a/appinfo/app.php b/appinfo/app.php index 88aeed65c..65c53725c 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -15,4 +15,4 @@ namespace OCA\News\AppInfo; require_once __DIR__ . '/../vendor/autoload.php'; -(new Application)->registerConfig(); +\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\News\Hooks\User', 'deleteUser'); \ No newline at end of file diff --git a/appinfo/info.xml b/appinfo/info.xml index a464f499b..8bf4536e6 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -8,7 +8,7 @@ Before you update to a new version, [check the changelog](https://github.com/nextcloud/news/blob/master/CHANGELOG.md) to avoid surprises. **Important**: To enable feed updates you will need to enable either [Nextcloud system cron](https://docs.nextcloud.com/server/10/admin_manual/configuration_server/background_jobs_configuration.html#cron) or use [an updater](https://github.com/nextcloud/news-updater) which uses the built in update API and disable cron updates. More information can be found [in the README](https://github.com/nextcloud/news).]]> - 11.0.0 + 11.0.1 agpl Bernhard Posselt Alessandro Cosentino @@ -38,10 +38,14 @@ Before you update to a new version, [check the changelog](https://github.com/nex - - - - + + OCA\News\Cron\Updater + + + + OCA\News\Settings\Admin + OCA\News\Settings\Section + @@ -49,17 +53,4 @@ Before you update to a new version, [check the changelog](https://github.com/nex news.page.index - - - - OCA\News\Cron\Updater - - - - - - OC_User::pre_deleteUser - OCA\News\Hooks\User::deleteUser - - diff --git a/lib/Config/AppConfig.php b/lib/Config/AppConfig.php deleted file mode 100644 index 9c30b4f80..000000000 --- a/lib/Config/AppConfig.php +++ /dev/null @@ -1,139 +0,0 @@ - - * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\Config; - -use OCP\BackgroundJob\IJobList; -use SimpleXMLElement; - -use OCP\INavigationManager; -use OCP\IURLGenerator; -use OCP\Util; -use OCP\App; - -// Used to parse app.json file, should be in core at some point -class AppConfig { - - private $config; - private $navigationManager; - private $urlGenerator; - private $jobList; - - /** - * TODO: External deps that are needed: - * - add jobs - * - connect to hooks - */ - public function __construct(INavigationManager $navigationManager, - IURLGenerator $urlGenerator, - IJobList $jobList) { - $this->navigationManager = $navigationManager; - $this->urlGenerator = $urlGenerator; - $this->config = []; - $this->jobList = $jobList; - } - - - /** - * Parse an xml config - */ - private function parseConfig($string) { - // no need to worry about XXE since local file - $xml = simplexml_load_string($string, 'SimpleXMLElement'); - return json_decode(json_encode((array)$xml), true); - } - - - /** - * @param string|array $data path to the config file or an array with the - * config - */ - public function loadConfig($data) { - if(is_array($data)) { - $this->config = $data; - } else { - $this->config = $this->parseConfig($data); - } - } - - - /** - * @param string $key if given returns the value of the config at index $key - * @return array|mixed the config - */ - public function getConfig($key=null) { - // FIXME: is this function interface a good idea? - if($key !== null) { - return $this->config[$key]; - } else { - return $this->config; - } - } - - - /** - * Registers all config options - */ - public function registerAll() { - $this->registerNavigation(); - $this->registerHooks(); - $this->jobList->add('OC\BackgroundJob\Legacy\RegularJob', [$this->config['cron']['job'], 'run']); - App::registerAdmin($this->config['id'], $this->config['admin']); - } - - - /** - * Parses the navigation and creates a navigation entry if needed - */ - public function registerNavigation() { - if (array_key_exists('navigation', $this->config)) { - $this->navigationManager->add(function () { - $nav =& $this->config['navigation']; - - $navConfig = [ - 'id' => $this->config['id'], - 'order' => $nav['order'], - 'name' => $nav['name'] - ]; - - $navConfig['href'] = $this->urlGenerator->linkToRoute( - $nav['route'] - ); - $navConfig['icon'] = $this->urlGenerator->imagePath( - $this->config['id'], $nav['icon'] - ); - - return $navConfig; - }); - } - } - - - /** - * Registers all hooks in the config - */ - public function registerHooks() { - // FIXME: this is temporarily static because core emitters are not - // future proof, therefore legacy code in here - foreach ($this->config['hooks'] as $hook) { - $listener = explode('::', $hook['channel']); - $reaction = explode('::', $hook['subscriber']); - - // config is written like HookNamespace::method => Class::method - Util::connectHook($listener[0], $listener[1], $reaction[0], - $reaction[1]); - } - } - - -} diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index b01b9971d..3d1db0d57 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -24,7 +24,6 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCA\News\Service\StatusService; -use OCA\News\Config\AppConfig; use OCA\News\Config\Config; use OCA\News\Explore\RecommendedSites; use OCA\News\Explore\RecommendedSiteNotFoundException; @@ -35,7 +34,6 @@ class PageController extends Controller { private $settings; private $l10n; private $userId; - private $appConfig; private $urlGenerator; private $config; private $recommendedSites; @@ -47,7 +45,6 @@ class PageController extends Controller { IRequest $request, IConfig $settings, IURLGenerator $urlGenerator, - AppConfig $appConfig, Config $config, IL10N $l10n, RecommendedSites $recommendedSites, @@ -56,7 +53,6 @@ class PageController extends Controller { parent::__construct($AppName, $request); $this->settings = $settings; $this->urlGenerator = $urlGenerator; - $this->appConfig = $appConfig; $this->l10n = $l10n; $this->userId = $UserId; $this->config = $config; @@ -155,53 +151,6 @@ class PageController extends Controller { } } - - /** - * @NoCSRFRequired - * @PublicPage - * - * Generates a web app manifest, according to specs in: - * https://developer.mozilla.org/en-US/Apps/Build/Manifest - */ - public function manifest() { - $config = $this->appConfig->getConfig(); - - // size of the icons: 128x128 is required by FxOS for all app manifests - $iconSizes = ['128', '512']; - $icons = []; - - $locale = str_replace('_', '-', $this->l10n->getLanguageCode()); - - foreach ($iconSizes as $size) { - $filename = 'app-' . $size . '.png'; - if (file_exists(__DIR__ . '/../../img/' . $filename)) { - $icons[$size] = $this->urlGenerator->imagePath($config['id'], - $filename); - } - } - - - $data = [ - "name" => $config['name'], - "type" => 'web', - "default_locale" => $locale, - "description" => $config['description'], - "launch_path" => $this->urlGenerator->linkToRoute( - $config['navigation']['route']), - "icons" => $icons, - "developer" => [ - "name" => $config['author'], - "url" => $config['homepage'] - ] - ]; - - $response = new JSONResponse($data); - $response->addHeader('Content-Type', - 'application/x-web-app-manifest+json'); - - return $response; - } - /** * @NoAdminRequired * diff --git a/lib/Cron/Updater.php b/lib/Cron/Updater.php index 5caa2223e..6d8fea832 100644 --- a/lib/Cron/Updater.php +++ b/lib/Cron/Updater.php @@ -5,34 +5,46 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Alessandro Cosentino * @author Bernhard Posselt - * @copyright Alessandro Cosentino 2012 * @copyright Bernhard Posselt 2012, 2014 */ namespace OCA\News\Cron; -use OCA\News\AppInfo\Application; +use OC\BackgroundJob\Job; + use OCA\News\Config\Config; use OCA\News\Service\StatusService; use OCA\News\Utility\Updater as UpdaterService; -class Updater { +class Updater extends Job { - public static function run() { - $app = new Application(); + /** + * @var Config + */ + private $config; + /** + * @var StatusService + */ + private $status; + /** + * @var UpdaterService + */ + private $updaterService; - $container = $app->getContainer(); + public function __construct(Config $config, StatusService $status, + UpdaterService $updaterService) { + $this->config = $config; + $this->status = $status; + $this->updaterService = $updaterService; + } - // make it possible to turn off cron updates if you use an external - // script to execute updates in parallel - $useCronUpdates = $container->query(Config::class)->getUseCronUpdates(); - $isProperlyConfigured = $container->query(StatusService::class)->isProperlyConfigured(); - if ($useCronUpdates && $isProperlyConfigured) { - $container->query(UpdaterService::class)->update(); - $container->query(UpdaterService::class)->beforeUpdate(); - $container->query(UpdaterService::class)->afterUpdate(); + protected function run($argument) { + if ($this->config->getUseCronUpdates() && + $this->status->isProperlyConfigured()) { + $this->updaterService->update(); + $this->updaterService->beforeUpdate(); + $this->updaterService->afterUpdate(); } } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php new file mode 100644 index 000000000..a256999f0 --- /dev/null +++ b/lib/Settings/Admin.php @@ -0,0 +1,38 @@ +config = $config; + } + + public function getForm() { + $data = [ + 'autoPurgeMinimumInterval' => + $this->config->getAutoPurgeMinimumInterval(), + 'autoPurgeCount' => $this->config->getAutoPurgeCount(), + 'maxRedirects' => $this->config->getMaxRedirects(), + 'feedFetcherTimeout' => $this->config->getFeedFetcherTimeout(), + 'useCronUpdates' => $this->config->getUseCronUpdates(), + 'maxSize' => $this->config->getMaxSize(), + 'exploreUrl' => $this->config->getExploreUrl(), + ]; + return new TemplateResponse('news', 'admin', $data, ''); + } + + public function getSection() { + return 'news'; + } + + public function getPriority() { + return 40; + } +} diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php new file mode 100644 index 000000000..5e1e47476 --- /dev/null +++ b/lib/Settings/Section.php @@ -0,0 +1,33 @@ +url = $url; + $this->l = $l; + } + + public function getID() { + return 'news'; + } + + public function getName() { + return $this->l->t('News'); + } + + public function getPriority() { + return 10; + } + + public function getIcon() { + return $this->url->imagePath('news', 'app.svg'); + } +} \ No newline at end of file -- cgit v1.2.3