Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions app/Http/RequestHandlers/TelemetryPreviewPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* 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 Fisharebest\Webtrees\Http\RequestHandlers;

use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\TelemetryDataService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function json_encode;

use const JSON_PRETTY_PRINT;
use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final class TelemetryPreviewPage implements RequestHandlerInterface
{
use ViewResponseTrait;

public function __construct(
private readonly TelemetryDataService $telemetry_data_service,
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->layout = 'layouts/administration';

$payload = $this->telemetry_data_service->assemblePayload();
$json = json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

$title = I18N::translate('Telemetry data preview');

return $this->viewResponse('admin/telemetry-preview', [
'title' => $title,
'payload' => $json,
]);
}
}
47 changes: 47 additions & 0 deletions app/Http/RequestHandlers/TelemetrySettingsAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* 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 Fisharebest\Webtrees\Http\RequestHandlers;

use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Site;
use Fisharebest\Webtrees\Validator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function redirect;
use function route;

final class TelemetrySettingsAction implements RequestHandlerInterface
{
public function handle(ServerRequestInterface $request): ResponseInterface
{
$endpointUrl = Validator::parsedBody($request)->string('TELEMETRY_ENDPOINT_URL');
$publishableKey = Validator::parsedBody($request)->string('TELEMETRY_PUBLISHABLE_KEY');

Site::setPreference('TELEMETRY_ENDPOINT_URL', $endpointUrl);
Site::setPreference('TELEMETRY_PUBLISHABLE_KEY', $publishableKey);

FlashMessages::addMessage(I18N::translate('The telemetry settings have been updated.'), 'success');

return redirect(route(ControlPanel::class));
}
}
45 changes: 45 additions & 0 deletions app/Http/RequestHandlers/TelemetrySettingsPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* 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 Fisharebest\Webtrees\Http\RequestHandlers;

use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Site;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

final class TelemetrySettingsPage implements RequestHandlerInterface
{
use ViewResponseTrait;

public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->layout = 'layouts/administration';

$title = I18N::translate('Telemetry settings');

return $this->viewResponse('admin/telemetry-settings', [
'title' => $title,
'endpoint_url' => Site::getPreference('TELEMETRY_ENDPOINT_URL') ?: 'https://vjdwtasmykejamkdprro.supabase.co',
'publishable_key' => Site::getPreference('TELEMETRY_PUBLISHABLE_KEY') ?: 'sb_publishable_mzCwYJ8Fs2yjE2gvQgDDeg_Vwpj5uDQ',
]);
}
}
86 changes: 86 additions & 0 deletions app/Http/RequestHandlers/TelemetrySubmitAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* webtrees: online genealogy
* Copyright (C) 2026 webtrees development team
* 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 Fisharebest\Webtrees\Http\RequestHandlers;

use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Services\TelemetryDataService;
use Fisharebest\Webtrees\Site;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function json_encode;
use function redirect;
use function route;

use const JSON_UNESCAPED_SLASHES;
use const JSON_UNESCAPED_UNICODE;

final class TelemetrySubmitAction implements RequestHandlerInterface
{
public function __construct(
private readonly TelemetryDataService $telemetry_data_service,
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$payload = $this->telemetry_data_service->assemblePayload();
$json = json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

$endpointUrl = Site::getPreference('TELEMETRY_ENDPOINT_URL') ?: 'https://vjdwtasmykejamkdprro.supabase.co';
$publishableKey = Site::getPreference('TELEMETRY_PUBLISHABLE_KEY') ?: 'sb_publishable_mzCwYJ8Fs2yjE2gvQgDDeg_Vwpj5uDQ';

$url = rtrim($endpointUrl, '/') . '/rest/v1/rpc/submit_webtrees_telemetry';

try {
$client = new Client([
'timeout' => 15,
]);

$client->post($url, [
'headers' => [
'Content-Type' => 'application/json',
'apikey' => $publishableKey,
'Authorization' => 'Bearer ' . $publishableKey,
'Prefer' => 'return=minimal',
],
'body' => $json,
]);

FlashMessages::addMessage(I18N::translate('Telemetry data has been sent successfully. Thank you!'), 'success');
} catch (GuzzleException $exception) {
$errorDetail = '';
if ($exception instanceof RequestException && $exception->getResponse() !== null) {
$errorDetail = (string) $exception->getResponse()->getBody();
}
if ($errorDetail === '') {
$errorDetail = $exception->getMessage();
}
FlashMessages::addMessage(I18N::translate('Failed to send telemetry data.') . ' ' . $errorDetail, 'danger');
}

return redirect(route(ControlPanel::class));
}
}
8 changes: 8 additions & 0 deletions app/Http/Routes/WebRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@
use Fisharebest\Webtrees\Http\RequestHandlers\SubmissionPage;
use Fisharebest\Webtrees\Http\RequestHandlers\SubmitterPage;
use Fisharebest\Webtrees\Http\RequestHandlers\SynchronizeTrees;
use Fisharebest\Webtrees\Http\RequestHandlers\TelemetryPreviewPage;
use Fisharebest\Webtrees\Http\RequestHandlers\TelemetrySettingsAction;
use Fisharebest\Webtrees\Http\RequestHandlers\TelemetrySettingsPage;
use Fisharebest\Webtrees\Http\RequestHandlers\TelemetrySubmitAction;
use Fisharebest\Webtrees\Http\RequestHandlers\TomSelectFamily;
use Fisharebest\Webtrees\Http\RequestHandlers\TomSelectIndividual;
use Fisharebest\Webtrees\Http\RequestHandlers\TomSelectLocation;
Expand Down Expand Up @@ -445,6 +449,10 @@ public function load(Map $router): void
$router->post(SiteRegistrationAction::class, '/site-registration');
$router->get(SiteTagsPage::class, '/tags');
$router->post(SiteTagsAction::class, '/tags');
$router->get(TelemetryPreviewPage::class, '/telemetry-preview');
$router->post(TelemetrySubmitAction::class, '/telemetry-submit');
$router->get(TelemetrySettingsPage::class, '/telemetry-settings');
$router->post(TelemetrySettingsAction::class, '/telemetry-settings');
$router->get(TreePageDefaultEdit::class, '/trees/default-blocks');
$router->post(TreePageDefaultUpdate::class, '/trees/default-blocks');
$router->get(MergeTreesPage::class, '/trees/merge');
Expand Down
Loading
Loading