3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette cron reminders
10 * Copyright © 2013-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2022 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
37 use Galette\Entity\Texts
;
38 use Galette\Repository\Members
;
39 use Galette\Repository\Reminders
;
40 use Galette\Filters\MembersList
;
43 require_once __DIR__
. '/../includes/galette.inc.php';
45 $gapp = new \Galette\Core\
LightSlimApp('CRON');
46 $app = $gapp->getApp();
49 require_once __DIR__
. '/../includes/dependencies.php';
51 if (isset($needs_update) && $needs_update === true) {
52 echo _T("Your Galette database is not present, or not up to date.");
57 * Authentication middleware
59 $authenticate = new \Galette\Middleware\
Authenticate($container);
61 require_once GALETTE_ROOT
. 'includes/routes/main.routes.php';
62 require_once GALETTE_ROOT
. 'includes/routes/authentication.routes.php';
63 require_once GALETTE_ROOT
. 'includes/routes/management.routes.php';
64 require_once GALETTE_ROOT
. 'includes/routes/members.routes.php';
65 require_once GALETTE_ROOT
. 'includes/routes/groups.routes.php';
66 require_once GALETTE_ROOT
. 'includes/routes/contributions.routes.php';
68 $container->get('login')->logCron(basename($argv[0], '.php'));
69 define('GALETTE_CRON', true);
72 if (!$container->get('login')->isCron()) {
76 if ($cron && !defined('GALETTE_URI')) {
77 echo _T('Please define constant "GALETTE_URI" with the path to your instance.') . "\n";
82 $container->get('preferences')
84 $reminders = new Reminders();
85 $success_detected = [];
88 $list_reminders = $reminders->getList($container->get('zdb'), false);
89 if (count($list_reminders) > 0) {
90 foreach ($list_reminders as $reminder) {
91 //send reminders by email
92 $sent = $reminder->send($texts, $container->get('history'), $container->get('zdb'));
95 $success_detected[] = $reminder->getMessage();
97 $error_detected[] = $reminder->getMessage();
101 if (count($error_detected) > 0) {
104 _T("Reminder has not been sent:")
108 if (count($success_detected) > 0) {
111 _T("Sent reminders:")
116 //called from a cron. warning and errors has been stored into history
117 //and probably logged
118 if (count($error_detected) > 0) {
119 //if there are errors, we print them
122 foreach ($error_detected as $e) {
129 //we can also print additional information.
130 if (count($success_detected) > 0) {
134 count($success_detected),
135 _T("%i emails have been sent successfully.")
140 //if there were no errors, we just exit properly for cron to be quiet.