Completed
Pull Request — master (#4212)
by Individual IT
13:52
created
apps/dav/lib/Connector/Sabre/QuotaPlugin.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -40,114 +40,114 @@
 block discarded – undo
40 40
  */
41 41
 class QuotaPlugin extends \Sabre\DAV\ServerPlugin {
42 42
 
43
-	/**
44
-	 * @var \OC\Files\View
45
-	 */
46
-	private $view;
43
+    /**
44
+     * @var \OC\Files\View
45
+     */
46
+    private $view;
47 47
 
48
-	/**
49
-	 * Reference to main server object
50
-	 *
51
-	 * @var \Sabre\DAV\Server
52
-	 */
53
-	private $server;
48
+    /**
49
+     * Reference to main server object
50
+     *
51
+     * @var \Sabre\DAV\Server
52
+     */
53
+    private $server;
54 54
 
55
-	/**
56
-	 * @param \OC\Files\View $view
57
-	 */
58
-	public function __construct($view) {
59
-		$this->view = $view;
60
-	}
55
+    /**
56
+     * @param \OC\Files\View $view
57
+     */
58
+    public function __construct($view) {
59
+        $this->view = $view;
60
+    }
61 61
 
62
-	/**
63
-	 * This initializes the plugin.
64
-	 *
65
-	 * This function is called by \Sabre\DAV\Server, after
66
-	 * addPlugin is called.
67
-	 *
68
-	 * This method should set up the requires event subscriptions.
69
-	 *
70
-	 * @param \Sabre\DAV\Server $server
71
-	 * @return void
72
-	 */
73
-	public function initialize(\Sabre\DAV\Server $server) {
62
+    /**
63
+     * This initializes the plugin.
64
+     *
65
+     * This function is called by \Sabre\DAV\Server, after
66
+     * addPlugin is called.
67
+     *
68
+     * This method should set up the requires event subscriptions.
69
+     *
70
+     * @param \Sabre\DAV\Server $server
71
+     * @return void
72
+     */
73
+    public function initialize(\Sabre\DAV\Server $server) {
74 74
 
75
-		$this->server = $server;
75
+        $this->server = $server;
76 76
 
77
-		$server->on('beforeWriteContent', array($this, 'checkQuota'), 10);
78
-		$server->on('beforeCreateFile', array($this, 'checkQuota'), 10);
79
-	}
77
+        $server->on('beforeWriteContent', array($this, 'checkQuota'), 10);
78
+        $server->on('beforeCreateFile', array($this, 'checkQuota'), 10);
79
+    }
80 80
 
81
-	/**
82
-	 * This method is called before any HTTP method and validates there is enough free space to store the file
83
-	 *
84
-	 * @param string $uri
85
-	 * @throws InsufficientStorage
86
-	 * @return bool
87
-	 */
88
-	public function checkQuota($uri) {
89
-		$length = $this->getLength();
90
-		if ($length) {
91
-			if (substr($uri, 0, 1) !== '/') {
92
-				$uri = '/' . $uri;
93
-			}
94
-			list($parentUri, $newName) = URLUtil::splitPath($uri);
95
-			if(is_null($parentUri)) {
96
-				$parentUri = '';
97
-			}
98
-			$req = $this->server->httpRequest;
99
-			if ($req->getHeader('OC-Chunked')) {
100
-				$info = \OC_FileChunking::decodeName($newName);
101
-				$chunkHandler = $this->getFileChunking($info);
102
-				// subtract the already uploaded size to see whether
103
-				// there is still enough space for the remaining chunks
104
-				$length -= $chunkHandler->getCurrentSize();
105
-				// use target file name for free space check in case of shared files
106
-				$uri = rtrim($parentUri, '/') . '/' . $info['name'];
107
-			}
108
-			$freeSpace = $this->getFreeSpace($uri);
109
-			if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) {
110
-				if (isset($chunkHandler)) {
111
-					$chunkHandler->cleanup();
112
-				}
113
-				throw new InsufficientStorage();
114
-			}
115
-		}
116
-		return true;
117
-	}
81
+    /**
82
+     * This method is called before any HTTP method and validates there is enough free space to store the file
83
+     *
84
+     * @param string $uri
85
+     * @throws InsufficientStorage
86
+     * @return bool
87
+     */
88
+    public function checkQuota($uri) {
89
+        $length = $this->getLength();
90
+        if ($length) {
91
+            if (substr($uri, 0, 1) !== '/') {
92
+                $uri = '/' . $uri;
93
+            }
94
+            list($parentUri, $newName) = URLUtil::splitPath($uri);
95
+            if(is_null($parentUri)) {
96
+                $parentUri = '';
97
+            }
98
+            $req = $this->server->httpRequest;
99
+            if ($req->getHeader('OC-Chunked')) {
100
+                $info = \OC_FileChunking::decodeName($newName);
101
+                $chunkHandler = $this->getFileChunking($info);
102
+                // subtract the already uploaded size to see whether
103
+                // there is still enough space for the remaining chunks
104
+                $length -= $chunkHandler->getCurrentSize();
105
+                // use target file name for free space check in case of shared files
106
+                $uri = rtrim($parentUri, '/') . '/' . $info['name'];
107
+            }
108
+            $freeSpace = $this->getFreeSpace($uri);
109
+            if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) {
110
+                if (isset($chunkHandler)) {
111
+                    $chunkHandler->cleanup();
112
+                }
113
+                throw new InsufficientStorage();
114
+            }
115
+        }
116
+        return true;
117
+    }
118 118
 
119
-	public function getFileChunking($info) {
120
-		// FIXME: need a factory for better mocking support
121
-		return new \OC_FileChunking($info);
122
-	}
119
+    public function getFileChunking($info) {
120
+        // FIXME: need a factory for better mocking support
121
+        return new \OC_FileChunking($info);
122
+    }
123 123
 
124
-	public function getLength() {
125
-		$req = $this->server->httpRequest;
126
-		$length = $req->getHeader('X-Expected-Entity-Length');
127
-		if (!is_numeric($length)) {
128
-			$length = $req->getHeader('Content-Length');
129
-			$length = is_numeric($length) ? $length : null;
130
-		}
124
+    public function getLength() {
125
+        $req = $this->server->httpRequest;
126
+        $length = $req->getHeader('X-Expected-Entity-Length');
127
+        if (!is_numeric($length)) {
128
+            $length = $req->getHeader('Content-Length');
129
+            $length = is_numeric($length) ? $length : null;
130
+        }
131 131
 
132
-		$ocLength = $req->getHeader('OC-Total-Length');
133
-		if (is_numeric($length) && is_numeric($ocLength)) {
134
-			return max($length, $ocLength);
135
-		}
132
+        $ocLength = $req->getHeader('OC-Total-Length');
133
+        if (is_numeric($length) && is_numeric($ocLength)) {
134
+            return max($length, $ocLength);
135
+        }
136 136
 
137
-		return $length;
138
-	}
137
+        return $length;
138
+    }
139 139
 
140
-	/**
141
-	 * @param string $uri
142
-	 * @return mixed
143
-	 * @throws ServiceUnavailable
144
-	 */
145
-	public function getFreeSpace($uri) {
146
-		try {
147
-			$freeSpace = $this->view->free_space(ltrim($uri, '/'));
148
-			return $freeSpace;
149
-		} catch (StorageNotAvailableException $e) {
150
-			throw new ServiceUnavailable($e->getMessage());
151
-		}
152
-	}
140
+    /**
141
+     * @param string $uri
142
+     * @return mixed
143
+     * @throws ServiceUnavailable
144
+     */
145
+    public function getFreeSpace($uri) {
146
+        try {
147
+            $freeSpace = $this->view->free_space(ltrim($uri, '/'));
148
+            return $freeSpace;
149
+        } catch (StorageNotAvailableException $e) {
150
+            throw new ServiceUnavailable($e->getMessage());
151
+        }
152
+    }
153 153
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,88 +32,88 @@
 block discarded – undo
32 32
 use Sabre\HTTP\Response;
33 33
 
34 34
 class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
35
-	protected $nonFatalExceptions = [
36
-		'Sabre\DAV\Exception\NotAuthenticated' => true,
37
-		// If tokenauth can throw this exception (which is basically as
38
-		// NotAuthenticated. So not fatal.
39
-		'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true,
40
-		// the sync client uses this to find out whether files exist,
41
-		// so it is not always an error, log it as debug
42
-		'Sabre\DAV\Exception\NotFound' => true,
43
-		// this one mostly happens when the same file is uploaded at
44
-		// exactly the same time from two clients, only one client
45
-		// wins, the second one gets "Precondition failed"
46
-		'Sabre\DAV\Exception\PreconditionFailed' => true,
47
-		// forbidden can be expected when trying to upload to
48
-		// read-only folders for example
49
-		'Sabre\DAV\Exception\Forbidden' => true,
50
-		// Happens when an external storage or federated share is temporarily
51
-		// not available
52
-		'Sabre\DAV\Exception\StorageNotAvailableException' => true,
53
-	];
35
+    protected $nonFatalExceptions = [
36
+        'Sabre\DAV\Exception\NotAuthenticated' => true,
37
+        // If tokenauth can throw this exception (which is basically as
38
+        // NotAuthenticated. So not fatal.
39
+        'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true,
40
+        // the sync client uses this to find out whether files exist,
41
+        // so it is not always an error, log it as debug
42
+        'Sabre\DAV\Exception\NotFound' => true,
43
+        // this one mostly happens when the same file is uploaded at
44
+        // exactly the same time from two clients, only one client
45
+        // wins, the second one gets "Precondition failed"
46
+        'Sabre\DAV\Exception\PreconditionFailed' => true,
47
+        // forbidden can be expected when trying to upload to
48
+        // read-only folders for example
49
+        'Sabre\DAV\Exception\Forbidden' => true,
50
+        // Happens when an external storage or federated share is temporarily
51
+        // not available
52
+        'Sabre\DAV\Exception\StorageNotAvailableException' => true,
53
+    ];
54 54
 
55
-	/** @var string */
56
-	private $appName;
55
+    /** @var string */
56
+    private $appName;
57 57
 
58
-	/** @var ILogger */
59
-	private $logger;
58
+    /** @var ILogger */
59
+    private $logger;
60 60
 
61
-	/**
62
-	 * @param string $loggerAppName app name to use when logging
63
-	 * @param ILogger $logger
64
-	 */
65
-	public function __construct($loggerAppName, $logger) {
66
-		$this->appName = $loggerAppName;
67
-		$this->logger = $logger;
68
-	}
61
+    /**
62
+     * @param string $loggerAppName app name to use when logging
63
+     * @param ILogger $logger
64
+     */
65
+    public function __construct($loggerAppName, $logger) {
66
+        $this->appName = $loggerAppName;
67
+        $this->logger = $logger;
68
+    }
69 69
 
70
-	/**
71
-	 * This initializes the plugin.
72
-	 *
73
-	 * This function is called by \Sabre\DAV\Server, after
74
-	 * addPlugin is called.
75
-	 *
76
-	 * This method should set up the required event subscriptions.
77
-	 *
78
-	 * @param \Sabre\DAV\Server $server
79
-	 * @return void
80
-	 */
81
-	public function initialize(\Sabre\DAV\Server $server) {
70
+    /**
71
+     * This initializes the plugin.
72
+     *
73
+     * This function is called by \Sabre\DAV\Server, after
74
+     * addPlugin is called.
75
+     *
76
+     * This method should set up the required event subscriptions.
77
+     *
78
+     * @param \Sabre\DAV\Server $server
79
+     * @return void
80
+     */
81
+    public function initialize(\Sabre\DAV\Server $server) {
82 82
 
83
-		$server->on('exception', array($this, 'logException'), 10);
84
-	}
83
+        $server->on('exception', array($this, 'logException'), 10);
84
+    }
85 85
 
86
-	/**
87
-	 * Log exception
88
-	 *
89
-	 */
90
-	public function logException(\Exception $ex) {
91
-		$exceptionClass = get_class($ex);
92
-		$level = \OCP\Util::FATAL;
93
-		if (isset($this->nonFatalExceptions[$exceptionClass])) {
94
-			$level = \OCP\Util::DEBUG;
95
-		}
86
+    /**
87
+     * Log exception
88
+     *
89
+     */
90
+    public function logException(\Exception $ex) {
91
+        $exceptionClass = get_class($ex);
92
+        $level = \OCP\Util::FATAL;
93
+        if (isset($this->nonFatalExceptions[$exceptionClass])) {
94
+            $level = \OCP\Util::DEBUG;
95
+        }
96 96
 
97
-		$message = $ex->getMessage();
98
-		if ($ex instanceof Exception) {
99
-			if (empty($message)) {
100
-				$response = new Response($ex->getHTTPCode());
101
-				$message = $response->getStatusText();
102
-			}
103
-			$message = "HTTP/1.1 {$ex->getHTTPCode()} $message";
104
-		}
97
+        $message = $ex->getMessage();
98
+        if ($ex instanceof Exception) {
99
+            if (empty($message)) {
100
+                $response = new Response($ex->getHTTPCode());
101
+                $message = $response->getStatusText();
102
+            }
103
+            $message = "HTTP/1.1 {$ex->getHTTPCode()} $message";
104
+        }
105 105
 
106
-		$user = \OC_User::getUser();
106
+        $user = \OC_User::getUser();
107 107
 
108
-		$exception = [
109
-			'Message' => $message,
110
-			'Exception' => $exceptionClass,
111
-			'Code' => $ex->getCode(),
112
-			'Trace' => $ex->getTraceAsString(),
113
-			'File' => $ex->getFile(),
114
-			'Line' => $ex->getLine(),
115
-			'User' => $user,
116
-		];
117
-		$this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
118
-	}
108
+        $exception = [
109
+            'Message' => $message,
110
+            'Exception' => $exceptionClass,
111
+            'Code' => $ex->getCode(),
112
+            'Trace' => $ex->getTraceAsString(),
113
+            'File' => $ex->getFile(),
114
+            'Line' => $ex->getLine(),
115
+            'User' => $user,
116
+        ];
117
+        $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
118
+    }
119 119
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/DavAclPlugin.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -43,50 +43,50 @@
 block discarded – undo
43 43
  * @package OCA\DAV\Connector\Sabre
44 44
  */
45 45
 class DavAclPlugin extends \Sabre\DAVACL\Plugin {
46
-	public function __construct() {
47
-		$this->hideNodesFromListings = true;
48
-		$this->allowUnauthenticatedAccess = false;
49
-	}
46
+    public function __construct() {
47
+        $this->hideNodesFromListings = true;
48
+        $this->allowUnauthenticatedAccess = false;
49
+    }
50 50
 
51
-	function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
52
-		$access = parent::checkPrivileges($uri, $privileges, $recursion, false);
53
-		if($access === false && $throwExceptions) {
54
-			/** @var INode $node */
55
-			$node = $this->server->tree->getNodeForPath($uri);
51
+    function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) {
52
+        $access = parent::checkPrivileges($uri, $privileges, $recursion, false);
53
+        if($access === false && $throwExceptions) {
54
+            /** @var INode $node */
55
+            $node = $this->server->tree->getNodeForPath($uri);
56 56
 
57
-			switch(get_class($node)) {
58
-				case 'OCA\DAV\CardDAV\AddressBook':
59
-					$type = 'Addressbook';
60
-					break;
61
-				default:
62
-					$type = 'Node';
63
-					break;
64
-			}
65
-			throw new NotFound(
66
-				sprintf(
67
-					"%s with name '%s' could not be found",
68
-					$type,
69
-					$node->getName()
70
-				)
71
-			);
72
-		}
57
+            switch(get_class($node)) {
58
+                case 'OCA\DAV\CardDAV\AddressBook':
59
+                    $type = 'Addressbook';
60
+                    break;
61
+                default:
62
+                    $type = 'Node';
63
+                    break;
64
+            }
65
+            throw new NotFound(
66
+                sprintf(
67
+                    "%s with name '%s' could not be found",
68
+                    $type,
69
+                    $node->getName()
70
+                )
71
+            );
72
+        }
73 73
 
74
-		return $access;
75
-	}
74
+        return $access;
75
+    }
76 76
 
77
-	public function propFind(PropFind $propFind, INode $node) {
78
-		// If the node is neither readable nor writable then fail unless its of
79
-		// the standard user-principal
80
-		if(!($node instanceof User)) {
81
-			$path = $propFind->getPath();
82
-			$readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false);
83
-			$writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false);
84
-			if ($readPermissions === false && $writePermissions === false) {
85
-				$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true);
86
-				$this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true);
87
-			}
88
-		}
77
+    public function propFind(PropFind $propFind, INode $node) {
78
+        // If the node is neither readable nor writable then fail unless its of
79
+        // the standard user-principal
80
+        if(!($node instanceof User)) {
81
+            $path = $propFind->getPath();
82
+            $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false);
83
+            $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false);
84
+            if ($readPermissions === false && $writePermissions === false) {
85
+                $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true);
86
+                $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true);
87
+            }
88
+        }
89 89
 
90
-		return parent::propFind($propFind, $node);
91
-	}
90
+        return parent::propFind($propFind, $node);
91
+    }
92 92
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/LegacyDAVACL.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,42 +32,42 @@
 block discarded – undo
32 32
 
33 33
 class LegacyDAVACL extends DavAclPlugin {
34 34
 
35
-	/**
36
-	 * @inheritdoc
37
-	 */
38
-	public function getCurrentUserPrincipals() {
39
-		$principalV2 = $this->getCurrentUserPrincipal();
35
+    /**
36
+     * @inheritdoc
37
+     */
38
+    public function getCurrentUserPrincipals() {
39
+        $principalV2 = $this->getCurrentUserPrincipal();
40 40
 
41
-		if (is_null($principalV2)) return [];
41
+        if (is_null($principalV2)) return [];
42 42
 
43
-		$principalV1 = $this->convertPrincipal($principalV2, false);
44
-		return array_merge(
45
-			[
46
-				$principalV2,
47
-				$principalV1
48
-			],
49
-			$this->getPrincipalMembership($principalV1)
50
-		);
51
-	}
43
+        $principalV1 = $this->convertPrincipal($principalV2, false);
44
+        return array_merge(
45
+            [
46
+                $principalV2,
47
+                $principalV1
48
+            ],
49
+            $this->getPrincipalMembership($principalV1)
50
+        );
51
+    }
52 52
 
53
-	private function convertPrincipal($principal, $toV2) {
54
-		list(, $name) = URLUtil::splitPath($principal);
55
-		if ($toV2) {
56
-			return "principals/users/$name";
57
-		}
58
-		return "principals/$name";
59
-	}
53
+    private function convertPrincipal($principal, $toV2) {
54
+        list(, $name) = URLUtil::splitPath($principal);
55
+        if ($toV2) {
56
+            return "principals/users/$name";
57
+        }
58
+        return "principals/$name";
59
+    }
60 60
 
61
-	public function propFind(PropFind $propFind, INode $node) {
62
-		/* Overload current-user-principal */
63
-		$propFind->handle('{DAV:}current-user-principal', function () {
64
-			if ($url = parent::getCurrentUserPrincipal()) {
65
-				return new Principal(Principal::HREF, $url . '/');
66
-			} else {
67
-				return new Principal(Principal::UNAUTHENTICATED);
68
-			}
69
-		});
61
+    public function propFind(PropFind $propFind, INode $node) {
62
+        /* Overload current-user-principal */
63
+        $propFind->handle('{DAV:}current-user-principal', function () {
64
+            if ($url = parent::getCurrentUserPrincipal()) {
65
+                return new Principal(Principal::HREF, $url . '/');
66
+            } else {
67
+                return new Principal(Principal::UNAUTHENTICATED);
68
+            }
69
+        });
70 70
 
71
-		return parent::propFind($propFind, $node);
72
-	}
71
+        return parent::propFind($propFind, $node);
72
+    }
73 73
 }
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -39,134 +39,134 @@
 block discarded – undo
39 39
 
40 40
 class Application extends App {
41 41
 
42
-	/**
43
-	 * Application constructor.
44
-	 */
45
-	public function __construct() {
46
-		parent::__construct('dav');
42
+    /**
43
+     * Application constructor.
44
+     */
45
+    public function __construct() {
46
+        parent::__construct('dav');
47 47
 
48
-		/*
48
+        /*
49 49
 		 * Register capabilities
50 50
 		 */
51
-		$this->getContainer()->registerCapability(Capabilities::class);
52
-	}
53
-
54
-	/**
55
-	 * @param IManager $contactsManager
56
-	 * @param string $userID
57
-	 */
58
-	public function setupContactsProvider(IManager $contactsManager, $userID) {
59
-		/** @var ContactsManager $cm */
60
-		$cm = $this->getContainer()->query(ContactsManager::class);
61
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
62
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
63
-	}
64
-
65
-	public function registerHooks() {
66
-		/** @var HookManager $hm */
67
-		$hm = $this->getContainer()->query(HookManager::class);
68
-		$hm->setup();
69
-
70
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
71
-
72
-		// first time login event setup
73
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
74
-			if ($event instanceof GenericEvent) {
75
-				$hm->firstLogin($event->getSubject());
76
-			}
77
-		});
78
-
79
-		// carddav/caldav sync event setup
80
-		$listener = function($event) {
81
-			if ($event instanceof GenericEvent) {
82
-				/** @var BirthdayService $b */
83
-				$b = $this->getContainer()->query(BirthdayService::class);
84
-				$b->onCardChanged(
85
-					$event->getArgument('addressBookId'),
86
-					$event->getArgument('cardUri'),
87
-					$event->getArgument('cardData')
88
-				);
89
-			}
90
-		};
91
-
92
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
93
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
94
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
95
-			if ($event instanceof GenericEvent) {
96
-				/** @var BirthdayService $b */
97
-				$b = $this->getContainer()->query(BirthdayService::class);
98
-				$b->onCardDeleted(
99
-					$event->getArgument('addressBookId'),
100
-					$event->getArgument('cardUri')
101
-				);
102
-			}
103
-		});
104
-
105
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
106
-			$user = $event->getSubject();
107
-			$syncService = $this->getContainer()->query(SyncService::class);
108
-			$syncService->updateUser($user);
109
-		});
110
-
111
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
112
-			/** @var Backend $backend */
113
-			$backend = $this->getContainer()->query(Backend::class);
114
-			$backend->onCalendarAdd(
115
-				$event->getArgument('calendarData')
116
-			);
117
-		});
118
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
119
-			/** @var Backend $backend */
120
-			$backend = $this->getContainer()->query(Backend::class);
121
-			$backend->onCalendarUpdate(
122
-				$event->getArgument('calendarData'),
123
-				$event->getArgument('shares'),
124
-				$event->getArgument('propertyMutations')
125
-			);
126
-		});
127
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
128
-			/** @var Backend $backend */
129
-			$backend = $this->getContainer()->query(Backend::class);
130
-			$backend->onCalendarDelete(
131
-				$event->getArgument('calendarData'),
132
-				$event->getArgument('shares')
133
-			);
134
-		});
135
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
136
-			/** @var Backend $backend */
137
-			$backend = $this->getContainer()->query(Backend::class);
138
-			$backend->onCalendarUpdateShares(
139
-				$event->getArgument('calendarData'),
140
-				$event->getArgument('shares'),
141
-				$event->getArgument('add'),
142
-				$event->getArgument('remove')
143
-			);
144
-		});
145
-
146
-		$listener = function(GenericEvent $event, $eventName) {
147
-			/** @var Backend $backend */
148
-			$backend = $this->getContainer()->query(Backend::class);
149
-
150
-			$subject = Event::SUBJECT_OBJECT_ADD;
151
-			if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
152
-				$subject = Event::SUBJECT_OBJECT_UPDATE;
153
-			} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
154
-				$subject = Event::SUBJECT_OBJECT_DELETE;
155
-			}
156
-			$backend->onTouchCalendarObject(
157
-				$subject,
158
-				$event->getArgument('calendarData'),
159
-				$event->getArgument('shares'),
160
-				$event->getArgument('objectData')
161
-			);
162
-		};
163
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
164
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
165
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
166
-	}
167
-
168
-	public function getSyncService() {
169
-		return $this->getContainer()->query(SyncService::class);
170
-	}
51
+        $this->getContainer()->registerCapability(Capabilities::class);
52
+    }
53
+
54
+    /**
55
+     * @param IManager $contactsManager
56
+     * @param string $userID
57
+     */
58
+    public function setupContactsProvider(IManager $contactsManager, $userID) {
59
+        /** @var ContactsManager $cm */
60
+        $cm = $this->getContainer()->query(ContactsManager::class);
61
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
62
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
63
+    }
64
+
65
+    public function registerHooks() {
66
+        /** @var HookManager $hm */
67
+        $hm = $this->getContainer()->query(HookManager::class);
68
+        $hm->setup();
69
+
70
+        $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
71
+
72
+        // first time login event setup
73
+        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
74
+            if ($event instanceof GenericEvent) {
75
+                $hm->firstLogin($event->getSubject());
76
+            }
77
+        });
78
+
79
+        // carddav/caldav sync event setup
80
+        $listener = function($event) {
81
+            if ($event instanceof GenericEvent) {
82
+                /** @var BirthdayService $b */
83
+                $b = $this->getContainer()->query(BirthdayService::class);
84
+                $b->onCardChanged(
85
+                    $event->getArgument('addressBookId'),
86
+                    $event->getArgument('cardUri'),
87
+                    $event->getArgument('cardData')
88
+                );
89
+            }
90
+        };
91
+
92
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
93
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
94
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
95
+            if ($event instanceof GenericEvent) {
96
+                /** @var BirthdayService $b */
97
+                $b = $this->getContainer()->query(BirthdayService::class);
98
+                $b->onCardDeleted(
99
+                    $event->getArgument('addressBookId'),
100
+                    $event->getArgument('cardUri')
101
+                );
102
+            }
103
+        });
104
+
105
+        $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
106
+            $user = $event->getSubject();
107
+            $syncService = $this->getContainer()->query(SyncService::class);
108
+            $syncService->updateUser($user);
109
+        });
110
+
111
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
112
+            /** @var Backend $backend */
113
+            $backend = $this->getContainer()->query(Backend::class);
114
+            $backend->onCalendarAdd(
115
+                $event->getArgument('calendarData')
116
+            );
117
+        });
118
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
119
+            /** @var Backend $backend */
120
+            $backend = $this->getContainer()->query(Backend::class);
121
+            $backend->onCalendarUpdate(
122
+                $event->getArgument('calendarData'),
123
+                $event->getArgument('shares'),
124
+                $event->getArgument('propertyMutations')
125
+            );
126
+        });
127
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
128
+            /** @var Backend $backend */
129
+            $backend = $this->getContainer()->query(Backend::class);
130
+            $backend->onCalendarDelete(
131
+                $event->getArgument('calendarData'),
132
+                $event->getArgument('shares')
133
+            );
134
+        });
135
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
136
+            /** @var Backend $backend */
137
+            $backend = $this->getContainer()->query(Backend::class);
138
+            $backend->onCalendarUpdateShares(
139
+                $event->getArgument('calendarData'),
140
+                $event->getArgument('shares'),
141
+                $event->getArgument('add'),
142
+                $event->getArgument('remove')
143
+            );
144
+        });
145
+
146
+        $listener = function(GenericEvent $event, $eventName) {
147
+            /** @var Backend $backend */
148
+            $backend = $this->getContainer()->query(Backend::class);
149
+
150
+            $subject = Event::SUBJECT_OBJECT_ADD;
151
+            if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
152
+                $subject = Event::SUBJECT_OBJECT_UPDATE;
153
+            } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
154
+                $subject = Event::SUBJECT_OBJECT_DELETE;
155
+            }
156
+            $backend->onTouchCalendarObject(
157
+                $subject,
158
+                $event->getArgument('calendarData'),
159
+                $event->getArgument('shares'),
160
+                $event->getArgument('objectData')
161
+            );
162
+        };
163
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
164
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
165
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
166
+    }
167
+
168
+    public function getSyncService() {
169
+        return $this->getContainer()->query(SyncService::class);
170
+    }
171 171
 
172 172
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/FixBirthdayCalendarComponent.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@
 block discarded – undo
28 28
 
29 29
 class FixBirthdayCalendarComponent implements IRepairStep {
30 30
 
31
-	/** @var IDBConnection */
32
-	private $connection;
33
-
34
-	/**
35
-	 * FixBirthdayCalendarComponent constructor.
36
-	 *
37
-	 * @param IDBConnection $connection
38
-	 */
39
-	public function __construct(IDBConnection $connection) {
40
-		$this->connection = $connection;
41
-	}
42
-
43
-	/**
44
-	 * @inheritdoc
45
-	 */
46
-	public function getName() {
47
-		return 'Fix component of birthday calendars';
48
-	}
49
-
50
-	/**
51
-	 * @inheritdoc
52
-	 */
53
-	public function run(IOutput $output) {
54
-		$query = $this->connection->getQueryBuilder();
55
-		$updated = $query->update('calendars')
56
-			->set('components', $query->createNamedParameter('VEVENT'))
57
-			->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
58
-			->execute();
59
-
60
-		$output->info("$updated birthday calendars updated.");
61
-	}
31
+    /** @var IDBConnection */
32
+    private $connection;
33
+
34
+    /**
35
+     * FixBirthdayCalendarComponent constructor.
36
+     *
37
+     * @param IDBConnection $connection
38
+     */
39
+    public function __construct(IDBConnection $connection) {
40
+        $this->connection = $connection;
41
+    }
42
+
43
+    /**
44
+     * @inheritdoc
45
+     */
46
+    public function getName() {
47
+        return 'Fix component of birthday calendars';
48
+    }
49
+
50
+    /**
51
+     * @inheritdoc
52
+     */
53
+    public function run(IOutput $output) {
54
+        $query = $this->connection->getQueryBuilder();
55
+        $updated = $query->update('calendars')
56
+            ->set('components', $query->createNamedParameter('VEVENT'))
57
+            ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
58
+            ->execute();
59
+
60
+        $output->info("$updated birthday calendars updated.");
61
+    }
62 62
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncBirthdayCalendar.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -33,55 +33,55 @@
 block discarded – undo
33 33
 
34 34
 class SyncBirthdayCalendar extends Command {
35 35
 
36
-	/** @var BirthdayService */
37
-	private $birthdayService;
36
+    /** @var BirthdayService */
37
+    private $birthdayService;
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/**
43
-	 * @param IUserManager $userManager
44
-	 * @param BirthdayService $birthdayService
45
-	 */
46
-	function __construct(IUserManager $userManager, BirthdayService $birthdayService) {
47
-		parent::__construct();
48
-		$this->birthdayService = $birthdayService;
49
-		$this->userManager = $userManager;
50
-	}
42
+    /**
43
+     * @param IUserManager $userManager
44
+     * @param BirthdayService $birthdayService
45
+     */
46
+    function __construct(IUserManager $userManager, BirthdayService $birthdayService) {
47
+        parent::__construct();
48
+        $this->birthdayService = $birthdayService;
49
+        $this->userManager = $userManager;
50
+    }
51 51
 
52
-	protected function configure() {
53
-		$this
54
-			->setName('dav:sync-birthday-calendar')
55
-			->setDescription('Synchronizes the birthday calendar')
56
-			->addArgument('user',
57
-				InputArgument::OPTIONAL,
58
-				'User for whom the birthday calendar will be synchronized');
59
-	}
52
+    protected function configure() {
53
+        $this
54
+            ->setName('dav:sync-birthday-calendar')
55
+            ->setDescription('Synchronizes the birthday calendar')
56
+            ->addArgument('user',
57
+                InputArgument::OPTIONAL,
58
+                'User for whom the birthday calendar will be synchronized');
59
+    }
60 60
 
61
-	/**
62
-	 * @param InputInterface $input
63
-	 * @param OutputInterface $output
64
-	 */
65
-	protected function execute(InputInterface $input, OutputInterface $output) {
66
-		$user = $input->getArgument('user');
67
-		if (!is_null($user)) {
68
-			if (!$this->userManager->userExists($user)) {
69
-				throw new \InvalidArgumentException("User <$user> in unknown.");
70
-			}
71
-			$output->writeln("Start birthday calendar sync for $user");
72
-			$this->birthdayService->syncUser($user);
73
-			return;
74
-		}
75
-		$output->writeln("Start birthday calendar sync for all users ...");
76
-		$p = new ProgressBar($output);
77
-		$p->start();
78
-		$this->userManager->callForAllUsers(function($user) use ($p)  {
79
-			$p->advance();
80
-			/** @var IUser $user */
81
-			$this->birthdayService->syncUser($user->getUID());
82
-		});
61
+    /**
62
+     * @param InputInterface $input
63
+     * @param OutputInterface $output
64
+     */
65
+    protected function execute(InputInterface $input, OutputInterface $output) {
66
+        $user = $input->getArgument('user');
67
+        if (!is_null($user)) {
68
+            if (!$this->userManager->userExists($user)) {
69
+                throw new \InvalidArgumentException("User <$user> in unknown.");
70
+            }
71
+            $output->writeln("Start birthday calendar sync for $user");
72
+            $this->birthdayService->syncUser($user);
73
+            return;
74
+        }
75
+        $output->writeln("Start birthday calendar sync for all users ...");
76
+        $p = new ProgressBar($output);
77
+        $p->start();
78
+        $this->userManager->callForAllUsers(function($user) use ($p)  {
79
+            $p->advance();
80
+            /** @var IUser $user */
81
+            $this->birthdayService->syncUser($user->getUID());
82
+        });
83 83
 
84
-		$p->finish();
85
-		$output->writeln('');
86
-	}
84
+        $p->finish();
85
+        $output->writeln('');
86
+    }
87 87
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncSystemAddressBook.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
 
32 32
 class SyncSystemAddressBook extends Command {
33 33
 
34
-	/** @var SyncService */
35
-	private $syncService;
34
+    /** @var SyncService */
35
+    private $syncService;
36 36
 
37
-	/**
38
-	 * @param SyncService $syncService
39
-	 */
40
-	function __construct(SyncService $syncService) {
41
-		parent::__construct();
42
-		$this->syncService = $syncService;
43
-	}
37
+    /**
38
+     * @param SyncService $syncService
39
+     */
40
+    function __construct(SyncService $syncService) {
41
+        parent::__construct();
42
+        $this->syncService = $syncService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('dav:sync-system-addressbook')
48
-			->setDescription('Synchronizes users to the system addressbook');
49
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('dav:sync-system-addressbook')
48
+            ->setDescription('Synchronizes users to the system addressbook');
49
+    }
50 50
 
51
-	/**
52
-	 * @param InputInterface $input
53
-	 * @param OutputInterface $output
54
-	 */
55
-	protected function execute(InputInterface $input, OutputInterface $output) {
56
-		$output->writeln('Syncing users ...');
57
-		$progress = new ProgressBar($output);
58
-		$progress->start();
59
-		$this->syncService->syncInstance(function() use ($progress) {
60
-			$progress->advance();
61
-		});
51
+    /**
52
+     * @param InputInterface $input
53
+     * @param OutputInterface $output
54
+     */
55
+    protected function execute(InputInterface $input, OutputInterface $output) {
56
+        $output->writeln('Syncing users ...');
57
+        $progress = new ProgressBar($output);
58
+        $progress->start();
59
+        $this->syncService->syncInstance(function() use ($progress) {
60
+            $progress->advance();
61
+        });
62 62
 
63
-		$progress->finish();
64
-		$output->writeln('');
65
-	}
63
+        $progress->finish();
64
+        $output->writeln('');
65
+    }
66 66
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/CreateCalendar.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -33,53 +33,53 @@
 block discarded – undo
33 33
 
34 34
 class CreateCalendar extends Command {
35 35
 
36
-	/** @var IUserManager */
37
-	protected $userManager;
36
+    /** @var IUserManager */
37
+    protected $userManager;
38 38
 
39
-	/** @var IGroupManager $groupManager */
40
-	private $groupManager;
39
+    /** @var IGroupManager $groupManager */
40
+    private $groupManager;
41 41
 
42
-	/** @var \OCP\IDBConnection */
43
-	protected $dbConnection;
42
+    /** @var \OCP\IDBConnection */
43
+    protected $dbConnection;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param IGroupManager $groupManager
48
-	 * @param IDBConnection $dbConnection
49
-	 */
50
-	function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
51
-		parent::__construct();
52
-		$this->userManager = $userManager;
53
-		$this->groupManager = $groupManager;
54
-		$this->dbConnection = $dbConnection;
55
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param IGroupManager $groupManager
48
+     * @param IDBConnection $dbConnection
49
+     */
50
+    function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
51
+        parent::__construct();
52
+        $this->userManager = $userManager;
53
+        $this->groupManager = $groupManager;
54
+        $this->dbConnection = $dbConnection;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-			->setName('dav:create-calendar')
60
-			->setDescription('Create a dav calendar')
61
-			->addArgument('user',
62
-				InputArgument::REQUIRED,
63
-				'User for whom the calendar will be created')
64
-			->addArgument('name',
65
-				InputArgument::REQUIRED,
66
-				'Name of the calendar');
67
-	}
57
+    protected function configure() {
58
+        $this
59
+            ->setName('dav:create-calendar')
60
+            ->setDescription('Create a dav calendar')
61
+            ->addArgument('user',
62
+                InputArgument::REQUIRED,
63
+                'User for whom the calendar will be created')
64
+            ->addArgument('name',
65
+                InputArgument::REQUIRED,
66
+                'Name of the calendar');
67
+    }
68 68
 
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-		$user = $input->getArgument('user');
71
-		if (!$this->userManager->userExists($user)) {
72
-			throw new \InvalidArgumentException("User <$user> in unknown.");
73
-		}
74
-		$principalBackend = new Principal(
75
-			$this->userManager,
76
-			$this->groupManager
77
-		);
78
-		$random = \OC::$server->getSecureRandom();
79
-		$dispatcher = \OC::$server->getEventDispatcher();
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+        $user = $input->getArgument('user');
71
+        if (!$this->userManager->userExists($user)) {
72
+            throw new \InvalidArgumentException("User <$user> in unknown.");
73
+        }
74
+        $principalBackend = new Principal(
75
+            $this->userManager,
76
+            $this->groupManager
77
+        );
78
+        $random = \OC::$server->getSecureRandom();
79
+        $dispatcher = \OC::$server->getEventDispatcher();
80 80
 
81
-		$name = $input->getArgument('name');
82
-		$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher);
83
-		$caldav->createCalendar("principals/users/$user", $name, []);
84
-	}
81
+        $name = $input->getArgument('name');
82
+        $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher);
83
+        $caldav->createCalendar("principals/users/$user", $name, []);
84
+    }
85 85
 }
Please login to merge, or discard this patch.