Skip to content

Commit a456fbe

Browse files
committed
disable cron when using Ajax
1 parent ac0e849 commit a456fbe

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

lib/Cron/Backup.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class Backup extends TimedJob {
4747
use TNC23Logger;
4848

4949

50-
5150
/** @var PointService */
5251
private $pointService;
5352

@@ -82,7 +81,11 @@ public function __construct(
8281
/**
8382
* @param $argument
8483
*/
85-
protected function run($argument) {
84+
protected function run($argument):void {
85+
if (!$this->cronService->isRealCron()) {
86+
return;
87+
}
88+
8689
$time = time();
8790
if ($this->configService->getAppValueInt(ConfigService::MOCKUP_DATE) > 0) {
8891
$time = $this->configService->getAppValueInt(ConfigService::MOCKUP_DATE);

lib/Cron/Event.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
3838
use OCA\Backup\Model\BackupEvent;
3939
use OCA\Backup\Service\ConfigService;
40+
use OCA\Backup\Service\CronService;
4041
use OCA\Backup\Service\FilesService;
4142

4243
/**
@@ -54,6 +55,9 @@ class Event extends TimedJob {
5455
/** @var FilesService */
5556
private $filesService;
5657

58+
/** @var CronService */
59+
private $cronService;
60+
5761
/** @var ConfigService */
5862
private $configService;
5963

@@ -63,17 +67,20 @@ class Event extends TimedJob {
6367
*
6468
* @param EventRequest $eventRequest
6569
* @param FilesService $filesService
70+
* @param CronService $cronService
6671
* @param ConfigService $configService
6772
*/
6873
public function __construct(
6974
EventRequest $eventRequest,
7075
FilesService $filesService,
76+
CronService $cronService,
7177
ConfigService $configService
7278
) {
7379
$this->setInterval(1);
7480

7581
$this->eventRequest = $eventRequest;
7682
$this->filesService = $filesService;
83+
$this->cronService = $cronService;
7784
$this->configService = $configService;
7885
}
7986

@@ -82,6 +89,10 @@ public function __construct(
8289
* @param $argument
8390
*/
8491
protected function run($argument) {
92+
if (!$this->cronService->isRealCron()) {
93+
return;
94+
}
95+
8596
foreach ($this->eventRequest->getQueue() as $event) {
8697
if ($event->getType() === 'ScanLocalFolder') {
8798
$this->scanLocalFolder($event);

lib/Cron/Manage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public function __construct(
102102
* @param $argument
103103
*/
104104
protected function run($argument) {
105+
if (!$this->cronService->isRealCron()) {
106+
return;
107+
}
108+
105109
// uploading
106110
foreach ($this->pointService->getLocalRestoringPoints() as $point) {
107111
try {

lib/Service/ConfigService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ public function __construct(IConfig $config) {
118118
}
119119

120120

121+
/**
122+
* @param string $key
123+
* @param string $default
124+
*
125+
* @return string
126+
*/
127+
public function getCoreValue(string $key, string $default): string {
128+
return $this->config->getAppValue('core', $key, $default);
129+
}
130+
121131
/**
122132
* Get a value by key
123133
*
@@ -350,4 +360,5 @@ public function setSettings(array $settings): array {
350360

351361
return $this->getSettings();
352362
}
363+
353364
}

lib/Service/CronService.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public function nextBackups(): array {
118118
if ($fullETA === -1 && $this->verifyFullBackup($time)) {
119119
$fullETA = $time;
120120
} elseif ($partialETA === -1
121-
&& $this->verifyIncrementalBackup($time)
122-
&& ($this->configService->getAppValueInt(ConfigService::DATE_FULL_RP) > 0
123-
|| $fullETA > 0)) { // we check that the incremental backup can have a parent
121+
&& $this->verifyIncrementalBackup($time)
122+
&& ($this->configService->getAppValueInt(ConfigService::DATE_FULL_RP) > 0
123+
|| $fullETA > 0)) { // we check that the incremental backup can have a parent
124124
$partialETA = $time;
125125
}
126126

@@ -363,4 +363,14 @@ private function orderByDate(array $points, array $dates): array {
363363
private function o(string $line, bool $ln = true): void {
364364
$this->outputService->o($line, $ln);
365365
}
366+
367+
368+
/**
369+
* @return bool
370+
*/
371+
public function isRealCron(): bool {
372+
$mode = $this->configService->getCoreValue('backgroundjobs_mode', '');
373+
374+
return (strtolower($mode) === 'cron' || strtolower($mode) === 'webcron');
375+
}
366376
}

0 commit comments

Comments
 (0)