aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib')
-rw-r--r--apps/files/lib/Activity/Settings/FavoriteAction.php16
-rw-r--r--apps/files/lib/Activity/Settings/FileActivitySettings.php (renamed from apps/files/lib/Search/FilesSearchResultEntry.php)33
-rw-r--r--apps/files/lib/Activity/Settings/FileChanged.php48
-rw-r--r--apps/files/lib/Activity/Settings/FileCreated.php98
-rw-r--r--apps/files/lib/Activity/Settings/FileFavorite.php98
-rw-r--r--apps/files/lib/Activity/Settings/FileFavoriteChanged.php (renamed from apps/files/lib/Activity/Settings/FileDeleted.php)26
-rw-r--r--apps/files/lib/Activity/Settings/FileRestored.php98
-rw-r--r--apps/files/lib/AppInfo/Application.php121
-rw-r--r--apps/files/lib/Command/DeleteOrphanedFiles.php33
-rw-r--r--apps/files/lib/Controller/ApiController.php2
-rw-r--r--apps/files/lib/Controller/ViewController.php5
-rw-r--r--apps/files/lib/Event/LoadAdditionalScriptsEvent.php5
-rw-r--r--apps/files/lib/Search/FilesSearchProvider.php63
-rw-r--r--apps/files/lib/Service/OwnershipTransferService.php2
14 files changed, 202 insertions, 446 deletions
diff --git a/apps/files/lib/Activity/Settings/FavoriteAction.php b/apps/files/lib/Activity/Settings/FavoriteAction.php
index 9db53eada8e..017669a137c 100644
--- a/apps/files/lib/Activity/Settings/FavoriteAction.php
+++ b/apps/files/lib/Activity/Settings/FavoriteAction.php
@@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings;
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FavoriteAction implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
+class FavoriteAction extends FileActivitySettings {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
diff --git a/apps/files/lib/Search/FilesSearchResultEntry.php b/apps/files/lib/Activity/Settings/FileActivitySettings.php
index c4f6e491d6f..0ec7cb27be5 100644
--- a/apps/files/lib/Search/FilesSearchResultEntry.php
+++ b/apps/files/lib/Activity/Settings/FileActivitySettings.php
@@ -3,9 +3,7 @@
declare(strict_types=1);
/**
- * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
@@ -21,17 +19,30 @@ declare(strict_types=1);
*
* 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\Files\Search;
+namespace OCA\Files\Activity\Settings;
+
+use OCP\Activity\ActivitySettings;
+use OCP\IL10N;
+
+abstract class FileActivitySettings extends ActivitySettings {
+ /** @var IL10N */
+ protected $l;
-use OCP\Search\ASearchResultEntry;
+ /**
+ * @param IL10N $l
+ */
+ public function __construct(IL10N $l) {
+ $this->l = $l;
+ }
+
+ public function getGroupIdentifier() {
+ return 'files';
+ }
-class FilesSearchResultEntry extends ASearchResultEntry {
- public function __construct(string $thumbnailUrl,
- string $filename,
- string $path,
- string $url) {
- parent::__construct($thumbnailUrl, $filename, $path, $url);
+ public function getGroupName() {
+ return $this->l->t('Files');
}
}
diff --git a/apps/files/lib/Activity/Settings/FileChanged.php b/apps/files/lib/Activity/Settings/FileChanged.php
index 503201bd129..aa684e5acb1 100644
--- a/apps/files/lib/Activity/Settings/FileChanged.php
+++ b/apps/files/lib/Activity/Settings/FileChanged.php
@@ -23,21 +23,7 @@
namespace OCA\Files\Activity\Settings;
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileChanged implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
+class FileChanged extends FileActivitySettings {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
@@ -51,7 +37,7 @@ class FileChanged implements ISetting {
* @since 11.0.0
*/
public function getName() {
- return $this->l->t('A file or folder has been <strong>changed</strong> or <strong>renamed</strong>');
+ return $this->l->t('A file or folder has been <strong>changed</strong>');
}
/**
@@ -64,35 +50,19 @@ class FileChanged implements ISetting {
return 1;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function canChangeStream() {
- return true;
+ public function canChangeMail() {
+ return false;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledStream() {
- return true;
+ public function isDefaultEnabledMail() {
+ return false;
}
- /**
- * @return bool True when the option can be changed for the mail
- * @since 11.0.0
- */
- public function canChangeMail() {
- return true;
+ public function canChangeNotification() {
+ return false;
}
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledMail() {
+ public function isDefaultEnabledNotification() {
return false;
}
}
diff --git a/apps/files/lib/Activity/Settings/FileCreated.php b/apps/files/lib/Activity/Settings/FileCreated.php
deleted file mode 100644
index 481c719d024..00000000000
--- a/apps/files/lib/Activity/Settings/FileCreated.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author 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/>.
- *
- */
-
-namespace OCA\Files\Activity\Settings;
-
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileCreated implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
- /**
- * @return string Lowercase a-z and underscore only identifier
- * @since 11.0.0
- */
- public function getIdentifier() {
- return 'file_created';
- }
-
- /**
- * @return string A translated string
- * @since 11.0.0
- */
- public function getName() {
- return $this->l->t('A new file or folder has been <strong>created</strong>');
- }
-
- /**
- * @return int whether the filter should be rather on the top or bottom of
- * the admin section. The filters are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
- * @since 11.0.0
- */
- public function getPriority() {
- return 0;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function canChangeStream() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledStream() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the mail
- * @since 11.0.0
- */
- public function canChangeMail() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledMail() {
- return false;
- }
-}
diff --git a/apps/files/lib/Activity/Settings/FileFavorite.php b/apps/files/lib/Activity/Settings/FileFavorite.php
deleted file mode 100644
index ac62242f703..00000000000
--- a/apps/files/lib/Activity/Settings/FileFavorite.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author 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/>.
- *
- */
-
-namespace OCA\Files\Activity\Settings;
-
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileFavorite implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
- /**
- * @return string Lowercase a-z and underscore only identifier
- * @since 11.0.0
- */
- public function getIdentifier() {
- return 'file_favorite';
- }
-
- /**
- * @return string A translated string
- * @since 11.0.0
- */
- public function getName() {
- return $this->l->t('Limit notifications about creation and changes to your <strong>favorite files</strong> <em>(Stream only)</em>');
- }
-
- /**
- * @return int whether the filter should be rather on the top or bottom of
- * the admin section. The filters are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
- * @since 11.0.0
- */
- public function getPriority() {
- return 2;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function canChangeStream() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledStream() {
- return false;
- }
-
- /**
- * @return bool True when the option can be changed for the mail
- * @since 11.0.0
- */
- public function canChangeMail() {
- return false;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledMail() {
- return false;
- }
-}
diff --git a/apps/files/lib/Activity/Settings/FileDeleted.php b/apps/files/lib/Activity/Settings/FileFavoriteChanged.php
index d4e56b6c717..e1730cc8d41 100644
--- a/apps/files/lib/Activity/Settings/FileDeleted.php
+++ b/apps/files/lib/Activity/Settings/FileFavoriteChanged.php
@@ -23,27 +23,13 @@
namespace OCA\Files\Activity\Settings;
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileDeleted implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
+class FileFavoriteChanged extends FileActivitySettings {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
- return 'file_deleted';
+ return 'file_favorite_changed';
}
/**
@@ -51,7 +37,7 @@ class FileDeleted implements ISetting {
* @since 11.0.0
*/
public function getName() {
- return $this->l->t('A file or folder has been <strong>deleted</strong>');
+ return $this->l->t('A favorite file or folder has been <strong>changed</strong>');
}
/**
@@ -61,7 +47,7 @@ class FileDeleted implements ISetting {
* @since 11.0.0
*/
public function getPriority() {
- return 3;
+ return 1;
}
/**
@@ -95,4 +81,8 @@ class FileDeleted implements ISetting {
public function isDefaultEnabledMail() {
return false;
}
+
+ public function isDefaultEnabledNotification() {
+ return true;
+ }
}
diff --git a/apps/files/lib/Activity/Settings/FileRestored.php b/apps/files/lib/Activity/Settings/FileRestored.php
deleted file mode 100644
index 59b722ddf85..00000000000
--- a/apps/files/lib/Activity/Settings/FileRestored.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
- *
- * @author 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/>.
- *
- */
-
-namespace OCA\Files\Activity\Settings;
-
-use OCP\Activity\ISetting;
-use OCP\IL10N;
-
-class FileRestored implements ISetting {
-
- /** @var IL10N */
- protected $l;
-
- /**
- * @param IL10N $l
- */
- public function __construct(IL10N $l) {
- $this->l = $l;
- }
-
- /**
- * @return string Lowercase a-z and underscore only identifier
- * @since 11.0.0
- */
- public function getIdentifier() {
- return 'file_restored';
- }
-
- /**
- * @return string A translated string
- * @since 11.0.0
- */
- public function getName() {
- return $this->l->t('A file or folder has been <strong>restored</strong>');
- }
-
- /**
- * @return int whether the filter should be rather on the top or bottom of
- * the admin section. The filters are arranged in ascending order of the
- * priority values. It is required to return a value between 0 and 100.
- * @since 11.0.0
- */
- public function getPriority() {
- return 4;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function canChangeStream() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledStream() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the mail
- * @since 11.0.0
- */
- public function canChangeMail() {
- return true;
- }
-
- /**
- * @return bool True when the option can be changed for the stream
- * @since 11.0.0
- */
- public function isDefaultEnabledMail() {
- return false;
- }
-}
diff --git a/apps/files/lib/AppInfo/Application.php b/apps/files/lib/AppInfo/Application.php
index 5e473c411ee..434fb482aa8 100644
--- a/apps/files/lib/AppInfo/Application.php
+++ b/apps/files/lib/AppInfo/Application.php
@@ -34,6 +34,7 @@ declare(strict_types=1);
namespace OCA\Files\AppInfo;
+use Closure;
use OC\Search\Provider\File;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
@@ -46,16 +47,24 @@ use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Notification\Notifier;
use OCA\Files\Search\FilesSearchProvider;
use OCA\Files\Service\TagService;
+use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Resources\IProviderManager;
-use OCP\IContainer;
+use OCP\IConfig;
use OCP\IL10N;
+use OCP\IPreview;
+use OCP\ISearch;
+use OCP\IRequest;
use OCP\IServerContainer;
+use OCP\ITagManager;
+use OCP\IUserSession;
use OCP\Notification\IManager;
+use OCP\Share\IManager as IShareManager;
use OCP\Util;
+use Psr\Container\ContainerInterface;
class Application extends App implements IBootstrap {
public const APP_ID = 'files';
@@ -68,18 +77,18 @@ class Application extends App implements IBootstrap {
/**
* Controllers
*/
- $context->registerService('APIController', function (IContainer $c) {
+ $context->registerService('APIController', function (ContainerInterface $c) {
/** @var IServerContainer $server */
- $server = $c->query(IServerContainer::class);
+ $server = $c->get(IServerContainer::class);
return new ApiController(
- $c->query('AppName'),
- $c->query('Request'),
- $server->getUserSession(),
- $c->query('TagService'),
- $server->getPreviewManager(),
- $server->getShareManager(),
- $server->getConfig(),
+ $c->get('AppName'),
+ $c->get(IRequest::class),
+ $c->get(IUserSession::class),
+ $c->get(TagService::class),
+ $c->get(IPreview::class),
+ $c->get(IShareManager::class),
+ $c->get(IConfig::class),
$server->getUserFolder()
);
});
@@ -87,14 +96,14 @@ class Application extends App implements IBootstrap {
/**
* Services
*/
- $context->registerService('TagService', function (IContainer $c) {
+ $context->registerService(TagService::class, function (ContainerInterface $c) {
/** @var IServerContainer $server */
- $server = $c->query(IServerContainer::class);
+ $server = $c->get(IServerContainer::class);
return new TagService(
- $server->getUserSession(),
- $server->getActivityManager(),
- $server->getTagManager()->load(self::APP_ID),
+ $c->get(IUserSession::class),
+ $c->get(IActivityManager::class),
+ $c->get(ITagManager::class)->load(self::APP_ID),
$server->getUserFolder(),
$server->getEventDispatcher()
);
@@ -112,35 +121,25 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
- $this->registerCollaboration($context);
- Listener::register($context->getServerContainer()->getEventDispatcher());
- $this->registerNotification($context);
- $this->registerSearchProvider($context);
+ $context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
+ $context->injectFn([Listener::class, 'register']);
+ $context->injectFn(Closure::fromCallable([$this, 'registerNotification']));
+ $context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider']));
$this->registerTemplates();
- $this->registerNavigation($context);
+ $context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
$this->registerHooks();
}
- /**
- * Register Collaboration ResourceProvider
- */
- private function registerCollaboration(IBootContext $context): void {
- /** @var IProviderManager $providerManager */
- $providerManager = $context->getAppContainer()->query(IProviderManager::class);
+ private function registerCollaboration(IProviderManager $providerManager): void {
$providerManager->registerResourceProvider(ResourceProvider::class);
}
- private function registerNotification(IBootContext $context): void {
- /** @var IManager $notifications */
- $notifications = $context->getAppContainer()->query(IManager::class);
+ private function registerNotification(IManager $notifications): void {
$notifications->registerNotifierService(Notifier::class);
}
- /**
- * @param IBootContext $context
- */
- private function registerSearchProvider(IBootContext $context): void {
- $context->getServerContainer()->getSearch()->registerProvider(File::class, ['apps' => ['files']]);
+ private function registerSearchProvider(ISearch $search): void {
+ $search->registerProvider(File::class, ['apps' => ['files']]);
}
private function registerTemplates(): void {
@@ -150,31 +149,35 @@ class Application extends App implements IBootstrap {
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
}
- private function registerNavigation(IBootContext $context): void {
- /** @var IL10N $l10n */
- $l10n = $context->getAppContainer()->query(IL10N::class);
- \OCA\Files\App::getNavigationManager()->add([
- 'id' => 'files',
- 'appname' => 'files',
- 'script' => 'list.php',
- 'order' => 0,
- 'name' => $l10n->t('All files')
- ]);
- \OCA\Files\App::getNavigationManager()->add([
- 'id' => 'recent',
- 'appname' => 'files',
- 'script' => 'recentlist.php',
- 'order' => 2,
- 'name' => $l10n->t('Recent')
- ]);
- \OCA\Files\App::getNavigationManager()->add([
- 'id' => 'favorites',
- 'appname' => 'files',
- 'script' => 'simplelist.php',
- 'order' => 5,
- 'name' => $l10n->t('Favorites'),
- 'expandedState' => 'show_Quick_Access'
- ]);
+ private function registerNavigation(IL10N $l10n): void {
+ \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
+ return [
+ 'id' => 'files',
+ 'appname' => 'files',
+ 'script' => 'list.php',
+ 'order' => 0,
+ 'name' => $l10n->t('All files')
+ ];
+ });
+ \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
+ return [
+ 'id' => 'recent',
+ 'appname' => 'files',
+ 'script' => 'recentlist.php',
+ 'order' => 2,
+ 'name' => $l10n->t('Recent')
+ ];
+ });
+ \OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
+ return [
+ 'id' => 'favorites',
+ 'appname' => 'files',
+ 'script' => 'simplelist.php',
+ 'order' => 5,
+ 'name' => $l10n->t('Favorites'),
+ 'expandedState' => 'show_Quick_Access'
+ ];
+ });
}
private function registerHooks(): void {
diff --git a/apps/files/lib/Command/DeleteOrphanedFiles.php b/apps/files/lib/Command/DeleteOrphanedFiles.php
index c8ce9729ef7..9795448ff97 100644
--- a/apps/files/lib/Command/DeleteOrphanedFiles.php
+++ b/apps/files/lib/Command/DeleteOrphanedFiles.php
@@ -78,6 +78,39 @@ class DeleteOrphanedFiles extends Command {
}
$output->writeln("$deletedEntries orphaned file cache entries deleted");
+
+ $deletedMounts = $this->cleanupOrphanedMounts();
+ $output->writeln("$deletedMounts orphaned mount entries deleted");
return 0;
}
+
+ private function cleanupOrphanedMounts() {
+ $deletedEntries = 0;
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('m.storage_id')
+ ->from('mounts', 'm')
+ ->where($query->expr()->isNull('s.numeric_id'))
+ ->leftJoin('m', 'storages', 's', $query->expr()->eq('m.storage_id', 's.numeric_id'))
+ ->groupBy('storage_id')
+ ->setMaxResults(self::CHUNK_SIZE);
+
+ $deleteQuery = $this->connection->getQueryBuilder();
+ $deleteQuery->delete('mounts')
+ ->where($deleteQuery->expr()->eq('storage_id', $deleteQuery->createParameter('storageid')));
+
+ $deletedInLastChunk = self::CHUNK_SIZE;
+ while ($deletedInLastChunk === self::CHUNK_SIZE) {
+ $deletedInLastChunk = 0;
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ $deletedInLastChunk++;
+ $deletedEntries += $deleteQuery->setParameter('storageid', (int) $row['storage_id'])
+ ->execute();
+ }
+ $result->closeCursor();
+ }
+
+ return $deletedEntries;
+ }
}
diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php
index 2add685133e..16596ea05a6 100644
--- a/apps/files/lib/Controller/ApiController.php
+++ b/apps/files/lib/Controller/ApiController.php
@@ -332,7 +332,7 @@ class ApiController extends Controller {
*
* @NoAdminRequired
*
- * @param string
+ * @param string $folderpath
* @return string
* @throws \OCP\Files\NotFoundException
*/
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 73ee589fdbc..1568e0c9f54 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -278,9 +278,8 @@ class ViewController extends Controller {
}
$event = new LoadAdditionalScriptsEvent();
- $this->eventDispatcher->dispatch(LoadAdditionalScriptsEvent::class, $event);
-
- $this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar());
+ $this->eventDispatcher->dispatchTyped($event);
+ $this->eventDispatcher->dispatchTyped(new LoadSidebar());
// Load Viewer scripts
if (class_exists(LoadViewer::class)) {
$this->eventDispatcher->dispatchTyped(new LoadViewer());
diff --git a/apps/files/lib/Event/LoadAdditionalScriptsEvent.php b/apps/files/lib/Event/LoadAdditionalScriptsEvent.php
index d9c80a23207..458ec916f8f 100644
--- a/apps/files/lib/Event/LoadAdditionalScriptsEvent.php
+++ b/apps/files/lib/Event/LoadAdditionalScriptsEvent.php
@@ -28,6 +28,11 @@ namespace OCA\Files\Event;
use OCP\EventDispatcher\Event;
+/**
+ * This event is triggered when the files app is rendered. It canb e used to add additional scripts to the files app.
+ *
+ * @since 17.0.0
+ */
class LoadAdditionalScriptsEvent extends Event {
private $hiddenFields = [];
diff --git a/apps/files/lib/Search/FilesSearchProvider.php b/apps/files/lib/Search/FilesSearchProvider.php
index 3f1c4de0aa1..e221dab0ab1 100644
--- a/apps/files/lib/Search/FilesSearchProvider.php
+++ b/apps/files/lib/Search/FilesSearchProvider.php
@@ -27,12 +27,14 @@ namespace OCA\Files\Search;
use OC\Search\Provider\File;
use OC\Search\Result\File as FileResult;
+use OCP\Files\IMimeTypeDetector;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\IProvider;
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
+use OCP\Search\SearchResultEntry;
class FilesSearchProvider implements IProvider {
@@ -45,29 +47,80 @@ class FilesSearchProvider implements IProvider {
/** @var IURLGenerator */
private $urlGenerator;
+ /** @var IMimeTypeDetector */
+ private $mimeTypeDetector;
+
public function __construct(File $fileSearch,
IL10N $l10n,
- IURLGenerator $urlGenerator) {
+ IURLGenerator $urlGenerator,
+ IMimeTypeDetector $mimeTypeDetector) {
$this->l10n = $l10n;
$this->fileSearch = $fileSearch;
$this->urlGenerator = $urlGenerator;
+ $this->mimeTypeDetector = $mimeTypeDetector;
}
+ /**
+ * @inheritDoc
+ */
public function getId(): string {
return 'files';
}
+ /**
+ * @inheritDoc
+ */
+ public function getName(): string {
+ return $this->l10n->t('Files');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getOrder(string $route, array $routeParameters): int {
+ if ($route === 'files.View.index') {
+ // Before comments
+ return -5;
+ }
+ return 5;
+ }
+
+ /**
+ * @inheritDoc
+ */
public function search(IUser $user, ISearchQuery $query): SearchResult {
return SearchResult::complete(
$this->l10n->t('Files'),
array_map(function (FileResult $result) {
- return new FilesSearchResultEntry(
- $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]),
+ // Generate thumbnail url
+ $thumbnailUrl = $result->has_preview
+ ? $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id])
+ : '';
+
+ return new SearchResultEntry(
+ $thumbnailUrl,
$result->name,
- $result->path,
- $result->link
+ $this->formatSubline($result),
+ $result->link,
+ $result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type)
);
}, $this->fileSearch->search($query->getTerm()))
);
}
+
+ /**
+ * Format subline for files
+ *
+ * @param FileResult $result
+ * @return string
+ */
+ private function formatSubline($result): string {
+ // Do not show the location if the file is in root
+ if ($result->path === '/' . $result->name) {
+ return '';
+ }
+
+ $path = ltrim(dirname($result->path), '/');
+ return $this->l10n->t('in %s', [$path]);
+ }
}
diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php
index 535822b999c..b04a53919ac 100644
--- a/apps/files/lib/Service/OwnershipTransferService.php
+++ b/apps/files/lib/Service/OwnershipTransferService.php
@@ -194,7 +194,7 @@ class OwnershipTransferService {
$output->writeln('Validating quota');
$size = $view->getFileInfo($sourcePath, false)->getSize(false);
$freeSpace = $view->free_space($destinationUid . '/files/');
- if ($size > $freeSpace) {
+ if ($size > $freeSpace && $freeSpace !== FileInfo::SPACE_UNKNOWN) {
$output->writeln('<error>Target user does not have enough free space available.</error>');
throw new \Exception('Execution terminated.');
}