]> git.agnieray.net Git - galette.git/blob - galette/cron/reminder.php
Cron script was not using DI; fixes #1384
[galette.git] / galette / cron / reminder.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette cron reminders
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2016 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Main
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.7.5dev - 2013-02-08
36 */
37
38 use Galette\Entity\Texts;
39 use Galette\Repository\Members;
40 use Galette\Repository\Reminders;
41 use Galette\Filters\MembersList;
42
43 /** @ignore */
44 require_once __DIR__ . '/../includes/galette.inc.php';
45
46 if (!$login->isCron()) {
47 die();
48 }
49
50 $texts = new Texts(
51 $container->get('texts_fields'),
52 $container->get('preferences')
53 );
54 $reminders = new Reminders();
55
56
57 $list_reminders = $reminders->getList($container->get('zdb'), false);
58 if (count($list_reminders) > 0) {
59 foreach ($list_reminders as $reminder) {
60 //send reminders by mail
61 $sent = $reminder->send($texts, $container->get('hist'), $container->get('zdb'));
62
63 if ($sent === true) {
64 $success_detected[] = $reminder->getMessage();
65 } else {
66 $error_detected[] = $reminder->getMessage();
67 }
68 }
69
70 if (count($error_detected) > 0) {
71 array_unshift(
72 $error_detected,
73 _T("Reminder has not been sent:")
74 );
75 }
76
77 if (count($success_detected) > 0) {
78 array_unshift(
79 $success_detected,
80 _T("Sent reminders:")
81 );
82 }
83 }
84
85 //called from a cron. warning and errors has been stored into history
86 //and probably logged
87 if (count($error_detected) > 0) {
88 //if there are errors, we print them
89 echo "\n";
90 $count = 0;
91 foreach ($error_detected as $e) {
92 if ($count > 0) {
93 echo ' ';
94 }
95 echo $e . "\n";
96 $count++;
97 }
98 //we can also print additionnal informations.
99 if (count($success_detected) > 0) {
100 echo "\n";
101 echo str_replace(
102 '%i',
103 count($success_detected),
104 _T("%i mails have been sent successfully.")
105 );
106 }
107 exit(1);
108 } else {
109 //if there were no errors, we just exit properly for cron to be quiet.
110 exit(0);
111 }