mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 16:26:59 -04:00
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>
This commit is contained in:
parent
5579aaa7cb
commit
701b57b81d
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\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\ILogger;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Share\IManager as IShareManager;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'files_versions';
|
||||
|
|
@ -67,14 +72,14 @@ class Application extends App implements IBootstrap {
|
|||
/** @var IServerContainer $server */
|
||||
$server = $c->get(IServerContainer::class);
|
||||
return new Principal(
|
||||
$server->getUserManager(),
|
||||
$server->getGroupManager(),
|
||||
$server->getShareManager(),
|
||||
$server->getUserSession(),
|
||||
$server->getAppManager(),
|
||||
$server->get(IUserManager::class),
|
||||
$server->get(IGroupManager::class),
|
||||
$server->get(IShareManager::class),
|
||||
$server->get(IUserSession::class),
|
||||
$server->get(IAppManager::class),
|
||||
$server->get(ProxyMapper::class),
|
||||
$server->get(KnownUserService::class),
|
||||
$server->getConfig()
|
||||
$server->get(IConfig::class)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -98,7 +103,7 @@ class Application extends App implements IBootstrap {
|
|||
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) {
|
||||
$appInfo = $appManager->getAppInfo($app);
|
||||
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 */
|
||||
$versionManager = $container->get(IVersionManager::class);
|
||||
$class = $backend['@value'];
|
||||
|
|
@ -125,7 +130,7 @@ class Application extends App implements IBootstrap {
|
|||
$backendObject = $container->get($class);
|
||||
$versionManager->registerBackend($for, $backendObject);
|
||||
} 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 OCP\Command\ICommand;
|
||||
use OCP\Files\StorageNotAvailableException;
|
||||
use OCP\ILogger;
|
||||
use OCP\IUserManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Expire implements ICommand {
|
||||
use FileAccess;
|
||||
|
|
@ -42,18 +43,14 @@ class Expire implements ICommand {
|
|||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $fileName
|
||||
*/
|
||||
public function __construct($user, $fileName) {
|
||||
public function __construct(string $user, string $fileName) {
|
||||
$this->user = $user;
|
||||
$this->fileName = $fileName;
|
||||
}
|
||||
|
||||
|
||||
public function handle() {
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
/** @var IUserManager $userManager */
|
||||
$userManager = \OC::$server->get(IUserManager::class);
|
||||
if (!$userManager->userExists($this->user)) {
|
||||
// User has been deleted already
|
||||
return;
|
||||
|
|
@ -65,11 +62,10 @@ class Expire implements ICommand {
|
|||
// In case of external storage and session credentials, the expiration
|
||||
// fails because the command does not have those credentials
|
||||
|
||||
/** @var ILogger $logger */
|
||||
$logger = \OC::$server->get(ILogger::class);
|
||||
|
||||
$logger->logException($e, [
|
||||
'level' => ILogger::WARN,
|
||||
/** @var LoggerInterface */
|
||||
$logger = \OC::$server->get(LoggerInterface::class);
|
||||
$logger->warning($e->getMessage(), [
|
||||
'exception' => $e,
|
||||
'uid' => $this->user,
|
||||
'fileName' => $this->fileName,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ use OCP\AppFramework\Controller;
|
|||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\FileDisplayResponse;
|
||||
use OCP\Files\IMimeTypeDetector;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IPreview;
|
||||
|
|
@ -44,9 +43,6 @@ class PreviewController extends Controller {
|
|||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var IMimeTypeDetector */
|
||||
private $mimeTypeDetector;
|
||||
|
||||
/** @var IVersionManager */
|
||||
private $versionManager;
|
||||
|
||||
|
|
@ -54,11 +50,10 @@ class PreviewController extends Controller {
|
|||
private $previewManager;
|
||||
|
||||
public function __construct(
|
||||
$appName,
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IRootFolder $rootFolder,
|
||||
IUserSession $userSession,
|
||||
IMimeTypeDetector $mimeTypeDetector,
|
||||
IVersionManager $versionManager,
|
||||
IPreview $previewManager
|
||||
) {
|
||||
|
|
@ -66,7 +61,6 @@ class PreviewController extends Controller {
|
|||
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userSession = $userSession;
|
||||
$this->mimeTypeDetector = $mimeTypeDetector;
|
||||
$this->versionManager = $versionManager;
|
||||
$this->previewManager = $previewManager;
|
||||
}
|
||||
|
|
@ -82,10 +76,10 @@ class PreviewController extends Controller {
|
|||
* @return DataResponse|FileDisplayResponse
|
||||
*/
|
||||
public function getPreview(
|
||||
$file = '',
|
||||
$x = 44,
|
||||
$y = 44,
|
||||
$version = ''
|
||||
string $file = '',
|
||||
int $x = 44,
|
||||
int $y = 44,
|
||||
string $version = ''
|
||||
) {
|
||||
if ($file === '' || $version === '' || $x === 0 || $y === 0) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
|
|
|
|||
|
|
@ -58,14 +58,14 @@ class CreateVersionEvent extends Event {
|
|||
*
|
||||
* @return Node
|
||||
*/
|
||||
public function getNode() {
|
||||
public function getNode(): Node {
|
||||
return $this->node;
|
||||
}
|
||||
|
||||
/**
|
||||
* disable versions for this file
|
||||
*/
|
||||
public function disableVersions() {
|
||||
public function disableVersions(): void {
|
||||
$this->createVersion = false;
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ class CreateVersionEvent extends Event {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldCreateVersion() {
|
||||
public function shouldCreateVersion(): bool {
|
||||
return $this->createVersion;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace OCA\Files_Versions;
|
|||
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IConfig;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Expiration {
|
||||
|
||||
|
|
@ -47,8 +48,12 @@ class Expiration {
|
|||
/** @var bool */
|
||||
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->logger = $logger;
|
||||
$this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto');
|
||||
|
||||
if ($this->retentionObligation !== 'disabled') {
|
||||
|
|
@ -60,14 +65,14 @@ class Expiration {
|
|||
* Is versions expiration enabled
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled() {
|
||||
public function isEnabled(): bool {
|
||||
return $this->retentionObligation !== 'disabled';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is default expiration active
|
||||
*/
|
||||
public function shouldAutoExpire() {
|
||||
public function shouldAutoExpire(): bool {
|
||||
return $this->minAge === self::NO_OBLIGATION
|
||||
|| $this->maxAge === self::NO_OBLIGATION;
|
||||
}
|
||||
|
|
@ -78,7 +83,7 @@ class Expiration {
|
|||
* @param bool $quotaExceeded
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired($timestamp, $quotaExceeded = false) {
|
||||
public function isExpired(int $timestamp, bool $quotaExceeded = false): bool {
|
||||
// No expiration if disabled
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
|
|
@ -117,7 +122,8 @@ class Expiration {
|
|||
|
||||
/**
|
||||
* Get maximal retention obligation as a timestamp
|
||||
* @return int
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public function getMaxAgeAsTimestamp() {
|
||||
$maxAge = false;
|
||||
|
|
@ -132,7 +138,7 @@ class Expiration {
|
|||
* Read versions_retention_obligation, validate it
|
||||
* and set private members accordingly
|
||||
*/
|
||||
private function parseRetentionObligation() {
|
||||
private function parseRetentionObligation(): void {
|
||||
$splitValues = explode(',', $this->retentionObligation);
|
||||
if (!isset($splitValues[0])) {
|
||||
$minValue = 'auto';
|
||||
|
|
@ -150,7 +156,7 @@ class Expiration {
|
|||
// Validate
|
||||
if (!ctype_digit($minValue) && $minValue !== 'auto') {
|
||||
$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.',
|
||||
['app' => 'files_versions']
|
||||
);
|
||||
|
|
@ -158,7 +164,7 @@ class Expiration {
|
|||
|
||||
if (!ctype_digit($maxValue) && $maxValue !== 'auto') {
|
||||
$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.',
|
||||
['app' => 'files_versions']
|
||||
);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class Hooks {
|
|||
/**
|
||||
* listen to write event.
|
||||
*/
|
||||
public static function write_hook($params) {
|
||||
public static function write_hook(array $params): void {
|
||||
$path = $params[Filesystem::signal_param_path];
|
||||
if ($path !== '') {
|
||||
Storage::store($path);
|
||||
|
|
@ -65,7 +65,7 @@ class Hooks {
|
|||
* This function is connected to the delete signal of OC_Filesystem
|
||||
* 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];
|
||||
if ($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
|
||||
* @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];
|
||||
if ($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
|
||||
* 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'];
|
||||
$newpath = $params['newpath'];
|
||||
if ($oldpath !== '' && $newpath !== '') {
|
||||
|
|
@ -105,7 +105,7 @@ class Hooks {
|
|||
* This function is connected to the copy signal of OC_Filesystem and copies the
|
||||
* the stored versions to the new location
|
||||
*/
|
||||
public static function copy_hook($params) {
|
||||
public static function copy_hook(array $params): void {
|
||||
$oldpath = $params['oldpath'];
|
||||
$newpath = $params['newpath'];
|
||||
if ($oldpath !== '' && $newpath !== '') {
|
||||
|
|
@ -121,7 +121,7 @@ class Hooks {
|
|||
* @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
|
||||
// to be renamed
|
||||
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files' . $params['oldpath']);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class Plugin extends ServerPlugin {
|
|||
|
||||
public function afterGet(RequestInterface $request, ResponseInterface $response) {
|
||||
$path = $request->getPath();
|
||||
if (strpos($path, 'versions') !== 0) {
|
||||
if (!str_starts_with($path, 'versions')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use OCA\Files_Versions\Versions\IVersionManager;
|
|||
use OCP\Files\IRootFolder;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use Sabre\DAV\INode;
|
||||
use Sabre\DAVACL\AbstractPrincipalCollection;
|
||||
use Sabre\DAVACL\PrincipalBackend;
|
||||
|
|
@ -42,18 +43,23 @@ class RootCollection extends AbstractPrincipalCollection {
|
|||
/** @var IVersionManager */
|
||||
private $versionManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
public function __construct(
|
||||
PrincipalBackend\BackendInterface $principalBackend,
|
||||
IRootFolder $rootFolder,
|
||||
IConfig $config,
|
||||
IUserManager $userManager,
|
||||
IVersionManager $versionManager
|
||||
IVersionManager $versionManager,
|
||||
IUserSession $userSession
|
||||
) {
|
||||
parent::__construct($principalBackend, 'principals/users');
|
||||
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userManager = $userManager;
|
||||
$this->versionManager = $versionManager;
|
||||
$this->userSession = $userSession;
|
||||
|
||||
$this->disableListing = !$config->getSystemValue('debug', false);
|
||||
}
|
||||
|
|
@ -70,7 +76,7 @@ class RootCollection extends AbstractPrincipalCollection {
|
|||
*/
|
||||
public function getChildForPrincipal(array $principalInfo) {
|
||||
[, $name] = \Sabre\Uri\split($principalInfo['uri']);
|
||||
$user = \OC::$server->getUserSession()->getUser();
|
||||
$user = $this->userSession->getUser();
|
||||
if (is_null($user) || $name !== $user->getUID()) {
|
||||
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\IVersionManager;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\IUser;
|
||||
use Sabre\DAV\Exception\Forbidden;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
use Sabre\DAV\ICollection;
|
||||
|
||||
class VersionCollection implements ICollection {
|
||||
/** @var Folder */
|
||||
private $userFolder;
|
||||
|
||||
/** @var File */
|
||||
private $file;
|
||||
|
|
@ -48,8 +45,7 @@ class VersionCollection implements ICollection {
|
|||
/** @var IVersionManager */
|
||||
private $versionManager;
|
||||
|
||||
public function __construct(Folder $userFolder, File $file, IUser $user, IVersionManager $versionManager) {
|
||||
$this->userFolder = $userFolder;
|
||||
public function __construct(File $file, IUser $user, IVersionManager $versionManager) {
|
||||
$this->file = $file;
|
||||
$this->user = $user;
|
||||
$this->versionManager = $versionManager;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class VersionRoot implements ICollection {
|
|||
throw new NotFound();
|
||||
}
|
||||
|
||||
return new VersionCollection($userFolder, $node, $this->user, $this->versionManager);
|
||||
return new VersionCollection($node, $this->user, $this->versionManager);
|
||||
}
|
||||
|
||||
public function getChildren(): array {
|
||||
|
|
|
|||
|
|
@ -46,10 +46,17 @@ use OCA\Files_Versions\AppInfo\Application;
|
|||
use OCA\Files_Versions\Command\Expire;
|
||||
use OCA\Files_Versions\Events\CreateVersionEvent;
|
||||
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\StorageNotAvailableException;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Lock\ILockingProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Storage {
|
||||
public const DEFAULTENABLED = true;
|
||||
|
|
@ -93,7 +100,7 @@ class Storage {
|
|||
*/
|
||||
public static function getUidAndFilename($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
|
||||
// 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
|
||||
|
|
@ -176,10 +183,10 @@ class Storage {
|
|||
|
||||
$files_view = new View('/'.$uid .'/files');
|
||||
|
||||
$eventDispatcher = \OC::$server->getEventDispatcher();
|
||||
$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
|
||||
$fileInfo = $files_view->getFileInfo($filename);
|
||||
$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) {
|
||||
$event = new CreateVersionEvent($node);
|
||||
$eventDispatcher->dispatch('OCA\Files_Versions::createVersion', $event);
|
||||
|
|
@ -194,8 +201,8 @@ class Storage {
|
|||
}
|
||||
|
||||
/** @var IVersionManager $versionManager */
|
||||
$versionManager = \OC::$server->query(IVersionManager::class);
|
||||
$userManager = \OC::$server->getUserManager();
|
||||
$versionManager = \OC::$server->get(IVersionManager::class);
|
||||
$userManager = \OC::$server->get(IUserManager::class);
|
||||
$user = $userManager->get($uid);
|
||||
|
||||
$versionManager->createVersion($user, $fileInfo);
|
||||
|
|
@ -324,7 +331,8 @@ class Storage {
|
|||
$filename = '/' . ltrim($file, '/');
|
||||
|
||||
// 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());
|
||||
$files_view = new View('/'. $user->getUID().'/files');
|
||||
|
|
@ -464,12 +472,15 @@ class Storage {
|
|||
if (empty($userFullPath)) {
|
||||
$versions[$key]['preview'] = '';
|
||||
} 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]['name'] = $versionedFile;
|
||||
$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
|
||||
$toDelete[$key] = $version['path'] . '.v' . $version['version'];
|
||||
$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 {
|
||||
$nextVersion = $version['version'] - $step;
|
||||
$prevTimestamp = $version['version'];
|
||||
|
|
@ -691,7 +702,9 @@ class Storage {
|
|||
$expiration = self::getExpiration();
|
||||
if ($expiration->isEnabled()) {
|
||||
$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) {
|
||||
$expiration = self::getExpiration();
|
||||
|
||||
/** @var LoggerInterface $logger */
|
||||
$logger = \OC::$server->get(LoggerInterface::class);
|
||||
|
||||
if ($expiration->isEnabled()) {
|
||||
// get available disk space for user
|
||||
$user = \OC::$server->getUserManager()->get($uid);
|
||||
$user = \OC::$server->get(IUserManager::class)->get($uid);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -750,7 +766,8 @@ class Storage {
|
|||
// subtract size of files and current versions size from quota
|
||||
if ($quota >= 0) {
|
||||
if ($softQuota) {
|
||||
$userFolder = \OC::$server->getUserFolder($uid);
|
||||
$root = \OC::$server->get(IRootFolder::class);
|
||||
$userFolder = $root->getUserFolder($uid);
|
||||
if (is_null($userFolder)) {
|
||||
$availableSpace = 0;
|
||||
} else {
|
||||
|
|
@ -790,7 +807,6 @@ class Storage {
|
|||
$versionsSize = $versionsSize - $sizeOfDeletedVersions;
|
||||
}
|
||||
|
||||
$logger = \OC::$server->getLogger();
|
||||
foreach ($toDelete as $key => $path) {
|
||||
\OC_Hook::emit('\OCP\Versions', 'preDelete', ['path' => $path, 'trigger' => self::DELETE_TRIGGER_QUOTA_EXCEEDED]);
|
||||
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]);
|
||||
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::$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'];
|
||||
$availableSpace += $version['size'];
|
||||
next($allVersions);
|
||||
|
|
@ -851,8 +867,8 @@ class Storage {
|
|||
*/
|
||||
protected static function getExpiration() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue