feat: Enable search engine indexing for sites and update related configurations

This commit is contained in:
2026-03-04 14:02:20 +01:00
parent 207edca896
commit 7ff7ff3a92
7 changed files with 157 additions and 3 deletions

1
.env
View File

@@ -1,4 +1,5 @@
DB_HOST=localhost
DB_HOST_REMOTE=host700513.hostido.net.pl
DB_NAME=host700513_backpro
DB_USER=host700513_backpro
DB_PASS=Mq9wH2B8KPeQh2wQ32Ya

View File

@@ -1,5 +1,20 @@
# Repository Guidelines
## Zasady pisania kodu
- Kod ma być czytelny „dla obcego”: jasne nazwy, mało magii
- Brak „skrótów na szybko” typu logika w widokach, copy-paste, losowe helpery bez spójności
- Każda funkcja/klasa ma mieć jedną odpowiedzialność, zwykle do 3050 linii (jeśli dłuższe dzielić)
- max 3 poziomy zagnieżdżeń (if/foreach), reszta do osobnych metod
- Nazewnictwo:
- klasy: PascalCase
- metody/zmienne: camelCase
- stałe: UPPER_SNAKE_CASE
- Zero „skrótologii” w nazwach (np. $d, $tmp, $x1) poza pętlami 23 linijki
- medoo + prepared statements bez wyjątków (żadnego sklejania SQL stringiem)
- XSS: escape w widokach (np. helper e())
- CSRF dla formularzy, sensowna obsługa sesji
- Kod ma mieć komentarze tylko tam, gdzie wyjaśniają „dlaczego”, nie „co”
## Project Structure & Module Organization
BackPRO is a custom PHP MVC application (no Laravel/Symfony). Main code lives in `src/` under PSR-4 namespace `App\\`.
- `src/Core/`: bootstrap, routing, base controller/model, config/auth helpers.

60
cron/enable-indexing.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
$basePath = dirname(__DIR__);
try {
require_once $basePath . '/vendor/autoload.php';
\App\Core\Config::load($basePath);
\App\Helpers\Logger::setBasePath($basePath);
$sites = \App\Models\Site::findAll('id ASC');
if (empty($sites)) {
echo "Brak stron do aktualizacji.\n";
exit(0);
}
$wordpress = new \App\Services\WordPressService();
$success = 0;
$failed = 0;
foreach ($sites as $site) {
$siteId = (int) ($site['id'] ?? 0);
$siteName = (string) ($site['name'] ?? 'bez-nazwy');
$siteUrl = (string) ($site['url'] ?? '');
$result = $wordpress->enableSearchEngineIndexing($site);
$isSuccess = !empty($result['success']);
$message = (string) ($result['message'] ?? 'brak komunikatu');
if ($isSuccess) {
$success++;
} else {
$failed++;
}
echo sprintf(
"[%s] site_id=%d, status=%s, site=%s, url=%s, message=%s\n",
date('Y-m-d H:i:s'),
$siteId,
$isSuccess ? 'ok' : 'error',
$siteName,
$siteUrl,
$message
);
}
$summary = "Indexing fix summary: success={$success}, failed={$failed}";
\App\Helpers\Logger::info($summary, 'installer');
echo $summary . "\n";
} catch (\Throwable $e) {
$message = 'Enable indexing cron error: ' . $e->getMessage();
echo $message . "\n";
if (class_exists(\App\Helpers\Logger::class)) {
\App\Helpers\Logger::error($message, 'installer');
}
exit(1);
}

View File

@@ -469,7 +469,7 @@ PHP;
'admin_password' => $config['admin_pass'],
'admin_password2' => $config['admin_pass'],
'admin_email' => $config['admin_email'],
'blog_public' => 0,
'blog_public' => 1,
],
'timeout' => 60,
'allow_redirects' => true,

View File

@@ -12,7 +12,7 @@ class WordPressService
{
private const BACKPRO_MU_PLUGIN_FILENAME = 'backpro-remote-tools.php';
private const BACKPRO_REMOTE_SERVICE_FILENAME = 'backpro-remote-service.php';
private const BACKPRO_REMOTE_SERVICE_VERSION = '1.3.0';
private const BACKPRO_REMOTE_SERVICE_VERSION = '1.4.0';
private const BACKPRO_NEWS_THEME_SLUG = 'backpro-news-mag';
private const BACKPRO_NEWS_THEME_SOURCE_DIR = 'assets/wp-theme-backpro-news';
private Client $client;
@@ -434,6 +434,41 @@ class WordPressService
return ['success' => false, 'message' => (string) ($retry['message'] ?? 'Blad zmiany permalink.')];
}
public function enableSearchEngineIndexing(array $site): array
{
$result = $this->callRemoteService($site, 'set_blog_public', ['blog_public' => '1']);
if (!empty($result['success'])) {
return [
'success' => true,
'blog_public' => (int) ($result['blog_public'] ?? 1),
'message' => (string) ($result['message'] ?? 'Wlaczono indeksowanie strony.'),
];
}
$ensure = $this->ensureRemoteService($site);
if (empty($ensure['success'])) {
return [
'success' => false,
'message' => (string) ($ensure['message'] ?? $result['message'] ?? 'Brak endpointu BackPRO na WordPress.'),
];
}
$refreshedSite = !empty($site['id']) ? (Site::find((int) $site['id']) ?: $site) : $site;
$retry = $this->callRemoteService($refreshedSite, 'set_blog_public', ['blog_public' => '1']);
if (!empty($retry['success'])) {
return [
'success' => true,
'blog_public' => (int) ($retry['blog_public'] ?? 1),
'message' => (string) ($retry['message'] ?? 'Wlaczono indeksowanie strony.'),
];
}
return [
'success' => false,
'message' => (string) ($retry['message'] ?? 'Nie udalo sie wlaczyc indeksowania strony.'),
];
}
public function ensureRemoteService(array $site): array
{
$siteData = $this->prepareRemoteServiceMetadata($site);
@@ -1047,7 +1082,7 @@ if (!defined('ABSPATH')) {
\$action = (string) (\$_POST['action'] ?? '');
if (\$action === 'ping') {
echo json_encode(['success' => true, 'message' => 'pong', 'version' => '1.3.0']);
echo json_encode(['success' => true, 'message' => 'pong', 'version' => '1.4.0']);
exit;
}
@@ -1117,6 +1152,23 @@ if (\$action === 'activate_theme') {
exit;
}
if (\$action === 'set_blog_public') {
\$blogPublicRaw = (string) (\$_POST['blog_public'] ?? '1');
\$blogPublic = \$blogPublicRaw === '0' ? 0 : 1;
update_option('blog_public', \$blogPublic);
\$applied = (int) get_option('blog_public', 1);
echo json_encode([
'success' => true,
'blog_public' => \$applied,
'message' => \$applied === 1
? 'Indeksowanie przez wyszukiwarki jest wlaczone.'
: 'Indeksowanie przez wyszukiwarki jest wylaczone.',
]);
exit;
}
if (\$action === 'cleanup') {
@unlink(__FILE__);
echo json_encode(['success' => true, 'message' => 'service_deleted']);

View File

@@ -0,0 +1,14 @@
[2026-03-04 13:18:31] ERROR: Enable indexing cron error: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:21:38] ERROR: Enable indexing cron error: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:22] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:22] INFO: FTP disconnected
[2026-03-04 13:24:27] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:27] INFO: FTP disconnected
[2026-03-04 13:24:31] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:32] INFO: FTP disconnected
[2026-03-04 13:24:36] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:36] INFO: FTP disconnected
[2026-03-04 13:24:40] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:40] INFO: FTP disconnected
[2026-03-04 13:24:45] INFO: FTP connected to host117523.hostido.net.pl
[2026-03-04 13:24:45] INFO: FTP disconnected

View File

@@ -0,0 +1,12 @@
[2026-03-04 13:24:26] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:26] INFO: BackPRO remote service uploaded to https://e-gryfino.pl (/public_html/backpro-remote-service.php)
[2026-03-04 13:24:31] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:31] INFO: BackPRO remote service uploaded to https://euforiamokotow.pl (/public_html/backpro-remote-service.php)
[2026-03-04 13:24:36] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:36] INFO: BackPRO remote service uploaded to https://ladek-zdroj.com.pl (/public_html/backpro-remote-service.php)
[2026-03-04 13:24:40] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:40] INFO: BackPRO remote service uploaded to https://e-kielce.pl (/public_html/backpro-remote-service.php)
[2026-03-04 13:24:44] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:44] INFO: BackPRO remote service uploaded to https://wareteka.pl (/public_html/backpro-remote-service.php)
[2026-03-04 13:24:49] WARNING: Could not persist remote service installation metadata: SQLSTATE[HY000] [2002] Nie można nawiązać połączenia, ponieważ komputer docelowy aktywnie go odmawia
[2026-03-04 13:24:49] INFO: BackPRO remote service uploaded to https://infozabrze.slask.pl (/public_html/backpro-remote-service.php)