65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Provisioning\Steps\Customer;
|
|
|
|
use App\Models\ProvisioningRun;
|
|
use App\Provisioning\StepResult;
|
|
use App\Services\Proxmox\ProxmoxClient;
|
|
|
|
/**
|
|
* The storage a plan change actually delivers.
|
|
*
|
|
* This is the half of a plan change that a downgrade can carry out in full: a
|
|
* disk cannot be shrunk, but a quota can, and the quota is what was sold. The
|
|
* customer on a 200 GB package gets 200 GB whatever size the underlying disk
|
|
* happens to be, and Nextcloud is what enforces it.
|
|
*
|
|
* `files default_quota`, not a per-user quota. An account with an explicit quota
|
|
* stops following the default, so writing one onto the admin account would
|
|
* freeze that account at today's figure and quietly exclude it from the next
|
|
* plan change. The default applies to every account on the instance — which is
|
|
* what a package's storage allowance means here, since a package is a whole
|
|
* Nextcloud and not a seat on a shared one.
|
|
*/
|
|
class ApplyStorageQuota extends CustomerStep
|
|
{
|
|
public function __construct(private ProxmoxClient $pve) {}
|
|
|
|
public function key(): string
|
|
{
|
|
return 'apply_storage_quota';
|
|
}
|
|
|
|
public function maxDuration(): int
|
|
{
|
|
return 120;
|
|
}
|
|
|
|
public function execute(ProvisioningRun $run): StepResult
|
|
{
|
|
$instance = $this->instance($run);
|
|
|
|
if ($instance === null) {
|
|
return StepResult::fail('no_instance');
|
|
}
|
|
|
|
$quota = (int) $instance->quota_gb;
|
|
|
|
// No allowance recorded: setting "0 GB" would lock the customer out of
|
|
// their own files, which is a far worse answer than leaving what is
|
|
// there and letting somebody notice.
|
|
if ($quota <= 0) {
|
|
return StepResult::advance();
|
|
}
|
|
|
|
$pve = $this->pve->forHost($instance->host);
|
|
$occ = 'cd /opt/nextcloud && docker compose exec -T app php occ ';
|
|
|
|
// Idempotent, like every other occ call in this pipeline: writing the
|
|
// same value again is a no-op and exits 0.
|
|
$this->guest($pve, $run, $occ.'config:app:set files default_quota --value='.escapeshellarg($quota.' GB'));
|
|
|
|
return StepResult::advance();
|
|
}
|
|
}
|