Passed
Push — master ( ebedbf...47a21f )
by Joas
12:46 queued 18s
created
apps/files_trashbin/lib/Command/CleanUp.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -39,98 +39,98 @@
 block discarded – undo
39 39
 
40 40
 class CleanUp extends Command {
41 41
 
42
-	/** @var IUserManager */
43
-	protected $userManager;
42
+    /** @var IUserManager */
43
+    protected $userManager;
44 44
 
45
-	/** @var IRootFolder */
46
-	protected $rootFolder;
45
+    /** @var IRootFolder */
46
+    protected $rootFolder;
47 47
 
48
-	/** @var \OCP\IDBConnection */
49
-	protected $dbConnection;
48
+    /** @var \OCP\IDBConnection */
49
+    protected $dbConnection;
50 50
 
51
-	/**
52
-	 * @param IRootFolder $rootFolder
53
-	 * @param IUserManager $userManager
54
-	 * @param IDBConnection $dbConnection
55
-	 */
56
-	public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) {
57
-		parent::__construct();
58
-		$this->userManager = $userManager;
59
-		$this->rootFolder = $rootFolder;
60
-		$this->dbConnection = $dbConnection;
61
-	}
51
+    /**
52
+     * @param IRootFolder $rootFolder
53
+     * @param IUserManager $userManager
54
+     * @param IDBConnection $dbConnection
55
+     */
56
+    public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) {
57
+        parent::__construct();
58
+        $this->userManager = $userManager;
59
+        $this->rootFolder = $rootFolder;
60
+        $this->dbConnection = $dbConnection;
61
+    }
62 62
 
63
-	protected function configure() {
64
-		$this
65
-			->setName('trashbin:cleanup')
66
-			->setDescription('Remove deleted files')
67
-			->addArgument(
68
-				'user_id',
69
-				InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
70
-				'remove deleted files of the given user(s)'
71
-			)
72
-			->addOption(
73
-				'all-users',
74
-				null,
75
-				InputOption::VALUE_NONE,
76
-				'run action on all users'
77
-			);
78
-	}
63
+    protected function configure() {
64
+        $this
65
+            ->setName('trashbin:cleanup')
66
+            ->setDescription('Remove deleted files')
67
+            ->addArgument(
68
+                'user_id',
69
+                InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
70
+                'remove deleted files of the given user(s)'
71
+            )
72
+            ->addOption(
73
+                'all-users',
74
+                null,
75
+                InputOption::VALUE_NONE,
76
+                'run action on all users'
77
+            );
78
+    }
79 79
 
80
-	protected function execute(InputInterface $input, OutputInterface $output): int {
81
-		$users = $input->getArgument('user_id');
82
-		if ((!empty($users)) and ($input->getOption('all-users'))) {
83
-			throw new InvalidOptionException('Either specify a user_id or --all-users');
84
-		} elseif (!empty($users)) {
85
-			foreach ($users as $user) {
86
-				if ($this->userManager->userExists($user)) {
87
-					$output->writeln("Remove deleted files of   <info>$user</info>");
88
-					$this->removeDeletedFiles($user);
89
-				} else {
90
-					$output->writeln("<error>Unknown user $user</error>");
91
-					return 1;
92
-				}
93
-			}
94
-		} elseif ($input->getOption('all-users')) {
95
-			$output->writeln('Remove deleted files for all users');
96
-			foreach ($this->userManager->getBackends() as $backend) {
97
-				$name = get_class($backend);
98
-				if ($backend instanceof IUserBackend) {
99
-					$name = $backend->getBackendName();
100
-				}
101
-				$output->writeln("Remove deleted files for users on backend <info>$name</info>");
102
-				$limit = 500;
103
-				$offset = 0;
104
-				do {
105
-					$users = $backend->getUsers('', $limit, $offset);
106
-					foreach ($users as $user) {
107
-						$output->writeln("   <info>$user</info>");
108
-						$this->removeDeletedFiles($user);
109
-					}
110
-					$offset += $limit;
111
-				} while (count($users) >= $limit);
112
-			}
113
-		} else {
114
-			throw new InvalidOptionException('Either specify a user_id or --all-users');
115
-		}
116
-		return 0;
117
-	}
80
+    protected function execute(InputInterface $input, OutputInterface $output): int {
81
+        $users = $input->getArgument('user_id');
82
+        if ((!empty($users)) and ($input->getOption('all-users'))) {
83
+            throw new InvalidOptionException('Either specify a user_id or --all-users');
84
+        } elseif (!empty($users)) {
85
+            foreach ($users as $user) {
86
+                if ($this->userManager->userExists($user)) {
87
+                    $output->writeln("Remove deleted files of   <info>$user</info>");
88
+                    $this->removeDeletedFiles($user);
89
+                } else {
90
+                    $output->writeln("<error>Unknown user $user</error>");
91
+                    return 1;
92
+                }
93
+            }
94
+        } elseif ($input->getOption('all-users')) {
95
+            $output->writeln('Remove deleted files for all users');
96
+            foreach ($this->userManager->getBackends() as $backend) {
97
+                $name = get_class($backend);
98
+                if ($backend instanceof IUserBackend) {
99
+                    $name = $backend->getBackendName();
100
+                }
101
+                $output->writeln("Remove deleted files for users on backend <info>$name</info>");
102
+                $limit = 500;
103
+                $offset = 0;
104
+                do {
105
+                    $users = $backend->getUsers('', $limit, $offset);
106
+                    foreach ($users as $user) {
107
+                        $output->writeln("   <info>$user</info>");
108
+                        $this->removeDeletedFiles($user);
109
+                    }
110
+                    $offset += $limit;
111
+                } while (count($users) >= $limit);
112
+            }
113
+        } else {
114
+            throw new InvalidOptionException('Either specify a user_id or --all-users');
115
+        }
116
+        return 0;
117
+    }
118 118
 
119
-	/**
120
-	 * remove deleted files for the given user
121
-	 *
122
-	 * @param string $uid
123
-	 */
124
-	protected function removeDeletedFiles($uid) {
125
-		\OC_Util::tearDownFS();
126
-		\OC_Util::setupFS($uid);
127
-		if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) {
128
-			$this->rootFolder->get('/' . $uid . '/files_trashbin')->delete();
129
-			$query = $this->dbConnection->getQueryBuilder();
130
-			$query->delete('files_trash')
131
-				->where($query->expr()->eq('user', $query->createParameter('uid')))
132
-				->setParameter('uid', $uid);
133
-			$query->execute();
134
-		}
135
-	}
119
+    /**
120
+     * remove deleted files for the given user
121
+     *
122
+     * @param string $uid
123
+     */
124
+    protected function removeDeletedFiles($uid) {
125
+        \OC_Util::tearDownFS();
126
+        \OC_Util::setupFS($uid);
127
+        if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) {
128
+            $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete();
129
+            $query = $this->dbConnection->getQueryBuilder();
130
+            $query->delete('files_trash')
131
+                ->where($query->expr()->eq('user', $query->createParameter('uid')))
132
+                ->setParameter('uid', $uid);
133
+            $query->execute();
134
+        }
135
+    }
136 136
 }
Please login to merge, or discard this patch.