diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2020-09-24 11:32:55 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2020-09-24 11:32:55 -0100 |
commit | 6d9afed84221d5485330f62eff6be1bebee404f3 (patch) | |
tree | e045542cb98a62a9f17efa095694e1ed5ce733a0 | |
parent | 888d9931413f5ddbb540ca8d9ca4833cf74ddbde (diff) |
compat nc20
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | appinfo/app.php | 42 | ||||
-rw-r--r-- | appinfo/autoload.php | 37 | ||||
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | composer/composer.json (renamed from composer.json) | 9 | ||||
-rw-r--r-- | composer/composer.lock (renamed from composer.lock) | 58 | ||||
-rw-r--r-- | lib/AppInfo/Application.php | 80 | ||||
-rw-r--r-- | lib/Listeners/WellKnownListener.php | 83 | ||||
-rw-r--r-- | lib/Service/WellKnownService.php (renamed from lib/Service/WebfingerService.php) | 17 |
10 files changed, 185 insertions, 158 deletions
@@ -3,3 +3,6 @@ js/ node_modules/ vendor/ img/twemoji/ +composer/* +!composer/composer.json +!composer/composer.lock @@ -64,9 +64,9 @@ clean: clean-dev: rm -rf node_modules -# composer packages -composer: - composer install --prefer-dist +build-composer: + composer install --prefer-dist --working-dir composer + composer update --prefer-dist --working-dir composer # releasing to github release: appstore github-release github-upload @@ -88,7 +88,7 @@ github-upload: --file $(build_dir)/$(app_name)-$(version).tar.gz # creating .tar.gz + signature -appstore: dev-setup lint build-js-production composer +appstore: dev-setup lint build-js-production build-composer mkdir -p $(sign_dir) rsync -a \ --exclude=/build \ @@ -101,8 +101,8 @@ appstore: dev-setup lint build-js-production composer --exclude=/.babelrc.js \ --exclude=/.drone.yml \ --exclude=/.eslintrc.js \ - --exclude=/composer.json \ - --exclude=/composer.lock \ + --exclude=/composer/composer.json \ + --exclude=/composer/composer.lock \ --exclude=/src \ --exclude=/node_modules \ --exclude=/webpack.*.js \ diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index 69e8e257..00000000 --- a/appinfo/app.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -declare(strict_types=1); - - -/** - * Nextcloud - Social Support - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Social\AppInfo; - - -require_once __DIR__ . '/autoload.php'; - - -/** @var Application $app */ -$app = \OC::$server->query(Application::class); - -$app->checkUpgradeStatus(); -$app->registerWebfinger(); - - diff --git a/appinfo/autoload.php b/appinfo/autoload.php deleted file mode 100644 index 3427325f..00000000 --- a/appinfo/autoload.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -declare(strict_types=1); - - -/** - * Nextcloud - Social Support - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Maxence Lange <maxence@artificial-owl.com> - * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Social\AppInfo; - -$composerDir = __DIR__ . '/../vendor/'; - -if (is_dir($composerDir) && file_exists($composerDir . 'autoload.php')) { - require_once $composerDir . 'autoload.php'; -} - diff --git a/appinfo/info.xml b/appinfo/info.xml index 70e44372..84a72e5b 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -35,7 +35,7 @@ <database>pgsql</database> <database>sqlite</database> <database>mysql</database> - <nextcloud min-version="17" max-version="19"/> + <nextcloud min-version="20" max-version="21"/> </dependencies> <background-jobs> diff --git a/composer.json b/composer/composer.json index f009f3b3..2e394046 100644 --- a/composer.json +++ b/composer/composer.json @@ -12,6 +12,15 @@ "config": { "platform": { "php": "7.0.0" + }, + "vendor-dir": ".", + "optimize-autoloader": true, + "classmap-authoritative": true, + "autoloader-suffix": "Social" + }, + "autoload": { + "psr-4": { + "OCA\\Social\\": "../lib/" } }, "require": { diff --git a/composer.lock b/composer/composer.lock index 758e0955..c03b7b1b 100644 --- a/composer.lock +++ b/composer/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "f93a783c86bad53b0b8486db3fc61380", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "d8778803612af20699c7efb0637bfe62478e596c" + "reference": "4e602526c3afbba7255ae4764037562075ef030f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/d8778803612af20699c7efb0637bfe62478e596c", - "reference": "d8778803612af20699c7efb0637bfe62478e596c", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/4e602526c3afbba7255ae4764037562075ef030f", + "reference": "4e602526c3afbba7255ae4764037562075ef030f", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2020-03-18T23:09:45+00:00" + "time": "2020-08-06T13:26:28+00:00" }, { "name": "friendica/json-ld", @@ -243,6 +243,7 @@ ], "description": "This tool check syntax of PHP files about 20x faster than serial check.", "homepage": "https://github.com/JakubOnderka/PHP-Parallel-Lint", + "abandoned": "php-parallel-lint/php-parallel-lint", "time": "2018-02-24T15:31:20+00:00" }, { @@ -853,6 +854,7 @@ "keywords": [ "tokenizer" ], + "abandoned": true, "time": "2017-11-27T05:48:46+00:00" }, { @@ -1560,16 +1562,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.17.0", + "version": "v1.18.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9" + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e94c8b1bbe2bc77507a1056cdb06451c75b427f9", - "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", "shasum": "" }, "require": { @@ -1581,7 +1583,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -1614,7 +1620,21 @@ "polyfill", "portable" ], - "time": "2020-05-12T16:14:59+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "theseer/tokenizer", @@ -1658,23 +1678,24 @@ }, { "name": "webmozart/assert", - "version": "1.8.0", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", - "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0", + "php": "^5.3.3 || ^7.0 || ^8.0", "symfony/polyfill-ctype": "^1.8" }, "conflict": { + "phpstan/phpstan": "<0.12.20", "vimeo/psalm": "<3.9.1" }, "require-dev": { @@ -1702,7 +1723,7 @@ "check", "validate" ], - "time": "2020-04-18T12:12:48+00:00" + "time": "2020-07-08T17:02:28+00:00" } ], "aliases": [], @@ -1716,5 +1737,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.0.0" - } + }, + "plugin-api-version": "1.1.0" } diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 9aeb978a..568d02fa 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -31,17 +31,20 @@ declare(strict_types=1); namespace OCA\Social\AppInfo; +use Closure; use OC\DB\SchemaWrapper; -use OC\Webfinger\Event\WebfingerEvent; -use OC\Webfinger\Model\WebfingerObject; +use OC\WellKnown\Event\WellKnownEvent; +use OCA\Social\Listeners\WellKnownListener; use OCA\Social\Notification\Notifier; use OCA\Social\Service\ConfigService; use OCA\Social\Service\UpdateService; -use OCA\Social\Service\WebfingerService; use OCP\AppFramework\App; -use OCP\AppFramework\IAppContainer; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\QueryException; -use OCP\EventDispatcher\IEventDispatcher; +use OCP\IServerContainer; +use Throwable; /** @@ -49,22 +52,12 @@ use OCP\EventDispatcher\IEventDispatcher; * * @package OCA\Social\AppInfo */ -class Application extends App { +class Application extends App implements IBootstrap { const APP_NAME = 'social'; - /** @var ConfigService */ - private $configService; - - /** @var UpdateService */ - private $updateService; - - /** @var IAppContainer */ - private $container; - - /** * Application constructor. * @@ -72,61 +65,58 @@ class Application extends App { */ public function __construct(array $params = []) { parent::__construct(self::APP_NAME, $params); + } - $this->container = $this->getContainer(); - $manager = $this->container->getServer() - ->getNotificationManager(); - $manager->registerNotifierService(Notifier::class); + /** + * @param IRegistrationContext $context + */ + public function register(IRegistrationContext $context): void { + $context->registerEventListener(WellKnownEvent::class, WellKnownListener::class); } /** - * + * @param IBootContext $context */ - public function registerWebfinger() { - /** @var IEventDispatcher $eventDispatcher */ - $eventDispatcher = \OC::$server->query(IEventDispatcher::class); - $eventDispatcher->addListener( - '\OC\Webfinger::onRequest', - function(WebfingerEvent $e) { - /** @var WebfingerService $webfingerService */ - $webfingerService = $this->container->query(WebfingerService::class); - try { - $webfingerService->webfinger($e); - } catch (\Exception $e) { - } - } - ); + public function boot(IBootContext $context): void { + $manager = $context->getServerContainer() + ->getNotificationManager(); + $manager->registerNotifierService(Notifier::class); + + try { + $context->injectFn(Closure::fromCallable([$this, 'checkUpgradeStatus'])); + } catch (Throwable $e) { + } } /** + * Register Navigation Tab * + * @param IServerContainer $container */ - public function checkUpgradeStatus() { - $upgradeChecked = $this->container->getServer() - ->getConfig() - ->getAppValue(Application::APP_NAME, 'update_checked', ''); + protected function checkUpgradeStatus(IServerContainer $container) { + $upgradeChecked = $container->getConfig() + ->getAppValue(Application::APP_NAME, 'update_checked', ''); if ($upgradeChecked === '0.3') { return; } try { - $this->configService = $this->container->query(ConfigService::class); - $this->updateService = $this->container->query(UpdateService::class); + $configService = $container->query(ConfigService::class); + $updateService = $container->query(UpdateService::class); } catch (QueryException $e) { return; } - $server = $this->container->getServer(); - $schema = new SchemaWrapper($server->getDatabaseConnection()); + $schema = new SchemaWrapper($container->getDatabaseConnection()); if ($schema->hasTable('social_a2_stream')) { - $this->updateService->checkUpdateStatus(); + $updateService->checkUpdateStatus(); } - $this->configService->setAppValue('update_checked', '0.3'); + $configService->setAppValue('update_checked', '0.3'); } } diff --git a/lib/Listeners/WellKnownListener.php b/lib/Listeners/WellKnownListener.php new file mode 100644 index 00000000..8eb18c64 --- /dev/null +++ b/lib/Listeners/WellKnownListener.php @@ -0,0 +1,83 @@ +<?php +declare(strict_types=1); + + +/** + * Nextcloud - Social Support + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2020, Maxence Lange <maxence@artificial-owl.com> + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\Social\Listeners; + + +use OC\WellKnown\Event\WellKnownEvent; +use OCA\Social\Exceptions\CacheActorDoesNotExistException; +use OCA\Social\Exceptions\SocialAppConfigException; +use OCA\Social\Exceptions\UnauthorizedFediverseException; +use OCA\Social\Service\WellKnownService; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\WellKnown\IWellKnownManager; + + +/** + * Class WellKnownListener + * + * @package OCA\Social\Listeners + */ +class WellKnownListener implements IEventListener { + + + private $wellKnownService; + + + /** + * WellKnownListener constructor. + * + * @param WellKnownService $wellKnownService + */ + public function __construct(WellKnownService $wellKnownService) { + $this->wellKnownService = $wellKnownService; + } + + + /** + * @param Event $event + */ + public function handle(Event $event): void { + if (!$event instanceof WellKnownEvent) { + return; + } + + $wellKnown = $event->getWellKnown(); + if ($wellKnown->getService() === IWellKnownManager::WEBFINGER) { + try { + $this->wellKnownService->webfinger($wellKnown); + } catch (CacheActorDoesNotExistException | SocialAppConfigException | UnauthorizedFediverseException $e) { + } + } + } + +} + diff --git a/lib/Service/WebfingerService.php b/lib/Service/WellKnownService.php index c0169886..2ce5342f 100644 --- a/lib/Service/WebfingerService.php +++ b/lib/Service/WellKnownService.php @@ -37,8 +37,9 @@ use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UnauthorizedFediverseException; use OCA\Social\Model\WebfingerLink; use OCP\IURLGenerator; +use OCP\WellKnown\Model\IWellKnown; -class WebfingerService { +class WellKnownService { /** @var IURLGenerator */ @@ -86,17 +87,16 @@ class WebfingerService { /** - * @param WebfingerEvent $event + * @param IWellKnown $wellKnown * * @throws CacheActorDoesNotExistException - * @throws UnauthorizedFediverseException * @throws SocialAppConfigException + * @throws UnauthorizedFediverseException */ - public function webfinger(WebfingerEvent $event) { + public function webfinger(IWellKnown $wellKnown) { $this->fediverseService->jailed(); - $subject = $event->getWebfinger() - ->getSubject(); + $subject = $wellKnown->getSubject(); if (strpos($subject, 'acct:') === 0) { $subject = substr($subject, 5); @@ -124,9 +124,8 @@ class WebfingerService { $subscribe = $this->urlGenerator->linkToRouteAbsolute('social.OStatus.subscribe') . '?uri={uri}'; $linkOstatus->setTemplate($subscribe); - $event->getWebfinger() - ->addLinkSerialized($linkPerson) - ->addLinkSerialized($linkOstatus); + $wellKnown->addLinkSerialized($linkPerson) + ->addLinkSerialized($linkOstatus); } } |