Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate app bootstrapping #2364

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions appinfo/app.php

This file was deleted.

37 changes: 21 additions & 16 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
use OCA\Contacts\Listener\LoadContactsFilesActions;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\SabrePluginEvent;

class Application extends App {
class Application extends App implements IBootstrap {
public const APP_ID = 'contacts';

public const AVAIL_SETTINGS = [
'allowSocialSync' => 'yes',
];
Expand All @@ -40,23 +43,25 @@ public function __construct() {
parent::__construct(self::APP_ID);
}

public function register() {
$server = $this->getContainer()->getServer();
public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
}

public function boot(IBootContext $context): void {
$appContainer = $context->getAppContainer();
$serverContainer = $context->getServerContainer();

/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $server->query(IEventDispatcher::class);
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) {
$server = $event->getServer();

if ($server !== null) {
// We have to register the PatchPlugin here and not info.xml,
// because info.xml plugins are loaded, after the
// beforeMethod:* hook has already been emitted.
$server->addPlugin($this->getContainer()->query(PatchPlugin::class));
$eventDispatcher = $serverContainer->get(IEventDispatcher::class);
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', static function (SabrePluginEvent $event) use ($appContainer) {
if ($event->getServer() === null) {
return;
}
});

// Register files action
$eventDispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadContactsFilesActions::class);
// We have to register the PatchPlugin here and not info.xml,
// because info.xml plugins are loaded, after the
// beforeMethod:* hook has already been emitted.
$event->getServer()->addPlugin($appContainer->get(PatchPlugin::class));
});
}
}
8 changes: 4 additions & 4 deletions lib/Dav/PatchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public function getHTTPMethods($uri) {
*
* @param PropPatch $propPatch
* @param INode $node
* @return void
* @return bool
*/
public function httpPatch(RequestInterface $request, ResponseInterface $response) {
public function httpPatch(RequestInterface $request, ResponseInterface $response): bool {
$path = $request->getPath();
$node = $this->server->tree->getNodeForPath($path);

Expand Down Expand Up @@ -127,7 +127,7 @@ public function httpPatch(RequestInterface $request, ResponseInterface $response
if (count($properties) > 1) {
throw new DAV\Exception\BadRequest('The specified property appear more than once');
}

// Init if not in the vcard
if (count($properties) === 0) {
$vCard->add($propertyName, $propertyData);
Expand All @@ -144,7 +144,7 @@ public function httpPatch(RequestInterface $request, ResponseInterface $response
$oldData = $properties[0]->getValue();
$properties[0]->setRawMimeDirValue($oldData.$propertyData);
}

// Validate & write
$vCard->validate();
$node->put($vCard->serialize());
Expand Down