]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Controllers/AdminToolsController.php
6dd89f185cc7a4be3a0ff77a03df391afc2da83f
[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 _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.")
82 );
83 }
84
85 // display page
86 $this->view->render(
87 $response,
88 'admintools.tpl',
89 $params
90 );
91 return $response;
92 }
93
94 /**
95 * Process Administration tools
96 *
97 * @param Request $request PSR Request
98 * @param Response $response PSR Response
99 *
100 * @return Response
101 */
102 public function process(Request $request, Response $response) :Response
103 {
104 $post = $request->getParsedBody();
105
106 $error_detected = [];
107 $success_detected = [];
108
109 if (isset($post['inittexts'])) {
110 //proceed emails texts reinitialization
111 $texts = new Texts($this->preferences);
112 $res = $texts->installInit(false);
113 if ($res === true) {
114 $success_detected[] = _T("Texts has been successfully reinitialized.");
115 } else {
116 $error_detected[] = _T("An error occurred reinitializing texts :(");
117 }
118 }
119
120 if (isset($post['initfields'])) {
121 //proceed fields configuration reinitialization
122 $fc = $this->fields_config;
123 $res = $fc->installInit();
124 if ($res === true) {
125 $success_detected[] = _T("Fields configuration has been successfully reinitialized.");
126 } else {
127 $error_detected[] = _T("An error occurred reinitializing fields configuration :(");
128 }
129 }
130
131 if (isset($post['initpdfmodels'])) {
132 //proceed emails texts reinitialization
133 $models = new PdfModels($this->zdb, $this->preferences, $this->login);
134 $res = $models->installInit($this->pdfmodels_fields, false);
135 if ($res === true) {
136 $success_detected[] = _T("PDF models has been successfully reinitialized.");
137 } else {
138 $error_detected[] = _T("An error occurred reinitializing PDF models :(");
139 }
140 }
141
142 if (isset($post['emptylogins'])) {
143 //proceed empty logins and passwords
144 //those ones cannot be null
145 $members = new Members();
146 $res = $members->emptylogins();
147 if ($res === true) {
148 $success_detected[] = str_replace(
149 '%i',
150 $members->getCount(),
151 _T("Logins and passwords has been successfully filled (%i processed).")
152 );
153 } else {
154 $error_detected[] = _T("An error occurred filling empty logins and passwords :(");
155 }
156 }
157
158 //flash messages
159 if (count($error_detected) > 0) {
160 foreach ($error_detected as $error) {
161 $this->flash->addMessage(
162 'error_detected',
163 $error
164 );
165 }
166 }
167 if (count($success_detected) > 0) {
168 foreach ($success_detected as $success) {
169 $this->flash->addMessage(
170 'success_detected',
171 $success
172 );
173 }
174 }
175
176 return $response
177 ->withStatus(301)
178 ->withHeader('Location', $this->router->pathFor('adminTools'));
179 }
180 }