3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette admin tools controller
10 * Copyright © 2020 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 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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.4dev - 2020-05-03
38 namespace Galette\Controllers
;
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
;
49 * Galette main controller
51 * @category Controllers
52 * @name AdminToolsController
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
61 class AdminToolsController
extends AbstractController
64 * Administration tools page
66 * @param Request $request PSR Request
67 * @param Response $response PSR Response
71 public function adminTools(Request
$request, Response
$response): Response
74 'page_title' => _T('Administration tools')
77 $cm = new CheckModules();
78 $modules_ok = $cm->isValid();
80 $this->flash
->addMessage(
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.")
96 * Process Administration tools
98 * @param Request $request PSR Request
99 * @param Response $response PSR Response
103 public function process(Request
$request, Response
$response): Response
105 $post = $request->getParsedBody();
107 $error_detected = [];
108 $success_detected = [];
110 if (isset($post['inittexts'])) {
111 //proceed emails texts reinitialization
112 $texts = new Texts($this->preferences
);
113 $res = $texts->installInit(false);
115 $success_detected[] = _T("Texts has been successfully reinitialized.");
117 $error_detected[] = _T("An error occurred reinitializing texts :(");
121 if (isset($post['initfields'])) {
122 //proceed fields configuration reinitialization
123 $fc = $this->fields_config
;
124 $res = $fc->installInit();
126 $success_detected[] = _T("Fields configuration has been successfully reinitialized.");
128 $error_detected[] = _T("An error occurred reinitializing fields configuration :(");
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);
137 $success_detected[] = _T("PDF models has been successfully reinitialized.");
139 $error_detected[] = _T("An error occurred reinitializing PDF models :(");
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();
149 $success_detected[] = str_replace(
151 $members->getCount(),
152 _T("Logins and passwords has been successfully filled (%i processed).")
155 $error_detected[] = _T("An error occurred filling empty logins and passwords :(");
160 if (count($error_detected) > 0) {
161 foreach ($error_detected as $error) {
162 $this->flash
->addMessage(
168 if (count($success_detected) > 0) {
169 foreach ($success_detected as $success) {
170 $this->flash
->addMessage(
179 ->withHeader('Location', $this->router
->pathFor('adminTools'));