1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* @author Morris Jobke <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license AGPL-3.0 |
9
|
|
|
* |
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
12
|
|
|
* as published by the Free Software Foundation. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Activity\BackgroundJob; |
25
|
|
|
|
26
|
|
|
use OC\BackgroundJob\TimedJob; |
27
|
|
|
use OCA\Activity\MailQueueHandler; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class EmailNotification |
31
|
|
|
* |
32
|
|
|
* @package OCA\Activity\BackgroundJob |
33
|
|
|
*/ |
34
|
|
|
class EmailNotification extends TimedJob { |
35
|
|
|
|
36
|
|
|
/** @var MailQueueHandler */ |
37
|
|
|
protected $queueHandler; |
38
|
|
|
|
39
|
|
|
/** @var bool */ |
40
|
|
|
protected $isCLI; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param MailQueueHandler $mailQueueHandler |
44
|
|
|
* @param bool $isCLI |
45
|
|
|
*/ |
46
|
4 |
|
public function __construct(MailQueueHandler $mailQueueHandler, |
47
|
|
|
$isCLI) { |
48
|
|
|
// Run all 15 Minutes |
49
|
4 |
|
$this->setInterval(15 * 60); |
50
|
|
|
|
51
|
4 |
|
$this->queueHandler = $mailQueueHandler; |
52
|
4 |
|
$this->isCLI = $isCLI; |
53
|
4 |
|
} |
54
|
|
|
|
55
|
2 |
|
protected function run($argument) { |
56
|
|
|
// We don't use time() but "time() - 1" here, so we don't run into |
57
|
|
|
// runtime issues later and delete emails, which were created in the |
58
|
|
|
// same second, but were not collected for the emails. |
59
|
2 |
|
$sendTime = time() - 1; |
60
|
|
|
|
61
|
2 |
|
if ($this->isCLI) { |
62
|
|
|
do { |
63
|
|
|
// If we are in CLI mode, we keep sending emails |
64
|
|
|
// until we are done. |
65
|
1 |
|
$emails_sent = $this->queueHandler->sendEmails(MailQueueHandler::CLI_EMAIL_BATCH_SIZE, $sendTime); |
66
|
1 |
|
} while ($emails_sent === MailQueueHandler::CLI_EMAIL_BATCH_SIZE); |
67
|
|
|
} else { |
68
|
|
|
// Only send 25 Emails in one go for web cron |
69
|
1 |
|
$this->queueHandler->sendEmails(MailQueueHandler::WEB_EMAIL_BATCH_SIZE, $sendTime); |
70
|
|
|
} |
71
|
2 |
|
} |
72
|
|
|
} |
73
|
|
|
|