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,196 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud GmbH.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @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_Sharing\Command;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Federation\ICloudIdManager;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Cleanup 'shared::' storage entries that have no matching entries in the
* shares_external table.
*/
class CleanupRemoteStorages extends Command {
/**
* @var IDBConnection
*/
protected $connection;
/**
* @var ICloudIdManager
*/
private $cloudIdManager;
public function __construct(IDBConnection $connection, ICloudIdManager $cloudIdManager) {
$this->connection = $connection;
$this->cloudIdManager = $cloudIdManager;
parent::__construct();
}
protected function configure() {
$this
->setName('sharing:cleanup-remote-storages')
->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table')
->addOption(
'dry-run',
null,
InputOption::VALUE_NONE,
'only show which storages would be deleted'
);
}
public function execute(InputInterface $input, OutputInterface $output): int {
$remoteStorages = $this->getRemoteStorages();
$output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked');
$remoteShareIds = $this->getRemoteShareIds();
$output->writeln(count($remoteShareIds) . ' remote share(s) exist');
foreach ($remoteShareIds as $id => $remoteShareId) {
if (isset($remoteStorages[$remoteShareId])) {
if ($input->getOption('dry-run') || $output->isVerbose()) {
$output->writeln("<info>$remoteShareId belongs to remote share $id</info>");
}
unset($remoteStorages[$remoteShareId]);
} else {
$output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>");
}
}
if (empty($remoteStorages)) {
$output->writeln('<info>no storages deleted</info>');
} else {
$dryRun = $input->getOption('dry-run');
foreach ($remoteStorages as $id => $numericId) {
if ($dryRun) {
$output->writeln("<error>$id [$numericId] can be deleted</error>");
$this->countFiles($numericId, $output);
} else {
$this->deleteStorage($id, $numericId, $output);
}
}
}
return 0;
}
public function countFiles($numericId, OutputInterface $output) {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->select($queryBuilder->func()->count('fileid'))
->from('filecache')
->where($queryBuilder->expr()->eq(
'storage',
$queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
IQueryBuilder::PARAM_STR)
);
$result = $queryBuilder->executeQuery();
$count = $result->fetchOne();
$result->closeCursor();
$output->writeln("$count files can be deleted for storage $numericId");
}
public function deleteStorage($id, $numericId, OutputInterface $output) {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->delete('storages')
->where($queryBuilder->expr()->eq(
'id',
$queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR),
IQueryBuilder::PARAM_STR)
);
$output->write("deleting $id [$numericId] ... ");
$count = $queryBuilder->executeStatement();
$output->writeln("deleted $count storage");
$this->deleteFiles($numericId, $output);
}
public function deleteFiles($numericId, OutputInterface $output) {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->delete('filecache')
->where($queryBuilder->expr()->eq(
'storage',
$queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR),
IQueryBuilder::PARAM_STR)
);
$output->write("deleting files for storage $numericId ... ");
$count = $queryBuilder->executeStatement();
$output->writeln("deleted $count files");
}
public function getRemoteStorages() {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->select(['id', 'numeric_id'])
->from('storages')
->where($queryBuilder->expr()->like(
'id',
// match all 'shared::' + 32 characters storages
$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)),
IQueryBuilder::PARAM_STR)
)
->andWhere($queryBuilder->expr()->notLike(
'id',
// but not the ones starting with a '/', they are for normal shares
$queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'),
IQueryBuilder::PARAM_STR)
)
->orderBy('numeric_id');
$result = $queryBuilder->executeQuery();
$remoteStorages = [];
while ($row = $result->fetch()) {
$remoteStorages[$row['id']] = $row['numeric_id'];
}
$result->closeCursor();
return $remoteStorages;
}
public function getRemoteShareIds() {
$queryBuilder = $this->connection->getQueryBuilder();
$queryBuilder->select(['id', 'share_token', 'owner', 'remote'])
->from('share_external');
$result = $queryBuilder->executeQuery();
$remoteShareIds = [];
while ($row = $result->fetch()) {
$cloudId = $this->cloudIdManager->getCloudId($row['owner'], $row['remote']);
$remote = $cloudId->getRemote();
$remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $remote);
}
$result->closeCursor();
return $remoteShareIds;
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 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_Sharing\Command;
use OC\Core\Command\Base;
use OCA\Files_Sharing\OrphanHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class DeleteOrphanShares extends Base {
private OrphanHelper $orphanHelper;
public function __construct(OrphanHelper $orphanHelper) {
parent::__construct();
$this->orphanHelper = $orphanHelper;
}
protected function configure(): void {
$this
->setName('sharing:delete-orphan-shares')
->setDescription('Delete shares where the owner no longer has access to the file')
->addOption(
'force',
'f',
InputOption::VALUE_NONE,
'delete the shares without asking'
);
}
public function execute(InputInterface $input, OutputInterface $output): int {
$force = $input->getOption('force');
$shares = $this->orphanHelper->getAllShares();
$orphans = [];
foreach ($shares as $share) {
if (!$this->orphanHelper->isShareValid($share['owner'], $share['fileid'])) {
$orphans[] = $share['id'];
$exists = $this->orphanHelper->fileExists($share['fileid']);
$output->writeln("<info>{$share['target']}</info> owned by <info>{$share['owner']}</info>");
if ($exists) {
$output->writeln(" file still exists but the share owner lost access to it, run <info>occ info:file {$share['fileid']}</info> for more information about the file");
} else {
$output->writeln(" file no longer exists");
}
}
}
$count = count($orphans);
if ($count === 0) {
$output->writeln("No orphan shares detected");
return 0;
}
if ($force) {
$doDelete = true;
} else {
$output->writeln("");
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion("Delete <info>$count</info> orphan shares? [y/N] ", false);
$doDelete = $helper->ask($input, $output, $question);
}
if ($doDelete) {
$this->orphanHelper->deleteShares($orphans);
}
return 0;
}
}
@@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Joas Schilling <coding@schilljs.com>
* @author Roeland Jago Douma <roeland@famdouma.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_Sharing\Command;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
use OCP\Notification\IManager as NotificationManager;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ExiprationNotification extends Command {
/** @var NotificationManager */
private $notificationManager;
/** @var IDBConnection */
private $connection;
/** @var ITimeFactory */
private $time;
/** @var ShareManager */
private $shareManager;
public function __construct(ITimeFactory $time,
NotificationManager $notificationManager,
IDBConnection $connection,
ShareManager $shareManager) {
parent::__construct();
$this->notificationManager = $notificationManager;
$this->connection = $connection;
$this->time = $time;
$this->shareManager = $shareManager;
}
protected function configure() {
$this
->setName('sharing:expiration-notification')
->setDescription('Notify share initiators when a share will expire the next day.');
}
public function execute(InputInterface $input, OutputInterface $output): int {
//Current time
$minTime = $this->time->getDateTime();
$minTime->add(new \DateInterval('P1D'));
$minTime->setTime(0, 0, 0);
$maxTime = clone $minTime;
$maxTime->setTime(23, 59, 59);
$shares = $this->shareManager->getAllShares();
$now = $this->time->getDateTime();
/** @var IShare $share */
foreach ($shares as $share) {
if ($share->getExpirationDate() === null
|| $share->getExpirationDate()->getTimestamp() < $minTime->getTimestamp()
|| $share->getExpirationDate()->getTimestamp() > $maxTime->getTimestamp()) {
continue;
}
$notification = $this->notificationManager->createNotification();
$notification->setApp('files_sharing')
->setDateTime($now)
->setObject('share', $share->getFullId())
->setSubject('expiresTomorrow');
// Only send to initiator for now
$notification->setUser($share->getSharedBy());
$this->notificationManager->notify($notification);
}
return 0;
}
}