]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Controllers/AdminToolsController.php
0a3f2a8957be006e4398330dcc235b3bac594245
[galette.git] / galette / lib / Galette / Controllers / AdminToolsController.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette admin tools controller
7 *
8 * PHP version 5
9 *
10 * Copyright © 2020 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 Entity
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020 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.9.4dev - 2020-05-03
36 */
37
38 namespace Galette\Controllers;
39
40 use Slim\Http\Request;
41 use Slim\Http\Response;
42 use Galette\Core\CheckModules;
43 use Galette\Entity\Texts;
44 use Galette\Repository\Members;
45 use Galette\Repository\PdfModels;
46 use Analog\Analog;
47
48 /**
49 * Galette main controller
50 *
51 * @category Controllers
52 * @name AdminToolsController
53 * @package Galette
54 * @author Johan Cwiklinski <johan@x-tnd.be>
55 * @copyright 2020 The Galette Team
56 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
57 * @link http://galette.tuxfamily.org
58 * @since Available since 0.9.4dev - 2020-05-03
59 */
60
61 class AdminToolsController extends AbstractController
62 {
63 /**
64 * Administration tools page
65 *
66 * @param Request $request PSR Request
67 * @param Response $response PSR Response
68 *
69 * @return Response
70 */
71 public function adminTools(Request $request, Response $response): Response
72 {
73 $params = [
74 'page_title' => _T('Administration tools')
75 ];
76
77 $cm = new CheckModules();
78 $modules_ok = $cm->isValid();
79 if (!$modules_ok) {
80 $this->flash->addMessage(
81 'error_detected',
82 _T("Some PHP modules are missing. Please install them or contact your support.<br/>More information on required modules may be found in the documentation.")
83 );
84 }
85
86 // display page
87 $this->view->render(
88 $response,
89 'admintools.tpl',
90 $params
91 );
92 return $response;
93 }
94
95 /**
96 * Process Administration tools
97 *
98 * @param Request $request PSR Request
99 * @param Response $response PSR Response
100 *
101 * @return Response
102 */
103 public function process(Request $request, Response $response): Response
104 {
105 $post = $request->getParsedBody();
106
107 $error_detected = [];
108 $success_detected = [];
109
110 if (isset($post['inittexts'])) {
111 //proceed emails texts reinitialization
112 $texts = new Texts($this->preferences);
113 $res = $texts->installInit(false);
114 if ($res === true) {
115 $success_detected[] = _T("Texts has been successfully reinitialized.");
116 } else {
117 $error_detected[] = _T("An error occurred reinitializing texts :(");
118 }
119 }
120
121 if (isset($post['initfields'])) {
122 //proceed fields configuration reinitialization
123 $fc = $this->fields_config;
124 $res = $fc->installInit();
125 if ($res === true) {
126 $success_detected[] = _T("Fields configuration has been successfully reinitialized.");
127 } else {
128 $error_detected[] = _T("An error occurred reinitializing fields configuration :(");
129 }
130 }
131
132 if (isset($post['initpdfmodels'])) {
133 //proceed emails texts reinitialization
134 $models = new PdfModels($this->zdb, $this->preferences, $this->login);
135 $res = $models->installInit($this->pdfmodels_fields, false);
136 if ($res === true) {
137 $success_detected[] = _T("PDF models has been successfully reinitialized.");
138 } else {
139 $error_detected[] = _T("An error occurred reinitializing PDF models :(");
140 }
141 }
142
143 if (isset($post['emptylogins'])) {
144 //proceed empty logins and passwords
145 //those ones cannot be null
146 $members = new Members();
147 $res = $members->emptylogins();
148 if ($res === true) {
149 $success_detected[] = str_replace(
150 '%i',
151 $members->getCount(),
152 _T("Logins and passwords has been successfully filled (%i processed).")
153 );
154 } else {
155 $error_detected[] = _T("An error occurred filling empty logins and passwords :(");
156 }
157 }
158
159 //flash messages
160 if (count($error_detected) > 0) {
161 foreach ($error_detected as $error) {
162 $this->flash->addMessage(
163 'error_detected',
164 $error
165 );
166 }
167 }
168 if (count($success_detected) > 0) {
169 foreach ($success_detected as $success) {
170 $this->flash->addMessage(
171 'success_detected',
172 $success
173 );
174 }
175 }
176
177 return $response
178 ->withStatus(301)
179 ->withHeader('Location', $this->router->pathFor('adminTools'));
180 }
181 }