2015-03-23 08:07:40 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 10:49:16 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2020-04-29 05:57:22 -04:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-07-21 12:13:36 -04:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2015-06-25 05:43:55 -04:00
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* 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, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-06-25 05:43:55 -04:00
|
|
|
*
|
2015-03-23 08:07:40 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Files_Versions\Command;
|
|
|
|
|
|
|
|
|
|
use OC\Command\FileAccess;
|
|
|
|
|
use OCA\Files_Versions\Storage;
|
|
|
|
|
use OCP\Command\ICommand;
|
2020-11-25 03:28:38 -05:00
|
|
|
use OCP\Files\StorageNotAvailableException;
|
2021-07-14 08:48:23 -04:00
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use Psr\Log\LoggerInterface;
|
2015-03-23 08:07:40 -04:00
|
|
|
|
|
|
|
|
class Expire implements ICommand {
|
|
|
|
|
use FileAccess;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $fileName;
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-26 12:11:34 -04:00
|
|
|
* @var string
|
2015-03-24 05:19:54 -04:00
|
|
|
*/
|
|
|
|
|
private $user;
|
|
|
|
|
|
2021-07-14 08:48:23 -04:00
|
|
|
public function __construct(string $user, string $fileName) {
|
2015-03-24 05:19:54 -04:00
|
|
|
$this->user = $user;
|
2015-03-23 08:07:40 -04:00
|
|
|
$this->fileName = $fileName;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-24 05:19:54 -04:00
|
|
|
public function handle() {
|
2021-07-14 08:48:23 -04:00
|
|
|
/** @var IUserManager $userManager */
|
|
|
|
|
$userManager = \OC::$server->get(IUserManager::class);
|
2015-06-05 05:31:49 -04:00
|
|
|
if (!$userManager->userExists($this->user)) {
|
|
|
|
|
// User has been deleted already
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 03:28:38 -05:00
|
|
|
try {
|
|
|
|
|
Storage::expire($this->fileName, $this->user);
|
|
|
|
|
} catch (StorageNotAvailableException $e) {
|
|
|
|
|
// In case of external storage and session credentials, the expiration
|
|
|
|
|
// fails because the command does not have those credentials
|
|
|
|
|
|
2021-07-14 08:48:23 -04:00
|
|
|
/** @var LoggerInterface */
|
|
|
|
|
$logger = \OC::$server->get(LoggerInterface::class);
|
|
|
|
|
$logger->warning($e->getMessage(), [
|
|
|
|
|
'exception' => $e,
|
2020-11-25 03:28:38 -05:00
|
|
|
'uid' => $this->user,
|
|
|
|
|
'fileName' => $this->fileName,
|
|
|
|
|
]);
|
|
|
|
|
}
|
2015-03-23 08:07:40 -04:00
|
|
|
}
|
|
|
|
|
}
|