migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,148 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Björn Schießle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Liam Dennehy <liam@wiemax.net>
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_Trashbin\Command;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IUserBackend;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CleanUp extends Command {
/** @var IUserManager */
protected $userManager;
/** @var IRootFolder */
protected $rootFolder;
/** @var \OCP\IDBConnection */
protected $dbConnection;
/**
* @param IRootFolder $rootFolder
* @param IUserManager $userManager
* @param IDBConnection $dbConnection
*/
public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection) {
parent::__construct();
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->dbConnection = $dbConnection;
}
protected function configure() {
$this
->setName('trashbin:cleanup')
->setDescription('Remove deleted files')
->addArgument(
'user_id',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'remove deleted files of the given user(s)'
)
->addOption(
'all-users',
null,
InputOption::VALUE_NONE,
'run action on all users'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$users = $input->getArgument('user_id');
$verbose = $input->getOption('verbose');
if ((!empty($users)) and ($input->getOption('all-users'))) {
throw new InvalidOptionException('Either specify a user_id or --all-users');
} elseif (!empty($users)) {
foreach ($users as $user) {
if ($this->userManager->userExists($user)) {
$output->writeln("Remove deleted files of <info>$user</info>");
$this->removeDeletedFiles($user, $output, $verbose);
} else {
$output->writeln("<error>Unknown user $user</error>");
return 1;
}
}
} elseif ($input->getOption('all-users')) {
$output->writeln('Remove deleted files for all users');
foreach ($this->userManager->getBackends() as $backend) {
$name = get_class($backend);
if ($backend instanceof IUserBackend) {
$name = $backend->getBackendName();
}
$output->writeln("Remove deleted files for users on backend <info>$name</info>");
$limit = 500;
$offset = 0;
do {
$users = $backend->getUsers('', $limit, $offset);
foreach ($users as $user) {
$output->writeln(" <info>$user</info>");
$this->removeDeletedFiles($user, $output, $verbose);
}
$offset += $limit;
} while (count($users) >= $limit);
}
} else {
throw new InvalidOptionException('Either specify a user_id or --all-users');
}
return 0;
}
/**
* remove deleted files for the given user
*/
protected function removeDeletedFiles(string $uid, OutputInterface $output, bool $verbose): void {
\OC_Util::tearDownFS();
\OC_Util::setupFS($uid);
$path = '/' . $uid . '/files_trashbin';
if ($this->rootFolder->nodeExists($path)) {
$node = $this->rootFolder->get($path);
if ($verbose) {
$output->writeln("Deleting <info>" . \OC_Helper::humanFileSize($node->getSize()) . "</info> in trash for <info>$uid</info>.");
}
$node->delete();
if ($this->rootFolder->nodeExists($path)) {
$output->writeln("<error>Trash folder sill exists after attempting to delete it</error>");
return;
}
$query = $this->dbConnection->getQueryBuilder();
$query->delete('files_trash')
->where($query->expr()->eq('user', $query->createParameter('uid')))
->setParameter('uid', $uid);
$query->execute();
} else {
if ($verbose) {
$output->writeln("No trash found for <info>$uid</info>");
}
}
}
}
@@ -0,0 +1,60 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
*
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_Trashbin\Command;
use OC\Command\FileAccess;
use OCA\Files_Trashbin\Trashbin;
use OCP\Command\ICommand;
class Expire implements ICommand {
use FileAccess;
/**
* @var string
*/
private $user;
/**
* @param string $user
*/
public function __construct($user) {
$this->user = $user;
}
public function handle() {
$userManager = \OC::$server->getUserManager();
if (!$userManager->userExists($this->user)) {
// User has been deleted already
return;
}
\OC_Util::tearDownFS();
\OC_Util::setupFS($this->user);
Trashbin::expire($this->user);
\OC_Util::tearDownFS();
}
}
@@ -0,0 +1,132 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud GmbH.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_Trashbin\Command;
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExpireTrash extends Command {
/**
* @var Expiration
*/
private $expiration;
/**
* @var IUserManager
*/
private $userManager;
/**
* @param IUserManager|null $userManager
* @param Expiration|null $expiration
*/
public function __construct(IUserManager $userManager = null,
Expiration $expiration = null) {
parent::__construct();
$this->userManager = $userManager;
$this->expiration = $expiration;
}
protected function configure() {
$this
->setName('trashbin:expire')
->setDescription('Expires the users trashbin')
->addArgument(
'user_id',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$maxAge = $this->expiration->getMaxAgeAsTimestamp();
if (!$maxAge) {
$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)");
return 1;
}
$users = $input->getArgument('user_id');
if (!empty($users)) {
foreach ($users as $user) {
if ($this->userManager->userExists($user)) {
$output->writeln("Remove deleted files of <info>$user</info>");
$userObject = $this->userManager->get($user);
$this->expireTrashForUser($userObject);
} else {
$output->writeln("<error>Unknown user $user</error>");
return 1;
}
}
} else {
$p = new ProgressBar($output);
$p->start();
$this->userManager->callForSeenUsers(function (IUser $user) use ($p) {
$p->advance();
$this->expireTrashForUser($user);
});
$p->finish();
$output->writeln('');
}
return 0;
}
public function expireTrashForUser(IUser $user) {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
return;
}
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
Trashbin::deleteExpiredFiles($dirContent, $uid);
}
/**
* Act on behalf on trash item owner
* @param string $user
* @return boolean
*/
protected function setupFS($user) {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);
// Check if this user has a trashbin directory
$view = new \OC\Files\View('/' . $user);
if (!$view->is_dir('/files_trashbin/files')) {
return false;
}
return true;
}
}
@@ -0,0 +1,293 @@
<?php
/**
* @copyright Copyright (c) 2021, Caitlin Hogan (cahogan16@gmail.com)
* @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,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_Trashbin\Command;
use OC\Core\Command\Base;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class RestoreAllFiles extends Base {
private const SCOPE_ALL = 0;
private const SCOPE_USER = 1;
private const SCOPE_GROUPFOLDERS = 2;
private static array $SCOPE_MAP = [
'user' => self::SCOPE_USER,
'groupfolders' => self::SCOPE_GROUPFOLDERS,
'all' => self::SCOPE_ALL
];
/** @var IUserManager */
protected $userManager;
/** @var IRootFolder */
protected $rootFolder;
/** @var \OCP\IDBConnection */
protected $dbConnection;
protected ITrashManager $trashManager;
/** @var IL10N */
protected $l10n;
/**
* @param IRootFolder $rootFolder
* @param IUserManager $userManager
* @param IDBConnection $dbConnection
* @param ITrashManager $trashManager
* @param IFactory $l10nFactory
*/
public function __construct(IRootFolder $rootFolder, IUserManager $userManager, IDBConnection $dbConnection, ITrashManager $trashManager, IFactory $l10nFactory) {
parent::__construct();
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->dbConnection = $dbConnection;
$this->trashManager = $trashManager;
$this->l10n = $l10nFactory->get('files_trashbin');
}
protected function configure(): void {
parent::configure();
$this
->setName('trashbin:restore')
->setDescription('Restore all deleted files according to the given filters')
->addArgument(
'user_id',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'restore all deleted files of the given user(s)'
)
->addOption(
'all-users',
null,
InputOption::VALUE_NONE,
'run action on all users'
)
->addOption(
'scope',
's',
InputOption::VALUE_OPTIONAL,
'Restore files from the given scope. Possible values are "user", "groupfolders" or "all"',
'user'
)
->addOption(
'since',
null,
InputOption::VALUE_OPTIONAL,
'Only restore files deleted after the given timestamp'
)
->addOption(
'until',
null,
InputOption::VALUE_OPTIONAL,
'Only restore files deleted before the given timestamp'
)
->addOption(
'dry-run',
'd',
InputOption::VALUE_NONE,
'Only show which files would be restored but do not perform any action'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
/** @var string[] $users */
$users = $input->getArgument('user_id');
if ((!empty($users)) && ($input->getOption('all-users'))) {
throw new InvalidOptionException('Either specify a user_id or --all-users');
}
[$scope, $since, $until, $dryRun] = $this->parseArgs($input);
if (!empty($users)) {
foreach ($users as $user) {
$output->writeln("Restoring deleted files for user <info>$user</info>");
$this->restoreDeletedFiles($user, $scope, $since, $until, $dryRun, $output);
}
} elseif ($input->getOption('all-users')) {
$output->writeln('Restoring deleted files for all users');
foreach ($this->userManager->getBackends() as $backend) {
$name = get_class($backend);
if ($backend instanceof IUserBackend) {
$name = $backend->getBackendName();
}
$output->writeln("Restoring deleted files for users on backend <info>$name</info>");
$limit = 500;
$offset = 0;
do {
$users = $backend->getUsers('', $limit, $offset);
foreach ($users as $user) {
$output->writeln("<info>$user</info>");
$this->restoreDeletedFiles($user, $scope, $since, $until, $dryRun, $output);
}
$offset += $limit;
} while (count($users) >= $limit);
}
} else {
throw new InvalidOptionException('Either specify a user_id or --all-users');
}
return 0;
}
/**
* Restore deleted files for the given user according to the given filters
*/
protected function restoreDeletedFiles(string $uid, int $scope, ?int $since, ?int $until, bool $dryRun, OutputInterface $output): void {
\OC_Util::tearDownFS();
\OC_Util::setupFS($uid);
\OC_User::setUserId($uid);
$user = $this->userManager->get($uid);
if ($user === null) {
$output->writeln("<error>Unknown user $uid</error>");
return;
}
$userTrashItems = $this->filterTrashItems(
$this->trashManager->listTrashRoot($user),
$scope,
$since,
$until,
$output);
$trashCount = count($userTrashItems);
if ($trashCount == 0) {
$output->writeln("User has no deleted files in the trashbin matching the given filters");
return;
}
$prepMsg = $dryRun ? 'Would restore' : 'Preparing to restore';
$output->writeln("$prepMsg <info>$trashCount</info> files...");
$count = 0;
foreach($userTrashItems as $trashItem) {
$filename = $trashItem->getName();
$humanTime = $this->l10n->l('datetime', $trashItem->getDeletedTime());
// We use getTitle() here instead of getOriginalLocation() because
// for groupfolders this contains the groupfolder name itself as prefix
// which makes it more human readable
$location = $trashItem->getTitle();
if ($dryRun) {
$output->writeln("Would restore <info>$filename</info> originally deleted at <info>$humanTime</info> to <info>/$location</info>");
continue;
}
$output->write("File <info>$filename</info> originally deleted at <info>$humanTime</info> restoring to <info>/$location</info>:");
try {
$trashItem->getTrashBackend()->restoreItem($trashItem);
} catch (\Throwable $e) {
$output->writeln(" <error>Failed: " . $e->getMessage() . "</error>");
$output->writeln(" <error>" . $e->getTraceAsString() . "</error>", OutputInterface::VERBOSITY_VERY_VERBOSE);
continue;
}
$count++;
$output->writeln(" <info>success</info>");
}
if (!$dryRun) {
$output->writeln("Successfully restored <info>$count</info> out of <info>$trashCount</info> files.");
}
}
protected function parseArgs(InputInterface $input): array {
$since = $this->parseTimestamp($input->getOption('since'));
$until = $this->parseTimestamp($input->getOption('until'));
if ($since !== null && $until !== null && $since > $until) {
throw new InvalidOptionException('since must be before until');
}
return [
$this->parseScope($input->getOption('scope')),
$since,
$until,
$input->getOption('dry-run')
];
}
protected function parseScope(string $scope): int {
if (isset(self::$SCOPE_MAP[$scope])) {
return self::$SCOPE_MAP[$scope];
}
throw new InvalidOptionException("Invalid scope '$scope'");
}
protected function parseTimestamp(?string $timestamp): ?int {
if ($timestamp === null) {
return null;
}
$timestamp = strtotime($timestamp);
if ($timestamp === false) {
throw new InvalidOptionException("Invalid timestamp '$timestamp'");
}
return $timestamp;
}
protected function filterTrashItems(array $trashItems, int $scope, ?int $since, ?int $until, OutputInterface $output): array {
$filteredTrashItems = [];
foreach ($trashItems as $trashItem) {
$trashItemClass = get_class($trashItem);
// Check scope with exact class name for locally deleted files
if ($scope === self::SCOPE_USER && $trashItemClass !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a user trash item", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
/**
* Check scope for groupfolders by string because the groupfolders app might not be installed.
* That's why PSALM doesn't know the class GroupTrashItem.
* @psalm-suppress RedundantCondition
*/
if ($scope === self::SCOPE_GROUPFOLDERS && $trashItemClass !== 'OCA\GroupFolders\Trash\GroupTrashItem') {
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it is not a groupfolders trash item", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
// Check left timestamp boundary
if ($since !== null && $trashItem->getDeletedTime() <= $since) {
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted before the 'since' timestamp", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
// Check right timestamp boundary
if ($until !== null && $trashItem->getDeletedTime() >= $until) {
$output->writeln("Skipping <info>" . $trashItem->getName() . "</info> because it was deleted after the 'until' timestamp", OutputInterface::VERBOSITY_VERBOSE);
continue;
}
$filteredTrashItems[] = $trashItem;
}
return $filteredTrashItems;
}
}
@@ -0,0 +1,148 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
*
* @author Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Files_Trashbin\Command;
use OC\Core\Command\Base;
use OCP\Command\IBus;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Size extends Base {
private $config;
private $userManager;
private $commandBus;
public function __construct(
IConfig $config,
IUserManager $userManager,
IBus $commandBus
) {
parent::__construct();
$this->config = $config;
$this->userManager = $userManager;
$this->commandBus = $commandBus;
}
protected function configure() {
parent::configure();
$this
->setName('trashbin:size')
->setDescription('Configure the target trashbin size')
->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'configure the target size for the provided user, if no user is given the default size is configured')
->addArgument(
'size',
InputArgument::OPTIONAL,
'the target size for the trashbin, if not provided the current trashbin size will be returned'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$user = $input->getOption('user');
$size = $input->getArgument('size');
if ($size) {
$parsedSize = \OC_Helper::computerFileSize($size);
if ($parsedSize === false) {
$output->writeln("<error>Failed to parse input size</error>");
return -1;
}
if ($user) {
$this->config->setUserValue($user, 'files_trashbin', 'trashbin_size', (string)$parsedSize);
$this->commandBus->push(new Expire($user));
} else {
$this->config->setAppValue('files_trashbin', 'trashbin_size', (string)$parsedSize);
$output->writeln("<info>Warning: changing the default trashbin size will automatically trigger cleanup of existing trashbins,</info>");
$output->writeln("<info>a users trashbin can exceed the configured size until they move a new file to the trashbin.</info>");
}
} else {
$this->printTrashbinSize($input, $output, $user);
}
return 0;
}
private function printTrashbinSize(InputInterface $input, OutputInterface $output, ?string $user) {
$globalSize = (int)$this->config->getAppValue('files_trashbin', 'trashbin_size', '-1');
if ($globalSize < 0) {
$globalHumanSize = "default (50% of available space)";
} else {
$globalHumanSize = \OC_Helper::humanFileSize($globalSize);
}
if ($user) {
$userSize = (int)$this->config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
if ($userSize < 0) {
$userHumanSize = ($globalSize < 0) ? $globalHumanSize : "default($globalHumanSize)";
} else {
$userHumanSize = \OC_Helper::humanFileSize($userSize);
}
if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) {
$output->writeln($userHumanSize);
} else {
$userValue = ($userSize < 0) ? 'default' : $userSize;
$globalValue = ($globalSize < 0) ? 'default' : $globalSize;
$this->writeArrayInOutputFormat($input, $output, [
'user_size' => $userValue,
'global_size' => $globalValue,
'effective_size' => ($userSize < 0) ? $globalValue : $userValue,
]);
}
} else {
$users = [];
$this->userManager->callForSeenUsers(function (IUser $user) use (&$users) {
$users[] = $user->getUID();
});
$userValues = $this->config->getUserValueForUsers('files_trashbin', 'trashbin_size', $users);
if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) {
$output->writeln("Default size: $globalHumanSize");
$output->writeln("");
if (count($userValues)) {
$output->writeln("Per-user sizes:");
$this->writeArrayInOutputFormat($input, $output, array_map(function ($size) {
return \OC_Helper::humanFileSize($size);
}, $userValues));
} else {
$output->writeln("No per-user sizes configured");
}
} else {
$globalValue = ($globalSize < 0) ? 'default' : $globalSize;
$this->writeArrayInOutputFormat($input, $output, [
'global_size' => $globalValue,
'user_sizes' => $userValues,
]);
}
}
}
}