Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_downloadactivity.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2020-09-04 13:36:59 +0300
committerGitHub <noreply@github.com>2020-09-04 13:36:59 +0300
commit2992d68bd941b6cf8a4dddb681cea55f4650d556 (patch)
tree1a1dd600916a7f014b8d17717ea5ab99bfa6ea81
parent3469adacac1b831dca5cbf41ec73bd792f0561fd (diff)
parent8b6298d090b69324f69fab24b2ca6ce79aebc514 (diff)
Merge pull request #62 from nextcloud/techdebt/noidv1.9.0
Use IBootstrap application class
-rw-r--r--appinfo/app.php23
-rwxr-xr-xlib/Activity/Listener.php8
-rw-r--r--lib/Activity/Provider.php28
-rw-r--r--lib/Activity/Setting.php16
-rw-r--r--lib/AppInfo/Application.php25
-rw-r--r--lib/CurrentUser.php13
6 files changed, 52 insertions, 61 deletions
diff --git a/appinfo/app.php b/appinfo/app.php
deleted file mode 100644
index 764b96c..0000000
--- a/appinfo/app.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.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/>.
- *
- */
-
-$application = \OC::$server->query(\OCA\FilesDownloadActivity\AppInfo\Application::class);
-$application->register();
diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php
index eba1b54..1d4d2b1 100755
--- a/lib/Activity/Listener.php
+++ b/lib/Activity/Listener.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
@@ -67,7 +69,7 @@ class Listener {
* Store the update hook events
* @param string $path Path of the file that has been read
*/
- public function readFile($path) {
+ public function readFile(string $path): void {
// Do not add activities for .part-files
if (substr($path, -5) === '.part') {
return;
@@ -79,7 +81,7 @@ class Listener {
}
try {
- list($filePath, $owner, $fileId, $isDir) = $this->getSourcePathAndOwner($path);
+ [$filePath, $owner, $fileId, $isDir] = $this->getSourcePathAndOwner($path);
} catch (NotFoundException $e) {
return;
} catch (InvalidPathException $e) {
@@ -142,7 +144,7 @@ class Listener {
* @throws NotFoundException
* @throws InvalidPathException
*/
- protected function getSourcePathAndOwner($path) {
+ protected function getSourcePathAndOwner(string $path): array {
$currentUserId = $this->currentUser->getUID();
$userFolder = $this->rootFolder->getUserFolder($currentUserId);
$node = $userFolder->get($path);
diff --git a/lib/Activity/Provider.php b/lib/Activity/Provider.php
index a65326f..c568867 100644
--- a/lib/Activity/Provider.php
+++ b/lib/Activity/Provider.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
@@ -83,7 +85,7 @@ class Provider implements IProvider {
* @throws \InvalidArgumentException
* @since 11.0.0
*/
- public function parse($language, IEvent $event, IEvent $previousEvent = null) {
+ public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'files_downloadactivity') {
throw new \InvalidArgumentException();
}
@@ -108,12 +110,12 @@ class Provider implements IProvider {
/**
* @param IEvent $event
- * @param IEvent $previousEvent
+ * @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
- public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) {
+ public function parseShortVersion(IEvent $event, IEvent $previousEvent = null): IEvent {
$parsedParameters = $this->getParsedParameters($event);
$params = $event->getSubjectParameters();
@@ -137,12 +139,12 @@ class Provider implements IProvider {
/**
* @param IEvent $event
- * @param IEvent $previousEvent
+ * @param IEvent|null $previousEvent
* @return IEvent
* @throws \InvalidArgumentException
* @since 11.0.0
*/
- public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
+ public function parseLongVersion(IEvent $event, IEvent $previousEvent = null): IEvent {
$parsedParameters = $this->getParsedParameters($event);
$params = $event->getSubjectParameters();
@@ -175,7 +177,7 @@ class Provider implements IProvider {
* @param array $parameters
* @throws \InvalidArgumentException
*/
- protected function setSubjects(IEvent $event, $subject, array $parameters) {
+ protected function setSubjects(IEvent $event, string $subject, array $parameters): void {
$placeholders = $replacements = [];
foreach ($parameters as $placeholder => $parameter) {
$placeholders[] = '{' . $placeholder . '}';
@@ -190,7 +192,7 @@ class Provider implements IProvider {
->setRichSubject($subject, $parameters);
}
- protected function getParsedParameters(IEvent $event) {
+ protected function getParsedParameters(IEvent $event): array {
$subject = $event->getSubject();
$parameters = $event->getSubjectParameters();
@@ -199,7 +201,7 @@ class Provider implements IProvider {
case self::SUBJECT_SHARED_FILE_DOWNLOADED:
$id = key($parameters[0]);
return [
- 'file' => $this->generateFileParameter($id, $parameters[0][$id]),
+ 'file' => $this->generateFileParameter((int) $id, $parameters[0][$id]),
'actor' => $this->generateUserParameter($parameters[1]),
];
}
@@ -211,7 +213,7 @@ class Provider implements IProvider {
* @param string $path
* @return array
*/
- protected function generateFileParameter($id, $path) {
+ protected function generateFileParameter(int $id, string $path): array {
return [
'type' => 'file',
'id' => $id,
@@ -225,7 +227,7 @@ class Provider implements IProvider {
* @param string $uid
* @return array
*/
- protected function generateUserParameter($uid) {
+ protected function generateUserParameter(string $uid): array {
if (!isset($this->displayNames[$uid])) {
$this->displayNames[$uid] = $this->getDisplayName($uid);
}
@@ -241,12 +243,12 @@ class Provider implements IProvider {
* @param string $uid
* @return string
*/
- protected function getDisplayName($uid) {
+ protected function getDisplayName(string $uid): string {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
return $user->getDisplayName();
- } else {
- return $uid;
}
+
+ return $uid;
}
}
diff --git a/lib/Activity/Setting.php b/lib/Activity/Setting.php
index 3c3f727..5c6d84b 100644
--- a/lib/Activity/Setting.php
+++ b/lib/Activity/Setting.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
@@ -41,7 +43,7 @@ class Setting implements ISetting {
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
- public function getIdentifier() {
+ public function getIdentifier(): string {
return 'file_downloaded';
}
@@ -49,7 +51,7 @@ class Setting implements ISetting {
* @return string A translated string
* @since 11.0.0
*/
- public function getName() {
+ public function getName(): string {
return $this->l->t('A local shared file or folder was <strong>downloaded</strong>');
}
@@ -59,7 +61,7 @@ class Setting implements ISetting {
* priority values. It is required to return a value between 0 and 100.
* @since 11.0.0
*/
- public function getPriority() {
+ public function getPriority(): int {
return 21;
}
@@ -67,7 +69,7 @@ class Setting implements ISetting {
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
- public function canChangeStream() {
+ public function canChangeStream(): bool {
return true;
}
@@ -75,7 +77,7 @@ class Setting implements ISetting {
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
- public function isDefaultEnabledStream() {
+ public function isDefaultEnabledStream(): bool {
return true;
}
@@ -83,7 +85,7 @@ class Setting implements ISetting {
* @return bool True when the option can be changed for the mail
* @since 11.0.0
*/
- public function canChangeMail() {
+ public function canChangeMail(): bool {
return true;
}
@@ -91,7 +93,7 @@ class Setting implements ISetting {
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
- public function isDefaultEnabledMail() {
+ public function isDefaultEnabledMail(): bool {
return false;
}
}
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index a5edf02..62c8466 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
@@ -23,24 +25,29 @@ namespace OCA\FilesDownloadActivity\AppInfo;
use OCA\FilesDownloadActivity\Activity\Listener;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\File;
use OCP\IPreview;
use OCP\Util;
use Symfony\Component\EventDispatcher\GenericEvent;
-class Application extends App {
+class Application extends App implements IBootstrap {
+
+ public const APP_ID = 'files_downloadactivity';
public function __construct() {
- parent::__construct('files_downloadactivity');
+ parent::__construct(self::APP_ID);
}
- /**
- * Register all hooks and listeners
- */
- public function register() {
+ public function register(IRegistrationContext $context): void {
+ }
+
+ public function boot(IBootContext $context): void {
Util::connectHook('OC_Filesystem', 'read', $this, 'listenReadFile');
- $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
+ $eventDispatcher = $context->getServerContainer()->getEventDispatcher();
$eventDispatcher->addListener(
IPreview::EVENT,
function (GenericEvent $event) {
@@ -52,7 +59,7 @@ class Application extends App {
/**
* @param array $params
*/
- public function listenReadFile($params) {
+ public function listenReadFile(array $params): void {
/** @var Listener $hooks */
$hooks = $this->getContainer()->query(Listener::class);
$hooks->readFile($params['path']);
@@ -61,7 +68,7 @@ class Application extends App {
/**
* @param GenericEvent $event
*/
- public function listenPreviewFile(GenericEvent $event) {
+ public function listenPreviewFile(GenericEvent $event): void {
$details = $event->getArguments();
if ($details['width'] <= 150 && $details['height'] <= 150) {
// Ignore mini preview, but we need "big" previews because of the viewer app.
diff --git a/lib/CurrentUser.php b/lib/CurrentUser.php
index 96680b5..002958e 100644
--- a/lib/CurrentUser.php
+++ b/lib/CurrentUser.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
*
@@ -21,11 +23,10 @@
namespace OCA\FilesDownloadActivity;
-
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
-use OCP\Share;
+use OCP\Share\IShare;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
@@ -59,7 +60,7 @@ class CurrentUser {
* Get an identifier for the user, session or token
* @return string
*/
- public function getUserIdentifier() {
+ public function getUserIdentifier(): string {
if ($this->identifier === null) {
$this->identifier = $this->getUID();
@@ -80,7 +81,7 @@ class CurrentUser {
* Get the current user from the session
* @return string|null
*/
- public function getUID() {
+ public function getUID(): ?string {
if ($this->sessionUser === false) {
$user = $this->userSession->getUser();
if ($user instanceof IUser) {
@@ -97,12 +98,12 @@ class CurrentUser {
* Get the cloud ID from the sharing token
* @return string|null
*/
- protected function getCloudIDFromToken() {
+ protected function getCloudIDFromToken(): ?string {
if (!empty($this->request->server['PHP_AUTH_USER'])) {
$token = $this->request->server['PHP_AUTH_USER'];
try {
$share = $this->shareManager->getShareByToken($token);
- if ($share->getShareType() === Share::SHARE_TYPE_REMOTE) {
+ if ($share->getShareType() === IShare::TYPE_REMOTE) {
return $share->getSharedWith();
}
} catch (ShareNotFound $e) {