Completed
Push — master ( 4c7e31...07f4c1 )
by
unknown
38:19 queued 39s
created
apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,63 +18,63 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class ExpireTrashTest extends TestCase {
21
-	/** @var IAppConfig&MockObject */
22
-	private $appConfig;
23
-
24
-	/** @var IUserManager&MockObject */
25
-	private $userManager;
26
-
27
-	/** @var Expiration&MockObject */
28
-	private $expiration;
29
-
30
-	/** @var IJobList&MockObject */
31
-	private $jobList;
32
-
33
-	/** @var LoggerInterface&MockObject */
34
-	private $logger;
35
-
36
-	/** @var ITimeFactory&MockObject */
37
-	private $time;
38
-
39
-	protected function setUp(): void {
40
-		parent::setUp();
41
-
42
-		$this->appConfig = $this->createMock(IAppConfig::class);
43
-		$this->userManager = $this->createMock(IUserManager::class);
44
-		$this->expiration = $this->createMock(Expiration::class);
45
-		$this->jobList = $this->createMock(IJobList::class);
46
-		$this->logger = $this->createMock(LoggerInterface::class);
47
-
48
-		$this->time = $this->createMock(ITimeFactory::class);
49
-		$this->time->method('getTime')
50
-			->willReturn(999999999);
51
-
52
-		$this->jobList->expects($this->once())
53
-			->method('setLastRun');
54
-		$this->jobList->expects($this->once())
55
-			->method('setExecutionTime');
56
-	}
57
-
58
-	public function testConstructAndRun(): void {
59
-		$this->appConfig->method('getValueString')
60
-			->with('files_trashbin', 'background_job_expire_trash', 'yes')
61
-			->willReturn('yes');
62
-		$this->appConfig->method('getValueInt')
63
-			->with('files_trashbin', 'background_job_expire_trash_offset', 0)
64
-			->willReturn(0);
65
-
66
-		$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
67
-		$job->start($this->jobList);
68
-	}
69
-
70
-	public function testBackgroundJobDeactivated(): void {
71
-		$this->appConfig->method('getValueString')
72
-			->with('files_trashbin', 'background_job_expire_trash', 'yes')
73
-			->willReturn('no');
74
-		$this->expiration->expects($this->never())
75
-			->method('getMaxAgeAsTimestamp');
76
-
77
-		$job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
78
-		$job->start($this->jobList);
79
-	}
21
+    /** @var IAppConfig&MockObject */
22
+    private $appConfig;
23
+
24
+    /** @var IUserManager&MockObject */
25
+    private $userManager;
26
+
27
+    /** @var Expiration&MockObject */
28
+    private $expiration;
29
+
30
+    /** @var IJobList&MockObject */
31
+    private $jobList;
32
+
33
+    /** @var LoggerInterface&MockObject */
34
+    private $logger;
35
+
36
+    /** @var ITimeFactory&MockObject */
37
+    private $time;
38
+
39
+    protected function setUp(): void {
40
+        parent::setUp();
41
+
42
+        $this->appConfig = $this->createMock(IAppConfig::class);
43
+        $this->userManager = $this->createMock(IUserManager::class);
44
+        $this->expiration = $this->createMock(Expiration::class);
45
+        $this->jobList = $this->createMock(IJobList::class);
46
+        $this->logger = $this->createMock(LoggerInterface::class);
47
+
48
+        $this->time = $this->createMock(ITimeFactory::class);
49
+        $this->time->method('getTime')
50
+            ->willReturn(999999999);
51
+
52
+        $this->jobList->expects($this->once())
53
+            ->method('setLastRun');
54
+        $this->jobList->expects($this->once())
55
+            ->method('setExecutionTime');
56
+    }
57
+
58
+    public function testConstructAndRun(): void {
59
+        $this->appConfig->method('getValueString')
60
+            ->with('files_trashbin', 'background_job_expire_trash', 'yes')
61
+            ->willReturn('yes');
62
+        $this->appConfig->method('getValueInt')
63
+            ->with('files_trashbin', 'background_job_expire_trash_offset', 0)
64
+            ->willReturn(0);
65
+
66
+        $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
67
+        $job->start($this->jobList);
68
+    }
69
+
70
+    public function testBackgroundJobDeactivated(): void {
71
+        $this->appConfig->method('getValueString')
72
+            ->with('files_trashbin', 'background_job_expire_trash', 'yes')
73
+            ->willReturn('no');
74
+        $this->expiration->expects($this->never())
75
+            ->method('getMaxAgeAsTimestamp');
76
+
77
+        $job = new ExpireTrash($this->appConfig, $this->userManager, $this->expiration, $this->logger, $this->time);
78
+        $job->start($this->jobList);
79
+    }
80 80
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -17,71 +17,71 @@
 block discarded – undo
17 17
 use Psr\Log\LoggerInterface;
18 18
 
19 19
 class ExpireTrash extends TimedJob {
20
-	public function __construct(
21
-		private IAppConfig $appConfig,
22
-		private IUserManager $userManager,
23
-		private Expiration $expiration,
24
-		private LoggerInterface $logger,
25
-		ITimeFactory $time,
26
-	) {
27
-		parent::__construct($time);
28
-		// Run once per 30 minutes
29
-		$this->setInterval(60 * 30);
30
-	}
20
+    public function __construct(
21
+        private IAppConfig $appConfig,
22
+        private IUserManager $userManager,
23
+        private Expiration $expiration,
24
+        private LoggerInterface $logger,
25
+        ITimeFactory $time,
26
+    ) {
27
+        parent::__construct($time);
28
+        // Run once per 30 minutes
29
+        $this->setInterval(60 * 30);
30
+    }
31 31
 
32
-	protected function run($argument) {
33
-		$backgroundJob = $this->appConfig->getValueString('files_trashbin', 'background_job_expire_trash', 'yes');
34
-		if ($backgroundJob === 'no') {
35
-			return;
36
-		}
32
+    protected function run($argument) {
33
+        $backgroundJob = $this->appConfig->getValueString('files_trashbin', 'background_job_expire_trash', 'yes');
34
+        if ($backgroundJob === 'no') {
35
+            return;
36
+        }
37 37
 
38
-		$maxAge = $this->expiration->getMaxAgeAsTimestamp();
39
-		if (!$maxAge) {
40
-			return;
41
-		}
38
+        $maxAge = $this->expiration->getMaxAgeAsTimestamp();
39
+        if (!$maxAge) {
40
+            return;
41
+        }
42 42
 
43
-		$stopTime = time() + 60 * 30; // Stops after 30 minutes.
44
-		$offset = $this->appConfig->getValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
45
-		$users = $this->userManager->getSeenUsers($offset);
43
+        $stopTime = time() + 60 * 30; // Stops after 30 minutes.
44
+        $offset = $this->appConfig->getValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
45
+        $users = $this->userManager->getSeenUsers($offset);
46 46
 
47
-		foreach ($users as $user) {
48
-			try {
49
-				$uid = $user->getUID();
50
-				if (!$this->setupFS($uid)) {
51
-					continue;
52
-				}
53
-				$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
54
-				Trashbin::deleteExpiredFiles($dirContent, $uid);
55
-			} catch (\Throwable $e) {
56
-				$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
57
-			}
47
+        foreach ($users as $user) {
48
+            try {
49
+                $uid = $user->getUID();
50
+                if (!$this->setupFS($uid)) {
51
+                    continue;
52
+                }
53
+                $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
54
+                Trashbin::deleteExpiredFiles($dirContent, $uid);
55
+            } catch (\Throwable $e) {
56
+                $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
57
+            }
58 58
 
59
-			$offset++;
59
+            $offset++;
60 60
 
61
-			if ($stopTime < time()) {
62
-				$this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', $offset);
63
-				\OC_Util::tearDownFS();
64
-				return;
65
-			}
66
-		}
61
+            if ($stopTime < time()) {
62
+                $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', $offset);
63
+                \OC_Util::tearDownFS();
64
+                return;
65
+            }
66
+        }
67 67
 
68
-		$this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
69
-		\OC_Util::tearDownFS();
70
-	}
68
+        $this->appConfig->setValueInt('files_trashbin', 'background_job_expire_trash_offset', 0);
69
+        \OC_Util::tearDownFS();
70
+    }
71 71
 
72
-	/**
73
-	 * Act on behalf on trash item owner
74
-	 */
75
-	protected function setupFS(string $user): bool {
76
-		\OC_Util::tearDownFS();
77
-		\OC_Util::setupFS($user);
72
+    /**
73
+     * Act on behalf on trash item owner
74
+     */
75
+    protected function setupFS(string $user): bool {
76
+        \OC_Util::tearDownFS();
77
+        \OC_Util::setupFS($user);
78 78
 
79
-		// Check if this user has a trashbin directory
80
-		$view = new View('/' . $user);
81
-		if (!$view->is_dir('/files_trashbin/files')) {
82
-			return false;
83
-		}
79
+        // Check if this user has a trashbin directory
80
+        $view = new View('/' . $user);
81
+        if (!$view->is_dir('/files_trashbin/files')) {
82
+            return false;
83
+        }
84 84
 
85
-		return true;
86
-	}
85
+        return true;
86
+    }
87 87
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 				$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
54 54
 				Trashbin::deleteExpiredFiles($dirContent, $uid);
55 55
 			} catch (\Throwable $e) {
56
-				$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
56
+				$this->logger->error('Error while expiring trashbin for user '.$user->getUID(), ['exception' => $e]);
57 57
 			}
58 58
 
59 59
 			$offset++;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 		\OC_Util::setupFS($user);
78 78
 
79 79
 		// Check if this user has a trashbin directory
80
-		$view = new View('/' . $user);
80
+		$view = new View('/'.$user);
81 81
 		if (!$view->is_dir('/files_trashbin/files')) {
82 82
 			return false;
83 83
 		}
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Command/ExpireTrash.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -21,91 +21,91 @@
 block discarded – undo
21 21
 
22 22
 class ExpireTrash extends Command {
23 23
 
24
-	/**
25
-	 * @param IUserManager|null $userManager
26
-	 * @param Expiration|null $expiration
27
-	 */
28
-	public function __construct(
29
-		private LoggerInterface $logger,
30
-		private ?IUserManager $userManager = null,
31
-		private ?Expiration $expiration = null,
32
-	) {
33
-		parent::__construct();
34
-	}
24
+    /**
25
+     * @param IUserManager|null $userManager
26
+     * @param Expiration|null $expiration
27
+     */
28
+    public function __construct(
29
+        private LoggerInterface $logger,
30
+        private ?IUserManager $userManager = null,
31
+        private ?Expiration $expiration = null,
32
+    ) {
33
+        parent::__construct();
34
+    }
35 35
 
36
-	protected function configure() {
37
-		$this
38
-			->setName('trashbin:expire')
39
-			->setDescription('Expires the users trashbin')
40
-			->addArgument(
41
-				'user_id',
42
-				InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
43
-				'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired'
44
-			);
45
-	}
36
+    protected function configure() {
37
+        $this
38
+            ->setName('trashbin:expire')
39
+            ->setDescription('Expires the users trashbin')
40
+            ->addArgument(
41
+                'user_id',
42
+                InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
43
+                'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired'
44
+            );
45
+    }
46 46
 
47
-	protected function execute(InputInterface $input, OutputInterface $output): int {
48
-		$maxAge = $this->expiration->getMaxAgeAsTimestamp();
49
-		if (!$maxAge) {
50
-			$output->writeln('Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)');
51
-			return 1;
52
-		}
47
+    protected function execute(InputInterface $input, OutputInterface $output): int {
48
+        $maxAge = $this->expiration->getMaxAgeAsTimestamp();
49
+        if (!$maxAge) {
50
+            $output->writeln('Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)');
51
+            return 1;
52
+        }
53 53
 
54
-		$users = $input->getArgument('user_id');
55
-		if (!empty($users)) {
56
-			foreach ($users as $user) {
57
-				if ($this->userManager->userExists($user)) {
58
-					$output->writeln("Remove deleted files of   <info>$user</info>");
59
-					$userObject = $this->userManager->get($user);
60
-					$this->expireTrashForUser($userObject);
61
-				} else {
62
-					$output->writeln("<error>Unknown user $user</error>");
63
-					return 1;
64
-				}
65
-			}
66
-		} else {
67
-			$p = new ProgressBar($output);
68
-			$p->start();
54
+        $users = $input->getArgument('user_id');
55
+        if (!empty($users)) {
56
+            foreach ($users as $user) {
57
+                if ($this->userManager->userExists($user)) {
58
+                    $output->writeln("Remove deleted files of   <info>$user</info>");
59
+                    $userObject = $this->userManager->get($user);
60
+                    $this->expireTrashForUser($userObject);
61
+                } else {
62
+                    $output->writeln("<error>Unknown user $user</error>");
63
+                    return 1;
64
+                }
65
+            }
66
+        } else {
67
+            $p = new ProgressBar($output);
68
+            $p->start();
69 69
 
70
-			$users = $this->userManager->getSeenUsers();
71
-			foreach ($users as $user) {
72
-				$p->advance();
73
-				$this->expireTrashForUser($user);
74
-			}
75
-			$p->finish();
76
-			$output->writeln('');
77
-		}
78
-		return 0;
79
-	}
70
+            $users = $this->userManager->getSeenUsers();
71
+            foreach ($users as $user) {
72
+                $p->advance();
73
+                $this->expireTrashForUser($user);
74
+            }
75
+            $p->finish();
76
+            $output->writeln('');
77
+        }
78
+        return 0;
79
+    }
80 80
 
81
-	public function expireTrashForUser(IUser $user) {
82
-		try {
83
-			$uid = $user->getUID();
84
-			if (!$this->setupFS($uid)) {
85
-				return;
86
-			}
87
-			$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
88
-			Trashbin::deleteExpiredFiles($dirContent, $uid);
89
-		} catch (\Throwable $e) {
90
-			$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
91
-		}
92
-	}
81
+    public function expireTrashForUser(IUser $user) {
82
+        try {
83
+            $uid = $user->getUID();
84
+            if (!$this->setupFS($uid)) {
85
+                return;
86
+            }
87
+            $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
88
+            Trashbin::deleteExpiredFiles($dirContent, $uid);
89
+        } catch (\Throwable $e) {
90
+            $this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
91
+        }
92
+    }
93 93
 
94
-	/**
95
-	 * Act on behalf on trash item owner
96
-	 * @param string $user
97
-	 * @return boolean
98
-	 */
99
-	protected function setupFS($user) {
100
-		\OC_Util::tearDownFS();
101
-		\OC_Util::setupFS($user);
94
+    /**
95
+     * Act on behalf on trash item owner
96
+     * @param string $user
97
+     * @return boolean
98
+     */
99
+    protected function setupFS($user) {
100
+        \OC_Util::tearDownFS();
101
+        \OC_Util::setupFS($user);
102 102
 
103
-		// Check if this user has a trashbin directory
104
-		$view = new View('/' . $user);
105
-		if (!$view->is_dir('/files_trashbin/files')) {
106
-			return false;
107
-		}
103
+        // Check if this user has a trashbin directory
104
+        $view = new View('/' . $user);
105
+        if (!$view->is_dir('/files_trashbin/files')) {
106
+            return false;
107
+        }
108 108
 
109
-		return true;
110
-	}
109
+        return true;
110
+    }
111 111
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
88 88
 			Trashbin::deleteExpiredFiles($dirContent, $uid);
89 89
 		} catch (\Throwable $e) {
90
-			$this->logger->error('Error while expiring trashbin for user ' . $user->getUID(), ['exception' => $e]);
90
+			$this->logger->error('Error while expiring trashbin for user '.$user->getUID(), ['exception' => $e]);
91 91
 		}
92 92
 	}
93 93
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		\OC_Util::setupFS($user);
102 102
 
103 103
 		// Check if this user has a trashbin directory
104
-		$view = new View('/' . $user);
104
+		$view = new View('/'.$user);
105 105
 		if (!$view->is_dir('/files_trashbin/files')) {
106 106
 			return false;
107 107
 		}
Please login to merge, or discard this patch.