Remove allmost all deprecation from the files_version app

The remaining deprecations are related to Utils::hooks and I will take a
look at how EventDispatcher works before working on them.

Aside from the deprecations, this patch also does a few minor
improvements around type hinting.

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/27968/head
Carl Schwan 2021-07-14 14:48:23 +07:00
parent 5579aaa7cb
commit 701b57b81d
No known key found for this signature in database
GPG Key ID: 06B35D38387B67BE
11 changed files with 96 additions and 77 deletions

@ -43,9 +43,14 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\ILogger; use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IManager as IShareManager;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class Application extends App implements IBootstrap { class Application extends App implements IBootstrap {
public const APP_ID = 'files_versions'; public const APP_ID = 'files_versions';
@ -67,14 +72,14 @@ class Application extends App implements IBootstrap {
/** @var IServerContainer $server */ /** @var IServerContainer $server */
$server = $c->get(IServerContainer::class); $server = $c->get(IServerContainer::class);
return new Principal( return new Principal(
$server->getUserManager(), $server->get(IUserManager::class),
$server->getGroupManager(), $server->get(IGroupManager::class),
$server->getShareManager(), $server->get(IShareManager::class),
$server->getUserSession(), $server->get(IUserSession::class),
$server->getAppManager(), $server->get(IAppManager::class),
$server->get(ProxyMapper::class), $server->get(ProxyMapper::class),
$server->get(KnownUserService::class), $server->get(KnownUserService::class),
$server->getConfig() $server->get(IConfig::class)
); );
}); });
@ -98,7 +103,7 @@ class Application extends App implements IBootstrap {
Hooks::connectHooks(); Hooks::connectHooks();
} }
public function registerVersionBackends(ContainerInterface $container, IAppManager $appManager, ILogger $logger) { public function registerVersionBackends(ContainerInterface $container, IAppManager $appManager, LoggerInterface $logger): void {
foreach ($appManager->getInstalledApps() as $app) { foreach ($appManager->getInstalledApps() as $app) {
$appInfo = $appManager->getAppInfo($app); $appInfo = $appManager->getAppInfo($app);
if (isset($appInfo['versions'])) { if (isset($appInfo['versions'])) {
@ -116,7 +121,7 @@ class Application extends App implements IBootstrap {
} }
} }
private function loadBackend(array $backend, ContainerInterface $container, ILogger $logger) { private function loadBackend(array $backend, ContainerInterface $container, LoggerInterface $logger): void {
/** @var IVersionManager $versionManager */ /** @var IVersionManager $versionManager */
$versionManager = $container->get(IVersionManager::class); $versionManager = $container->get(IVersionManager::class);
$class = $backend['@value']; $class = $backend['@value'];
@ -125,7 +130,7 @@ class Application extends App implements IBootstrap {
$backendObject = $container->get($class); $backendObject = $container->get($class);
$versionManager->registerBackend($for, $backendObject); $versionManager->registerBackend($for, $backendObject);
} catch (\Exception $e) { } catch (\Exception $e) {
$logger->logException($e); $logger->error($e->getMessage(), ['exception' => $e]);
} }
} }
} }

@ -27,7 +27,8 @@ use OC\Command\FileAccess;
use OCA\Files_Versions\Storage; use OCA\Files_Versions\Storage;
use OCP\Command\ICommand; use OCP\Command\ICommand;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\ILogger; use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class Expire implements ICommand { class Expire implements ICommand {
use FileAccess; use FileAccess;
@ -42,18 +43,14 @@ class Expire implements ICommand {
*/ */
private $user; private $user;
/** public function __construct(string $user, string $fileName) {
* @param string $user
* @param string $fileName
*/
public function __construct($user, $fileName) {
$this->user = $user; $this->user = $user;
$this->fileName = $fileName; $this->fileName = $fileName;
} }
public function handle() { public function handle() {
$userManager = \OC::$server->getUserManager(); /** @var IUserManager $userManager */
$userManager = \OC::$server->get(IUserManager::class);
if (!$userManager->userExists($this->user)) { if (!$userManager->userExists($this->user)) {
// User has been deleted already // User has been deleted already
return; return;
@ -65,11 +62,10 @@ class Expire implements ICommand {
// In case of external storage and session credentials, the expiration // In case of external storage and session credentials, the expiration
// fails because the command does not have those credentials // fails because the command does not have those credentials
/** @var ILogger $logger */ /** @var LoggerInterface */
$logger = \OC::$server->get(ILogger::class); $logger = \OC::$server->get(LoggerInterface::class);
$logger->warning($e->getMessage(), [
$logger->logException($e, [ 'exception' => $e,
'level' => ILogger::WARN,
'uid' => $this->user, 'uid' => $this->user,
'fileName' => $this->fileName, 'fileName' => $this->fileName,
]); ]);

@ -29,7 +29,6 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IPreview; use OCP\IPreview;
@ -44,9 +43,6 @@ class PreviewController extends Controller {
/** @var IUserSession */ /** @var IUserSession */
private $userSession; private $userSession;
/** @var IMimeTypeDetector */
private $mimeTypeDetector;
/** @var IVersionManager */ /** @var IVersionManager */
private $versionManager; private $versionManager;
@ -54,11 +50,10 @@ class PreviewController extends Controller {
private $previewManager; private $previewManager;
public function __construct( public function __construct(
$appName, string $appName,
IRequest $request, IRequest $request,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IUserSession $userSession, IUserSession $userSession,
IMimeTypeDetector $mimeTypeDetector,
IVersionManager $versionManager, IVersionManager $versionManager,
IPreview $previewManager IPreview $previewManager
) { ) {
@ -66,7 +61,6 @@ class PreviewController extends Controller {
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->userSession = $userSession; $this->userSession = $userSession;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->versionManager = $versionManager; $this->versionManager = $versionManager;
$this->previewManager = $previewManager; $this->previewManager = $previewManager;
} }
@ -82,10 +76,10 @@ class PreviewController extends Controller {
* @return DataResponse|FileDisplayResponse * @return DataResponse|FileDisplayResponse
*/ */
public function getPreview( public function getPreview(
$file = '', string $file = '',
$x = 44, int $x = 44,
$y = 44, int $y = 44,
$version = '' string $version = ''
) { ) {
if ($file === '' || $version === '' || $x === 0 || $y === 0) { if ($file === '' || $version === '' || $x === 0 || $y === 0) {
return new DataResponse([], Http::STATUS_BAD_REQUEST); return new DataResponse([], Http::STATUS_BAD_REQUEST);

@ -58,14 +58,14 @@ class CreateVersionEvent extends Event {
* *
* @return Node * @return Node
*/ */
public function getNode() { public function getNode(): Node {
return $this->node; return $this->node;
} }
/** /**
* disable versions for this file * disable versions for this file
*/ */
public function disableVersions() { public function disableVersions(): void {
$this->createVersion = false; $this->createVersion = false;
} }
@ -74,7 +74,7 @@ class CreateVersionEvent extends Event {
* *
* @return bool * @return bool
*/ */
public function shouldCreateVersion() { public function shouldCreateVersion(): bool {
return $this->createVersion; return $this->createVersion;
} }
} }

@ -26,6 +26,7 @@ namespace OCA\Files_Versions;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig; use OCP\IConfig;
use Psr\Log\LoggerInterface;
class Expiration { class Expiration {
@ -47,8 +48,12 @@ class Expiration {
/** @var bool */ /** @var bool */
private $canPurgeToSaveSpace; private $canPurgeToSaveSpace;
public function __construct(IConfig $config,ITimeFactory $timeFactory) { /** @var LoggerInterface */
private $logger;
public function __construct(IConfig $config, ITimeFactory $timeFactory, LoggerInterface $logger) {
$this->timeFactory = $timeFactory; $this->timeFactory = $timeFactory;
$this->logger = $logger;
$this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto'); $this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto');
if ($this->retentionObligation !== 'disabled') { if ($this->retentionObligation !== 'disabled') {
@ -60,14 +65,14 @@ class Expiration {
* Is versions expiration enabled * Is versions expiration enabled
* @return bool * @return bool
*/ */
public function isEnabled() { public function isEnabled(): bool {
return $this->retentionObligation !== 'disabled'; return $this->retentionObligation !== 'disabled';
} }
/** /**
* Is default expiration active * Is default expiration active
*/ */
public function shouldAutoExpire() { public function shouldAutoExpire(): bool {
return $this->minAge === self::NO_OBLIGATION return $this->minAge === self::NO_OBLIGATION
|| $this->maxAge === self::NO_OBLIGATION; || $this->maxAge === self::NO_OBLIGATION;
} }
@ -78,7 +83,7 @@ class Expiration {
* @param bool $quotaExceeded * @param bool $quotaExceeded
* @return bool * @return bool
*/ */
public function isExpired($timestamp, $quotaExceeded = false) { public function isExpired(int $timestamp, bool $quotaExceeded = false): bool {
// No expiration if disabled // No expiration if disabled
if (!$this->isEnabled()) { if (!$this->isEnabled()) {
return false; return false;
@ -117,7 +122,8 @@ class Expiration {
/** /**
* Get maximal retention obligation as a timestamp * Get maximal retention obligation as a timestamp
* @return int *
* @return int|false
*/ */
public function getMaxAgeAsTimestamp() { public function getMaxAgeAsTimestamp() {
$maxAge = false; $maxAge = false;
@ -132,7 +138,7 @@ class Expiration {
* Read versions_retention_obligation, validate it * Read versions_retention_obligation, validate it
* and set private members accordingly * and set private members accordingly
*/ */
private function parseRetentionObligation() { private function parseRetentionObligation(): void {
$splitValues = explode(',', $this->retentionObligation); $splitValues = explode(',', $this->retentionObligation);
if (!isset($splitValues[0])) { if (!isset($splitValues[0])) {
$minValue = 'auto'; $minValue = 'auto';
@ -150,7 +156,7 @@ class Expiration {
// Validate // Validate
if (!ctype_digit($minValue) && $minValue !== 'auto') { if (!ctype_digit($minValue) && $minValue !== 'auto') {
$isValid = false; $isValid = false;
\OC::$server->getLogger()->warning( $this->logger->warning(
$minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
['app' => 'files_versions'] ['app' => 'files_versions']
); );
@ -158,7 +164,7 @@ class Expiration {
if (!ctype_digit($maxValue) && $maxValue !== 'auto') { if (!ctype_digit($maxValue) && $maxValue !== 'auto') {
$isValid = false; $isValid = false;
\OC::$server->getLogger()->warning( $this->logger->warning(
$maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.',
['app' => 'files_versions'] ['app' => 'files_versions']
); );

@ -50,7 +50,7 @@ class Hooks {
/** /**
* listen to write event. * listen to write event.
*/ */
public static function write_hook($params) { public static function write_hook(array $params): void {
$path = $params[Filesystem::signal_param_path]; $path = $params[Filesystem::signal_param_path];
if ($path !== '') { if ($path !== '') {
Storage::store($path); Storage::store($path);
@ -65,7 +65,7 @@ class Hooks {
* This function is connected to the delete signal of OC_Filesystem * This function is connected to the delete signal of OC_Filesystem
* cleanup the versions directory if the actual file gets deleted * cleanup the versions directory if the actual file gets deleted
*/ */
public static function remove_hook($params) { public static function remove_hook(array $params): void {
$path = $params[Filesystem::signal_param_path]; $path = $params[Filesystem::signal_param_path];
if ($path !== '') { if ($path !== '') {
Storage::delete($path); Storage::delete($path);
@ -76,7 +76,7 @@ class Hooks {
* mark file as "deleted" so that we can clean up the versions if the file is gone * mark file as "deleted" so that we can clean up the versions if the file is gone
* @param array $params * @param array $params
*/ */
public static function pre_remove_hook($params) { public static function pre_remove_hook(array $params): void {
$path = $params[Filesystem::signal_param_path]; $path = $params[Filesystem::signal_param_path];
if ($path !== '') { if ($path !== '') {
Storage::markDeletedFile($path); Storage::markDeletedFile($path);
@ -90,7 +90,7 @@ class Hooks {
* This function is connected to the rename signal of OC_Filesystem and adjust the name and location * This function is connected to the rename signal of OC_Filesystem and adjust the name and location
* of the stored versions along the actual file * of the stored versions along the actual file
*/ */
public static function rename_hook($params) { public static function rename_hook(array $params): void {
$oldpath = $params['oldpath']; $oldpath = $params['oldpath'];
$newpath = $params['newpath']; $newpath = $params['newpath'];
if ($oldpath !== '' && $newpath !== '') { if ($oldpath !== '' && $newpath !== '') {
@ -105,7 +105,7 @@ class Hooks {
* This function is connected to the copy signal of OC_Filesystem and copies the * This function is connected to the copy signal of OC_Filesystem and copies the
* the stored versions to the new location * the stored versions to the new location
*/ */
public static function copy_hook($params) { public static function copy_hook(array $params): void {
$oldpath = $params['oldpath']; $oldpath = $params['oldpath'];
$newpath = $params['newpath']; $newpath = $params['newpath'];
if ($oldpath !== '' && $newpath !== '') { if ($oldpath !== '' && $newpath !== '') {
@ -121,7 +121,7 @@ class Hooks {
* @param array $params array with oldpath and newpath * @param array $params array with oldpath and newpath
* *
*/ */
public static function pre_renameOrCopy_hook($params) { public static function pre_renameOrCopy_hook(array $params): void {
// if we rename a movable mount point, then the versions don't have // if we rename a movable mount point, then the versions don't have
// to be renamed // to be renamed
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files' . $params['oldpath']); $absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files' . $params['oldpath']);

@ -53,7 +53,7 @@ class Plugin extends ServerPlugin {
public function afterGet(RequestInterface $request, ResponseInterface $response) { public function afterGet(RequestInterface $request, ResponseInterface $response) {
$path = $request->getPath(); $path = $request->getPath();
if (strpos($path, 'versions') !== 0) { if (!str_starts_with($path, 'versions')) {
return; return;
} }

@ -27,6 +27,7 @@ use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\IRootFolder; use OCP\Files\IRootFolder;
use OCP\IConfig; use OCP\IConfig;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession;
use Sabre\DAV\INode; use Sabre\DAV\INode;
use Sabre\DAVACL\AbstractPrincipalCollection; use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend; use Sabre\DAVACL\PrincipalBackend;
@ -42,18 +43,23 @@ class RootCollection extends AbstractPrincipalCollection {
/** @var IVersionManager */ /** @var IVersionManager */
private $versionManager; private $versionManager;
/** @var IUserSession */
private $userSession;
public function __construct( public function __construct(
PrincipalBackend\BackendInterface $principalBackend, PrincipalBackend\BackendInterface $principalBackend,
IRootFolder $rootFolder, IRootFolder $rootFolder,
IConfig $config, IConfig $config,
IUserManager $userManager, IUserManager $userManager,
IVersionManager $versionManager IVersionManager $versionManager,
IUserSession $userSession
) { ) {
parent::__construct($principalBackend, 'principals/users'); parent::__construct($principalBackend, 'principals/users');
$this->rootFolder = $rootFolder; $this->rootFolder = $rootFolder;
$this->userManager = $userManager; $this->userManager = $userManager;
$this->versionManager = $versionManager; $this->versionManager = $versionManager;
$this->userSession = $userSession;
$this->disableListing = !$config->getSystemValue('debug', false); $this->disableListing = !$config->getSystemValue('debug', false);
} }
@ -70,7 +76,7 @@ class RootCollection extends AbstractPrincipalCollection {
*/ */
public function getChildForPrincipal(array $principalInfo) { public function getChildForPrincipal(array $principalInfo) {
[, $name] = \Sabre\Uri\split($principalInfo['uri']); [, $name] = \Sabre\Uri\split($principalInfo['uri']);
$user = \OC::$server->getUserSession()->getUser(); $user = $this->userSession->getUser();
if (is_null($user) || $name !== $user->getUID()) { if (is_null($user) || $name !== $user->getUID()) {
throw new \Sabre\DAV\Exception\Forbidden(); throw new \Sabre\DAV\Exception\Forbidden();
} }

@ -29,15 +29,12 @@ namespace OCA\Files_Versions\Sabre;
use OCA\Files_Versions\Versions\IVersion; use OCA\Files_Versions\Versions\IVersion;
use OCA\Files_Versions\Versions\IVersionManager; use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Files\File; use OCP\Files\File;
use OCP\Files\Folder;
use OCP\IUser; use OCP\IUser;
use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound; use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection; use Sabre\DAV\ICollection;
class VersionCollection implements ICollection { class VersionCollection implements ICollection {
/** @var Folder */
private $userFolder;
/** @var File */ /** @var File */
private $file; private $file;
@ -48,8 +45,7 @@ class VersionCollection implements ICollection {
/** @var IVersionManager */ /** @var IVersionManager */
private $versionManager; private $versionManager;
public function __construct(Folder $userFolder, File $file, IUser $user, IVersionManager $versionManager) { public function __construct(File $file, IUser $user, IVersionManager $versionManager) {
$this->userFolder = $userFolder;
$this->file = $file; $this->file = $file;
$this->user = $user; $this->user = $user;
$this->versionManager = $versionManager; $this->versionManager = $versionManager;

@ -87,7 +87,7 @@ class VersionRoot implements ICollection {
throw new NotFound(); throw new NotFound();
} }
return new VersionCollection($userFolder, $node, $this->user, $this->versionManager); return new VersionCollection($node, $this->user, $this->versionManager);
} }
public function getChildren(): array { public function getChildren(): array {

@ -46,10 +46,17 @@ use OCA\Files_Versions\AppInfo\Application;
use OCA\Files_Versions\Command\Expire; use OCA\Files_Versions\Command\Expire;
use OCA\Files_Versions\Events\CreateVersionEvent; use OCA\Files_Versions\Events\CreateVersionEvent;
use OCA\Files_Versions\Versions\IVersionManager; use OCA\Files_Versions\Versions\IVersionManager;
use OCP\Command\IBus;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\IURLGenerator;
use OCP\IUser; use OCP\IUser;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use Psr\Log\LoggerInterface;
class Storage { class Storage {
public const DEFAULTENABLED = true; public const DEFAULTENABLED = true;
@ -93,7 +100,7 @@ class Storage {
*/ */
public static function getUidAndFilename($filename) { public static function getUidAndFilename($filename) {
$uid = Filesystem::getOwner($filename); $uid = Filesystem::getOwner($filename);
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->get(IUserManager::class);
// if the user with the UID doesn't exists, e.g. because the UID points // if the user with the UID doesn't exists, e.g. because the UID points
// to a remote user with a federated cloud ID we use the current logged-in // to a remote user with a federated cloud ID we use the current logged-in
// user. We need a valid local user to create the versions // user. We need a valid local user to create the versions
@ -176,10 +183,10 @@ class Storage {
$files_view = new View('/'.$uid .'/files'); $files_view = new View('/'.$uid .'/files');
$eventDispatcher = \OC::$server->getEventDispatcher(); $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$fileInfo = $files_view->getFileInfo($filename); $fileInfo = $files_view->getFileInfo($filename);
$id = $fileInfo->getId(); $id = $fileInfo->getId();
$nodes = \OC::$server->getRootFolder()->getUserFolder($uid)->getById($id); $nodes = \OC::$server->get(IRootFolder::class)->getUserFolder($uid)->getById($id);
foreach ($nodes as $node) { foreach ($nodes as $node) {
$event = new CreateVersionEvent($node); $event = new CreateVersionEvent($node);
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event); $eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
@ -194,8 +201,8 @@ class Storage {
} }
/** @var IVersionManager $versionManager */ /** @var IVersionManager $versionManager */
$versionManager = \OC::$server->query(IVersionManager::class); $versionManager = \OC::$server->get(IVersionManager::class);
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->get(IUserManager::class);
$user = $userManager->get($uid); $user = $userManager->get($uid);
$versionManager->createVersion($user, $fileInfo); $versionManager->createVersion($user, $fileInfo);
@ -324,7 +331,8 @@ class Storage {
$filename = '/' . ltrim($file, '/'); $filename = '/' . ltrim($file, '/');
// Fetch the userfolder to trigger view hooks // Fetch the userfolder to trigger view hooks
$userFolder = \OC::$server->getUserFolder($user->getUID()); $root = \OC::$server->get(IRootFolder::class);
$userFolder = $root->getUserFolder($user->getUID());
$users_view = new View('/'.$user->getUID()); $users_view = new View('/'.$user->getUID());
$files_view = new View('/'. $user->getUID().'/files'); $files_view = new View('/'. $user->getUID().'/files');
@ -464,12 +472,15 @@ class Storage {
if (empty($userFullPath)) { if (empty($userFullPath)) {
$versions[$key]['preview'] = ''; $versions[$key]['preview'] = '';
} else { } else {
$versions[$key]['preview'] = \OC::$server->getURLGenerator('files_version.Preview.getPreview', ['file' => $userFullPath, 'version' => $timestamp]); /** @var IURLGenerator $urlGenerator */
$urlGenerator = \OC::$server->get(IURLGenerator::class);
$versions[$key]['preview'] = $urlGenerator->linkToRoute('files_version.Preview.getPreview',
['file' => $userFullPath, 'version' => $timestamp]);
} }
$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename); $versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
$versions[$key]['name'] = $versionedFile; $versions[$key]['name'] = $versionedFile;
$versions[$key]['size'] = $view->filesize($dir . '/' . $entryName); $versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
$versions[$key]['mimetype'] = \OC::$server->getMimeTypeDetector()->detectPath($versionedFile); $versions[$key]['mimetype'] = \OC::$server->get(IMimeTypeDetector::class)->detectPath($versionedFile);
} }
} }
} }
@ -657,7 +668,7 @@ class Storage {
//distance between two version too small, mark to delete //distance between two version too small, mark to delete
$toDelete[$key] = $version['path'] . '.v' . $version['version']; $toDelete[$key] = $version['path'] . '.v' . $version['version'];
$size += $version['size']; $size += $version['size'];
\OC::$server->getLogger()->info('Mark to expire '. $version['path'] .' next version should be ' . $nextVersion . " or smaller. (prevTimestamp: " . $prevTimestamp . "; step: " . $step, ['app' => 'files_versions']); \OC::$server->get(LoggerInterface::class)->info('Mark to expire '. $version['path'] .' next version should be ' . $nextVersion . " or smaller. (prevTimestamp: " . $prevTimestamp . "; step: " . $step, ['app' => 'files_versions']);
} else { } else {
$nextVersion = $version['version'] - $step; $nextVersion = $version['version'] - $step;
$prevTimestamp = $version['version']; $prevTimestamp = $version['version'];
@ -691,7 +702,9 @@ class Storage {
$expiration = self::getExpiration(); $expiration = self::getExpiration();
if ($expiration->isEnabled()) { if ($expiration->isEnabled()) {
$command = new Expire($uid, $fileName); $command = new Expire($uid, $fileName);
\OC::$server->getCommandBus()->push($command); /** @var IBus $bus */
$bus = \OC::$server->get(IBus::class);
$bus->push($command);
} }
} }
@ -708,11 +721,14 @@ class Storage {
public static function expire($filename, $uid) { public static function expire($filename, $uid) {
$expiration = self::getExpiration(); $expiration = self::getExpiration();
/** @var LoggerInterface $logger */
$logger = \OC::$server->get(LoggerInterface::class);
if ($expiration->isEnabled()) { if ($expiration->isEnabled()) {
// get available disk space for user // get available disk space for user
$user = \OC::$server->getUserManager()->get($uid); $user = \OC::$server->get(IUserManager::class)->get($uid);
if (is_null($user)) { if (is_null($user)) {
\OC::$server->getLogger()->error('Backends provided no user object for ' . $uid, ['app' => 'files_versions']); $logger->error('Backends provided no user object for ' . $uid, ['app' => 'files_versions']);
throw new \OC\User\NoUserException('Backends provided no user object for ' . $uid); throw new \OC\User\NoUserException('Backends provided no user object for ' . $uid);
} }
@ -750,7 +766,8 @@ class Storage {
// subtract size of files and current versions size from quota // subtract size of files and current versions size from quota
if ($quota >= 0) { if ($quota >= 0) {
if ($softQuota) { if ($softQuota) {
$userFolder = \OC::$server->getUserFolder($uid); $root = \OC::$server->get(IRootFolder::class);
$userFolder = $root->getUserFolder($uid);
if (is_null($userFolder)) { if (is_null($userFolder)) {
$availableSpace = 0; $availableSpace = 0;
} else { } else {
@ -790,7 +807,6 @@ class Storage {
$versionsSize = $versionsSize - $sizeOfDeletedVersions; $versionsSize = $versionsSize - $sizeOfDeletedVersions;
} }
$logger = \OC::$server->getLogger();
foreach ($toDelete as $key => $path) { foreach ($toDelete as $key => $path) {
\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]); \OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
self::deleteVersion($versionsFileview, $path); self::deleteVersion($versionsFileview, $path);
@ -812,7 +828,7 @@ class Storage {
\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]); \OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']); self::deleteVersion($versionsFileview, $version['path'] . '.v' . $version['version']);
\OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]); \OC_Hook::emit('\OCP\Versions', 'delete', ['path' => $version['path'].'.v'.$version['version'], 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
\OC::$server->getLogger()->info('running out of space! Delete oldest version: ' . $version['path'].'.v'.$version['version'], ['app' => 'files_versions']); $logger->info('running out of space! Delete oldest version: ' . $version['path'].'.v'.$version['version'], ['app' => 'files_versions']);
$versionsSize -= $version['size']; $versionsSize -= $version['size'];
$availableSpace += $version['size']; $availableSpace += $version['size'];
next($allVersions); next($allVersions);
@ -851,8 +867,8 @@ class Storage {
*/ */
protected static function getExpiration() { protected static function getExpiration() {
if (self::$application === null) { if (self::$application === null) {
self::$application = \OC::$server->query(Application::class); self::$application = \OC::$server->get(Application::class);
} }
return self::$application->getContainer()->query(Expiration::class); return self::$application->getContainer()->get(Expiration::class);
} }
} }