Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions js/settings.js

This file was deleted.

2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCA\QuotaWarning\Job\User;
use OCA\QuotaWarning\Notification\Notifier;
use OCA\QuotaWarning\SettingsForm;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand All @@ -25,6 +26,7 @@ public function __construct() {

#[\Override]
public function register(IRegistrationContext $context): void {
$context->registerDeclarativeSettings(SettingsForm::class);
}

#[\Override]
Expand Down
65 changes: 20 additions & 45 deletions lib/CheckQuota.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OCA\QuotaWarning\AppInfo\Application;
use OCA\QuotaWarning\Job\User;
use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
use OCP\Files\FileInfo;
use OCP\Files\NotFoundException;
Expand All @@ -22,42 +23,16 @@
use Psr\Log\LoggerInterface;

class CheckQuota {

/** @var IConfig */
protected $config;

/** @var LoggerInterface */
protected $logger;

/** @var IMailer */
protected $mailer;

/** @var IFactory */
protected $l10nFactory;

/** @var IUserManager */
protected $userManager;

/** @var IJobList */
protected $jobList;

/** @var IManager */
protected $notificationManager;

public function __construct(IConfig $config,
LoggerInterface $logger,
IMailer $mailer,
IFactory $l10nFactory,
IUserManager $userManager,
IJobList $jobList,
IManager $notificationManager) {
$this->config = $config;
$this->logger = $logger;
$this->mailer = $mailer;
$this->l10nFactory = $l10nFactory;
$this->userManager = $userManager;
$this->jobList = $jobList;
$this->notificationManager = $notificationManager;
public function __construct(
private readonly IAppConfig $appConfig,
private readonly IConfig $config,
private readonly LoggerInterface $logger,
private readonly IMailer $mailer,
private readonly IFactory $l10nFactory,
private readonly IUserManager $userManager,
private readonly IJobList $jobList,
private readonly IManager $notificationManager,
) {
}

/**
Expand All @@ -73,27 +48,27 @@ public function check(string $userId): void {

$usage = $this->getRelativeQuotaUsage($userId);

if ($usage > $this->config->getAppValue('quota_warning', 'alert_percentage', '95')) {
if ($usage > $this->appConfig->getAppValueInt('alert_percentage', 95)) {
if ($this->shouldIssueWarning($userId, 'alert')) {
$this->issueWarning($userId, $usage);
if ($this->config->getAppValue('quota_warning', 'alert_email', 'no') === 'yes') {
if ($this->appConfig->getAppValueBool('alert_email')) {
$this->sendEmail($userId, $usage);
}
}
$this->updateLastWarning($userId, 'alert');
} elseif ($usage > $this->config->getAppValue('quota_warning', 'warning_percentage', '90')) {
} elseif ($usage > $this->appConfig->getAppValueInt('warning_percentage', 90)) {
if ($this->shouldIssueWarning($userId, 'warning')) {
$this->issueWarning($userId, $usage);
if ($this->config->getAppValue('quota_warning', 'warning_email', 'no') === 'yes') {
if ($this->appConfig->getAppValueBool('warning_email')) {
$this->sendEmail($userId, $usage);
}
}
$this->updateLastWarning($userId, 'warning');
$this->removeLastWarning($userId, 'alert');
} elseif ($usage > $this->config->getAppValue('quota_warning', 'info_percentage', '85')) {
} elseif ($usage > $this->appConfig->getAppValueInt('info_percentage', 85)) {
if ($this->shouldIssueWarning($userId, 'info')) {
$this->issueWarning($userId, $usage);
if ($this->config->getAppValue('quota_warning', 'info_email', 'no') === 'yes') {
if ($this->appConfig->getAppValueBool('info_email')) {
$this->sendEmail($userId, $usage);
}
}
Expand All @@ -112,7 +87,7 @@ public function check(string $userId): void {
public function getRelativeQuotaUsage(string $userId): float {
try {
$storage = $this->getStorageInfo($userId);
} catch (NotFoundException $e) {
} catch (NotFoundException) {
return 0.0;
}

Expand Down Expand Up @@ -173,7 +148,7 @@ protected function sendEmail(string $userId, float $percentage): void {
$emailTemplate->addHeader();
$emailTemplate->addHeading($l->t('Nearing your storage quota'), false);

$link = $this->config->getAppValue('quota_warning', 'plan_management_url');
$link = $this->appConfig->getAppValueString('plan_management_url');

$help = $l->t('You are using more than %d%% of your storage quota. Try to free up some space by deleting old files you don\'t need anymore.', [$percentage]);
if ($link !== '') {
Expand Down Expand Up @@ -236,7 +211,7 @@ protected function shouldIssueWarning(string $userId, string $level): bool {
return true;
}

$days = (int)$this->config->getAppValue('quota_warning', 'repeat_warning', '7');
$days = $this->appConfig->getAppValueInt('repeat_warning', 7);

if ($days <= 0) {
return false;
Expand Down
21 changes: 5 additions & 16 deletions lib/Job/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,13 @@
use OCP\BackgroundJob\TimedJob;

class User extends TimedJob {

/** @var CheckQuota */
protected $checkQuota;

public function __construct(ITimeFactory $time,
CheckQuota $checkQuota) {
public function __construct(
ITimeFactory $time,
protected CheckQuota $checkQuota,
) {
parent::__construct($time);
$this->checkQuota = $checkQuota;
$this->setInterval(86400);

if (method_exists($this, 'setTimeSensitivity')) {
/**
* This constant is always defined when setTimeSensitivity exists,
* Psalm can not know this :(
* @psalm-suppress UndefinedConstant
*/
$this->setTimeSensitivity(TimedJob::TIME_INSENSITIVE);
}
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
}

#[\Override]
Expand Down
25 changes: 6 additions & 19 deletions lib/Migration/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,20 @@

namespace OCA\QuotaWarning\Migration;

use OCA\QuotaWarning\AppInfo\Application;
use OCA\QuotaWarning\Job\User;
use OCP\AppFramework\Services\IAppConfig;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class Install implements IRepairStep {

/** @var IUserManager */
protected $userManager;

/** @var IJobList */
protected $jobList;
/** @var IConfig */
protected $config;

public function __construct(
IUserManager $userManager,
IJobList $jobList,
IConfig $config,
protected IUserManager $userManager,
protected IJobList $jobList,
protected IAppConfig $appConfig,
) {
$this->userManager = $userManager;
$this->jobList = $jobList;
$this->config = $config;
}

#[\Override]
Expand All @@ -44,7 +31,7 @@ public function getName(): string {

#[\Override]
public function run(IOutput $output): void {
if ($this->config->getAppValue(Application::APP_ID, 'initialised', 'no') === 'yes') {
if ($this->appConfig->getAppValueBool('initialised')) {
return;
}

Expand All @@ -58,6 +45,6 @@ public function run(IOutput $output): void {
});
$output->finishProgress();

$this->config->setAppValue(Application::APP_ID, 'initialised', 'yes');
$this->appConfig->setAppValueBool('initialised', true);
}
}
19 changes: 5 additions & 14 deletions lib/Migration/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,19 @@
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

/**
* Repair step called when disabling the quota_warning application. This will
* remove all the jobs from the job lists.
*
* @author Carl Schwan <carl@carlschwan.eu>
*/
class Uninstall implements IRepairStep {

/** @var IJobList */
private $jobList;

public function __construct(IJobList $jobList) {
$this->jobList = $jobList;
public function __construct(
private readonly IJobList $jobList,
) {
}

#[\Override]
public function getName() {
public function getName(): string {
return 'Remove QuotaWarning background jobs';
}

#[\Override]
public function run(IOutput $output) {
public function run(IOutput $output): void {
// Remove all the background jobs
$this->jobList->remove(User::class);
}
Expand Down
50 changes: 0 additions & 50 deletions lib/Settings.php

This file was deleted.

Loading
Loading