. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Services\PendingChangesService; use Fisharebest\Webtrees\Validator; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use function response; /** * Accept pending changes for a record. */ class PendingChangesAcceptRecord implements RequestHandlerInterface { private PendingChangesService $pending_changes_service; /** * @param PendingChangesService $pending_changes_service */ public function __construct(PendingChangesService $pending_changes_service) { $this->pending_changes_service = $pending_changes_service; } /** * @param ServerRequestInterface $request * * @return ResponseInterface */ public function handle(ServerRequestInterface $request): ResponseInterface { $tree = Validator::attributes($request)->tree(); $xref = Validator::attributes($request)->isXref()->string('xref', ''); $record = Registry::gedcomRecordFactory()->make($xref, $tree); if ($record) { if ($record->isPendingDeletion()) { /* I18N: %s is the name of a genealogy record */ FlashMessages::addMessage(I18N::translate('ā€œ%sā€ has been deleted.', $record->fullName())); } else { /* I18N: %s is the name of a genealogy record */ FlashMessages::addMessage(I18N::translate('The changes to ā€œ%sā€ have been accepted.', $record->fullName())); } $this->pending_changes_service->acceptRecord($record); } return response(); } }