]> git.agnieray.net Git - galette.git/blob - galette/cron/reminder.php
Remove 'svn' lines
[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 * @link http://galette.tuxfamily.org
34 * @since Available since 0.7.5dev - 2013-02-08
35 */
36
37 use Galette\Entity\Texts;
38 use Galette\Repository\Members;
39 use Galette\Repository\Reminders;
40 use Galette\Filters\MembersList;
41
42 /** @ignore */
43 require_once __DIR__ . '/../includes/galette.inc.php';
44
45 $app = new \Slim\App(
46 array(
47 'templates.path' => GALETTE_ROOT . 'templates/default/',
48 'mode' => 'CRON'
49 )
50 );
51 session_start();
52 require_once __DIR__ . '/../includes/dependencies.php';
53
54 if (isset($needs_update) && $needs_update === true) {
55 echo _T("Your Galette database is not present, or not up to date.");
56 die(1);
57 }
58
59 /** TODO: login is now handled in dependencies.php; the cron case should be aswell */
60 if ($cron) {
61 $container->get('login')->logCron(basename($argv[0], '.php'));
62 }
63
64 if (!$container->get('login')->isCron()) {
65 die(1);
66 }
67
68 $texts = new Texts(
69 $container->get('preferences')
70 );
71 $reminders = new Reminders();
72
73
74 $list_reminders = $reminders->getList($container->get('zdb'), false);
75 if (count($list_reminders) > 0) {
76 foreach ($list_reminders as $reminder) {
77 //send reminders by email
78 $sent = $reminder->send($texts, $container->get('history'), $container->get('zdb'));
79
80 if ($sent === true) {
81 $success_detected[] = $reminder->getMessage();
82 } else {
83 $error_detected[] = $reminder->getMessage();
84 }
85 }
86
87 if (count($error_detected) > 0) {
88 array_unshift(
89 $error_detected,
90 _T("Reminder has not been sent:")
91 );
92 }
93
94 if (count($success_detected) > 0) {
95 array_unshift(
96 $success_detected,
97 _T("Sent reminders:")
98 );
99 }
100 }
101
102 //called from a cron. warning and errors has been stored into history
103 //and probably logged
104 if (count($error_detected) > 0) {
105 //if there are errors, we print them
106 echo "\n";
107 $count = 0;
108 foreach ($error_detected as $e) {
109 if ($count > 0) {
110 echo ' ';
111 }
112 echo $e . "\n";
113 $count++;
114 }
115 //we can also print additionnal information.
116 if (count($success_detected) > 0) {
117 echo "\n";
118 echo str_replace(
119 '%i',
120 count($success_detected),
121 _T("%i emails have been sent successfully.")
122 );
123 }
124 exit(1);
125 } else {
126 //if there were no errors, we just exit properly for cron to be quiet.
127 exit(0);
128 }