-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix expire commands and background job when trash and/or version apps…
… are disabled Signed-off-by: Carl Schwan <[email protected]>
- Loading branch information
1 parent
b9838fc
commit bc21eee
Showing
9 changed files
with
300 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]> | ||
* @copyright Copyright (c) 2022 Carl Schwan <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -21,10 +22,10 @@ | |
|
||
namespace OCA\GroupFolders\BackgroundJob; | ||
|
||
class ExpireGroupVersionsPlaceholder extends \OC\BackgroundJob\TimedJob { | ||
class ExpireGroupPlaceholder extends \OC\BackgroundJob\TimedJob { | ||
public function __construct() { | ||
// Run once per hour | ||
$this->setInterval(60 * 60); | ||
// Run at some point in a far far future :p | ||
$this->setInterval(60 * 60 * 99999999); | ||
} | ||
|
||
protected function run($argument) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]> | ||
* @copyright Copyright (c) 2021 Carl Schwan <[email protected]> | ||
* | ||
* @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\GroupFolders\BackgroundJob; | ||
|
||
use OCA\GroupFolders\Trash\TrashBackend; | ||
use OCA\Files_Trashbin\Expiration; | ||
use OCP\IConfig; | ||
|
||
class ExpireGroupTrash extends \OC\BackgroundJob\TimedJob { | ||
|
||
/** @var TrashBackend */ | ||
private $trashBackend; | ||
|
||
/** @var Expiration */ | ||
private $expiration; | ||
|
||
/** @var IConfig */ | ||
private $config; | ||
|
||
public function __construct( | ||
TrashBackend $trashBackend, | ||
Expiration $expiration, | ||
IConfig $config | ||
) { | ||
// Run once per hour | ||
$this->setInterval(60 * 60); | ||
|
||
$this->trashBackend = $trashBackend; | ||
$this->expiration = $expiration; | ||
$this->config = $config; | ||
} | ||
|
||
protected function run($argument) { | ||
$backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); | ||
if ($backgroundJob === 'no') { | ||
return; | ||
} | ||
$this->trashBackend->expire($this->expiration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]> | ||
* | ||
* @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\GroupFolders\Command\ExpireGroup; | ||
|
||
use OC\Core\Command\Base; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Base class for the group folder expiration commands. | ||
*/ | ||
class ExpireGroupBase extends Base { | ||
public function __construct() { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() { | ||
$this | ||
->setName('groupfolders:expire') | ||
->setDescription('Trigger expiration for files stored in group folders (trash and versions). Currently disabled.'); | ||
parent::configure(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$output->writeln('<error>groupfolder expiration handling is currently disabled because there is nothing to expire. Enable the "Delete Files" or/and "Versions" app to enable this feature.</error>'); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021 Carl Schwan <[email protected]> | ||
* | ||
* @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\GroupFolders\Command\ExpireGroup; | ||
|
||
use OCA\Files_Trashbin\Expiration; | ||
use OCA\GroupFolders\Trash\TrashBackend; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ExpireGroupTrash extends ExpireGroupBase { | ||
/** @var TrashBackend */ | ||
private $trashBackend; | ||
|
||
/** @var Expiration */ | ||
private $expiration; | ||
|
||
public function __construct( | ||
TrashBackend $trashBackend, | ||
Expiration $expiration | ||
) { | ||
parent::__construct(); | ||
$this->trashBackend = $trashBackend; | ||
$this->expiration = $expiration; | ||
} | ||
|
||
protected function configure() { | ||
$this | ||
->setName('groupfolders:expire') | ||
->setDescription('Trigger expiration of the trashbin for files stored in group folders'); | ||
parent::configure(); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
[$count, $size] = $this->trashBackend->expire($this->expiration); | ||
$output->writeln("<info>Removed $count expired trashbin items</info>"); | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]> | ||
* @copyright Copyright (c) 2021 Carl Schwan <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -19,42 +20,34 @@ | |
* | ||
*/ | ||
|
||
namespace OCA\GroupFolders\Command; | ||
namespace OCA\GroupFolders\Command\ExpireGroup; | ||
|
||
use OC\Core\Command\Base; | ||
use OCA\Files_Trashbin\Expiration; | ||
use OCA\Files_Versions\Versions\IVersion; | ||
use OCA\GroupFolders\Trash\TrashBackend; | ||
use OCA\GroupFolders\Versions\GroupVersionsExpireManager; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ExpireGroupVersions extends Base { | ||
/** | ||
* Trigger expiry of versions for files stored in group folders. | ||
*/ | ||
class ExpireGroupVersions extends ExpireGroupBase { | ||
/** @var GroupVersionsExpireManager */ | ||
private $expireManager; | ||
|
||
/** @var TrashBackend */ | ||
private $trashBackend; | ||
|
||
/** @var Expiration */ | ||
private $expiration; | ||
protected $expireManager; | ||
|
||
public function __construct( | ||
GroupVersionsExpireManager $expireManager, | ||
TrashBackend $trashBackend, | ||
Expiration $expiration | ||
GroupVersionsExpireManager $expireManager | ||
) { | ||
parent::__construct(); | ||
$this->expireManager = $expireManager; | ||
$this->trashBackend = $trashBackend; | ||
$this->expiration = $expiration; | ||
} | ||
|
||
protected function configure() { | ||
parent::configure(); | ||
$this | ||
->setName('groupfolders:expire') | ||
->setDescription('Trigger expiry of versions and trashbin for files stored in group folders'); | ||
parent::configure(); | ||
->setDescription('Trigger expiry of versions for files stored in group folders'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
|
@@ -71,10 +64,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { | |
$output->writeln("<info>Cleaning up versions for no longer existing file with id $id</info>"); | ||
}); | ||
|
||
|
||
list($count, $size) = $this->trashBackend->expire($this->expiration); | ||
$output->writeln("<info>Removed $count expired trashbin items</info>"); | ||
|
||
$this->expireManager->expireAll(); | ||
return 0; | ||
} | ||
|
Oops, something went wrong.