use OC\Command\FileAccess;
use OCA\Files_Versions\Storage;
use OCP\Command\ICommand;
+use OCP\IUser;
class Expire implements ICommand {
use FileAccess;
private $neededSpace = 0;
/**
+ * @var int
+ */
+ private $user;
+
+ /**
+ * @param IUser $user
* @param string $fileName
* @param int|null $versionsSize
* @param int $neededSpace
*/
- function __construct($fileName, $versionsSize = null, $neededSpace = 0) {
+ function __construct(IUser $user, $fileName, $versionsSize = null, $neededSpace = 0) {
+ $this->user = $user;
$this->fileName = $fileName;
$this->versionsSize = $versionsSize;
$this->neededSpace = $neededSpace;
}
- public function handle(){
+ public function handle() {
+ $this->setupFS($this->user);
Storage::expire($this->fileName, $this->versionsSize, $this->neededSpace);
}
}
* @param int $neededSpace
*/
private static function scheduleExpire($fileName, $versionsSize = null, $neededSpace = 0) {
- $command = new Expire($fileName, $versionsSize, $neededSpace);
+ $command = new Expire(\OC::$server->getUserSession()->getUser(), $fileName, $versionsSize, $neededSpace);
\OC::$server->getCommandBus()->push($command);
}
// execute rename hook of versions app
\OC\Files\Filesystem::rename("test.txt", "test2.txt");
+ $this->runCommands();
+
$this->assertFalse($this->rootView->file_exists($v1));
$this->assertFalse($this->rootView->file_exists($v2));
// execute rename hook of versions app
\OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt');
+
self::loginHelper(self::TEST_VERSIONS_USER2);
+ $this->runCommands();
+
$this->assertFalse($this->rootView->file_exists($v1));
$this->assertFalse($this->rootView->file_exists($v2));
self::loginHelper(self::TEST_VERSIONS_USER);
+ $this->runCommands();
+
$this->assertTrue($this->rootView->file_exists($v1));
$this->assertTrue($this->rootView->file_exists($v2));
// execute copy hook of versions app
\OC\Files\Filesystem::copy("test.txt", "test2.txt");
+ $this->runCommands();
+
$this->assertTrue($this->rootView->file_exists($v1));
$this->assertTrue($this->rootView->file_exists($v2));
public static function loginHelper($user, $create = false) {
if ($create) {
- \OC_User::createUser($user, $user);
+ $backend = new \OC_User_Dummy();
+ $backend->createUser($user, $user);
+ \OC::$server->getUserManager()->registerBackend($backend);
}
\OC_Util::tearDownFS();