-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCallNumberDataFix.php
111 lines (95 loc) · 4.19 KB
/
CallNumberDataFix.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2022 webtrees development team
* <http://webtrees.net>
*
* RepositoryHierarchy (webtrees custom module):
* Copyright (C) 2022 Markus Hemprich
* <http://www.familienforschung-hemprich.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Jefferson49\Webtrees\Module\RepositoryHierarchy;
use Fisharebest\Webtrees\Http\RequestHandlers\PendingChanges;
use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\Module\ModuleDataFixInterface;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Validator;
use Jefferson49\Webtrees\Internationalization\MoreI18N;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function route;
/**
* Run data-fix for call number categories
*/
class CallNumberDataFix implements RequestHandlerInterface
{
use ViewResponseTrait;
//Module service to search and find modules
private ModuleService $module_service;
/**
* DataFix constructor.
*
* @param ModuleService $module_service
*/
public function __construct(ModuleService $module_service)
{
$this->module_service = $module_service;
}
/**
* Handle the request for the call number data fix
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$repository_xref = Validator::attributes($request)->string(CallNumberCategory::VAR_XREF);
$category_name = Validator::queryParams($request)->string(CallNumberCategory::VAR_CATEGORY_NAME);
$category_full_name = Validator::queryParams($request)->string(CallNumberCategory::VAR_CATEGORY_FULL_NAME);
$data_fixes = $this->module_service->findByInterface(ModuleDataFixInterface::class);
$data_fix = RepositoryHierarchy::activeModuleName();
$module = $data_fixes->get($data_fix);
$module->setDataFixParams($tree, $repository_xref, $category_name, $category_full_name);
$this->layout = 'layouts/administration';
if ($module instanceof ModuleDataFixInterface) {
$title = $module->title() . ' — ' . e($tree->title());
$page_url = route(self::class, ['data_fix' => $data_fix, 'tree' => $tree->name()]);
$pending_url = route(PendingChanges::class, ['tree' => $tree->name(), 'url' => $page_url]);
return $this->viewResponse(
'admin/data-fix-page',
[
RepositoryHierarchy::VAR_DATA_FIX => $module,
RepositoryHierarchy::VAR_DATA_FIX_TITLE => $title,
CallNumberCategory::VAR_TREE => $tree,
RepositoryHierarchy::VAR_DATA_FIX_PENDING_URL => $pending_url,
]
);
}
//Default: continue with general data fix selection
$title = MoreI18N::xlate('Data fixes') . ' — ' . e($tree->title());
$data_fixes = $this->module_service->findByInterface(ModuleDataFixInterface::class, false, true);
return $this->viewResponse(
'admin/data-fix-select',
[
RepositoryHierarchy::VAR_DATA_FIX_TITLE => $title,
RepositoryHierarchy::VAR_DATA_FIXES => $data_fixes,
CallNumberCategory::VAR_TREE => $tree,
]
);
}
}