This commit is contained in:
Jacek
2026-03-16 10:01:47 +01:00
parent 7f85a57c0d
commit 45e768d083
6 changed files with 283 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -19,4 +19,9 @@ $config['trustmate']['enabled'] = true;
$config['trustmate']['uid'] = '34eb36ba-c715-4cdc-8707-22376c9f14c7';
$config['cron_key'] = 'Gi7FzWtkry19hZ1BqT1LKEWfwokQpigh';
$database_inst['host_remote'] = 'host700513.hostido.net.pl';
$database_inst['user'] = 'host700513_pomysloweprezenty-pl';
$database_inst['password'] = 'QBVbveHAzR78UN8pc7Um';
$database_inst['name'] = 'host700513_pomysloweprezenty-pl';
?>

81
temp/diagnose_apilo.php Normal file
View File

@@ -0,0 +1,81 @@
<?php
/**
* Diagnostic script for Apilo integration on the instance DB
* Temporary — delete after diagnosis
*/
$db_host = 'host700513.hostido.net.pl';
$db_user = 'host700513_pomysloweprezenty-pl';
$db_pass = 'QBVbveHAzR78UN8pc7Um';
$db_name = 'host700513_pomysloweprezenty-pl';
$pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8", $db_user, $db_pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "=== 1. APILO SETTINGS ===\n";
$stmt = $pdo->query("SELECT name, LEFT(value, 200) as value FROM pp_shop_apilo_settings ORDER BY name");
foreach ($stmt as $row) {
echo sprintf(" %-35s = %s\n", $row['name'], $row['value']);
}
echo "\n=== 2. PENDING ORDERS (apilo_order_id IS NULL) ===\n";
$stmt = $pdo->query("SELECT COUNT(*) as cnt FROM pp_shop_orders WHERE apilo_order_id IS NULL");
$row = $stmt->fetch();
echo " Total with NULL: " . $row['cnt'] . "\n";
$stmt = $pdo->query("SELECT id, date_order, status, apilo_order_id FROM pp_shop_orders WHERE apilo_order_id IS NULL ORDER BY date_order DESC LIMIT 10");
echo " Last 10 NULL orders:\n";
foreach ($stmt as $row) {
echo sprintf(" #%s date=%s status=%s\n", $row['id'], $row['date_order'], $row['status']);
}
echo "\n=== 3. FAILED ORDERS (apilo_order_id = -1) ===\n";
$stmt = $pdo->query("SELECT COUNT(*) as cnt FROM pp_shop_orders WHERE apilo_order_id = -1");
$row = $stmt->fetch();
echo " Total with -1: " . $row['cnt'] . "\n";
$stmt = $pdo->query("SELECT id, date_order, status FROM pp_shop_orders WHERE apilo_order_id = -1 ORDER BY date_order DESC LIMIT 10");
echo " Last 10 failed orders:\n";
foreach ($stmt as $row) {
echo sprintf(" #%s date=%s status=%s\n", $row['id'], $row['date_order'], $row['status']);
}
echo "\n=== 4. SKIPPED ORDERS (apilo_order_id = -2) ===\n";
$stmt = $pdo->query("SELECT COUNT(*) as cnt FROM pp_shop_orders WHERE apilo_order_id = -2");
$row = $stmt->fetch();
echo " Total with -2: " . $row['cnt'] . "\n";
echo "\n=== 5. RECENT APILO LOGS (pp_log) ===\n";
$stmt = $pdo->query("SELECT id, action, order_id, message, date FROM pp_log WHERE action LIKE '%apilo%' OR action LIKE '%send_order%' OR action LIKE '%token%' OR action LIKE '%keepalive%' ORDER BY id DESC LIMIT 20");
$rows = $stmt->fetchAll();
if (empty($rows)) {
echo " No Apilo logs found in pp_log\n";
// Try broader search
$stmt = $pdo->query("SELECT id, action, order_id, message, date FROM pp_log ORDER BY id DESC LIMIT 10");
$rows = $stmt->fetchAll();
echo " Last 10 logs (any type):\n";
}
foreach ($rows as $row) {
echo sprintf(" [%s] #%s action=%s order=%s msg=%s\n", $row['date'], $row['id'], $row['action'], $row['order_id'], substr($row['message'], 0, 120));
}
echo "\n=== 6. CRON JOBS STATUS ===\n";
$stmt = $pdo->query("SELECT job_type, status, COUNT(*) as cnt FROM pp_cron_jobs GROUP BY job_type, status ORDER BY job_type, status");
echo " Job type / status / count:\n";
foreach ($stmt as $row) {
echo sprintf(" %-30s %-12s %s\n", $row['job_type'], $row['status'], $row['cnt']);
}
echo "\n=== 7. RECENT CRON EXECUTIONS ===\n";
$stmt = $pdo->query("SELECT id, job_type, status, created_at, processed_at FROM pp_cron_jobs ORDER BY id DESC LIMIT 15");
foreach ($stmt as $row) {
echo sprintf(" #%s type=%s status=%s created=%s processed=%s\n", $row['id'], $row['job_type'], $row['status'], $row['created_at'], $row['processed_at']);
}
echo "\n=== 8. SUCCESSFULLY SENT ORDERS (last 5) ===\n";
$stmt = $pdo->query("SELECT id, date_order, apilo_order_id, status FROM pp_shop_orders WHERE apilo_order_id > 0 ORDER BY date_order DESC LIMIT 5");
foreach ($stmt as $row) {
echo sprintf(" #%s date=%s apilo_id=%s status=%s\n", $row['id'], $row['date_order'], $row['apilo_order_id'], $row['status']);
}
echo "\nDone.\n";

49
temp/diagnose_apilo2.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
$pdo = new PDO("mysql:host=host700513.hostido.net.pl;dbname=host700513_pomysloweprezenty-pl;charset=utf8", 'host700513_pomysloweprezenty-pl', 'QBVbveHAzR78UN8pc7Um');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "=== CRON JOBS TABLE COLUMNS ===\n";
$stmt = $pdo->query("DESCRIBE pp_cron_jobs");
foreach ($stmt as $row) echo " " . $row['Field'] . " (" . $row['Type'] . ")\n";
echo "\n=== RECENT CRON JOBS (last 20) ===\n";
$stmt = $pdo->query("SELECT * FROM pp_cron_jobs ORDER BY id DESC LIMIT 20");
foreach ($stmt as $row) {
echo " #" . $row['id'] . " type=" . $row['job_type'] . " status=" . $row['status'] . " created=" . ($row['created_at'] ?? $row['date'] ?? 'n/a') . "\n";
}
echo "\n=== PENDING CRON JOBS ===\n";
$stmt = $pdo->query("SELECT * FROM pp_cron_jobs WHERE status = 'pending' ORDER BY id");
foreach ($stmt as $row) {
echo " #" . $row['id'] . " type=" . $row['job_type'];
foreach ($row as $k => $v) if ($v !== null && $k !== 'id' && $k !== 'job_type') echo " $k=$v";
echo "\n";
}
echo "\n=== NULL ORDERS SINCE 2026-03-15 (after last successful sync) ===\n";
$stmt = $pdo->query("SELECT id, date_order, status FROM pp_shop_orders WHERE apilo_order_id IS NULL AND date_order >= '2026-03-15 14:00:00' ORDER BY date_order ASC");
$rows = $stmt->fetchAll();
echo " Count: " . count($rows) . "\n";
foreach ($rows as $row) {
echo sprintf(" #%s date=%s status=%s\n", $row['id'], $row['date_order'], $row['status']);
}
echo "\n=== NULL ORDERS COUNT BY DATE RANGE ===\n";
$stmt = $pdo->query("SELECT
SUM(CASE WHEN date_order >= '2026-03-15 14:00:00' THEN 1 ELSE 0 END) as since_break,
SUM(CASE WHEN date_order >= '2024-08-20' AND date_order < '2026-03-15 14:00:00' THEN 1 ELSE 0 END) as before_break_after_sync_start,
SUM(CASE WHEN date_order < '2024-08-20' THEN 1 ELSE 0 END) as before_sync_start
FROM pp_shop_orders WHERE apilo_order_id IS NULL");
$row = $stmt->fetch();
echo " Since break (2026-03-15 14:00+): " . $row['since_break'] . "\n";
echo " Before break, after sync_start: " . $row['before_break_after_sync_start'] . "\n";
echo " Before sync_start (2024-08-20): " . $row['before_sync_start'] . "\n";
echo "\n=== LAST SUCCESSFUL SEND ORDER JOB ===\n";
$stmt = $pdo->query("SELECT * FROM pp_cron_jobs WHERE job_type = 'apilo_send_order' AND status = 'completed' ORDER BY id DESC LIMIT 3");
foreach ($stmt as $row) {
foreach ($row as $k => $v) if ($v !== null) echo " $k=$v";
echo "\n";
}
echo "\nDone.\n";

77
temp/fix_apilo_queue.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
/**
* Fix stuck Apilo cron jobs on the instance after deploying the closure fix.
* Run once after uploading the fixed cron.php.
*
* Temporary — delete after use.
*/
$pdo = new PDO("mysql:host=host700513.hostido.net.pl;dbname=host700513_pomysloweprezenty-pl;charset=utf8", 'host700513_pomysloweprezenty-pl', 'QBVbveHAzR78UN8pc7Um');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "=== BEFORE FIX ===\n";
$stmt = $pdo->query("SELECT job_type, status, COUNT(*) as cnt FROM pp_cron_jobs WHERE status IN ('pending','processing','failed') GROUP BY job_type, status ORDER BY job_type");
foreach ($stmt as $row) {
echo " {$row['job_type']} {$row['status']} {$row['cnt']}\n";
}
// 1. Reset the stuck apilo_send_order job (attempts back to 0, clear error)
echo "\n=== Resetting apilo_send_order pending jobs ===\n";
$stmt = $pdo->prepare("UPDATE pp_cron_jobs SET attempts = 0, last_error = NULL, scheduled_at = NOW() WHERE job_type = 'apilo_send_order' AND status = 'pending'");
$stmt->execute();
echo " Reset {$stmt->rowCount()} apilo_send_order jobs\n";
// 2. Reset token keepalive failed jobs
echo "\n=== Resetting apilo_token_keepalive failed jobs ===\n";
$stmt = $pdo->prepare("UPDATE pp_cron_jobs SET attempts = 0, last_error = NULL, status = 'pending', scheduled_at = NOW() WHERE job_type = 'apilo_token_keepalive' AND status = 'failed'");
$stmt->execute();
echo " Reset {$stmt->rowCount()} token keepalive jobs\n";
// 3. Cancel sync_payment and sync_status jobs for orders that haven't been sent yet
// (these orders have apilo_order_id = NULL so sync is pointless — they'll be re-queued after order is sent)
echo "\n=== Cancelling premature sync jobs for unsent orders ===\n";
$stmt = $pdo->query("
SELECT cj.id, cj.job_type, cj.payload
FROM pp_cron_jobs cj
WHERE cj.status = 'pending'
AND cj.job_type IN ('apilo_sync_payment', 'apilo_sync_status')
");
$to_cancel = [];
foreach ($stmt as $row) {
$payload = json_decode($row['payload'], true);
$order_id = $payload['order_id'] ?? 0;
// Check if this order has been sent to Apilo
$check = $pdo->prepare("SELECT apilo_order_id FROM pp_shop_orders WHERE id = ?");
$check->execute([$order_id]);
$order = $check->fetch();
if ($order && ($order['apilo_order_id'] === null || (int)$order['apilo_order_id'] <= 0)) {
$to_cancel[] = $row['id'];
}
}
if ($to_cancel) {
$ids = implode(',', $to_cancel);
$pdo->exec("UPDATE pp_cron_jobs SET status = 'cancelled' WHERE id IN ($ids)");
echo " Cancelled " . count($to_cancel) . " premature sync jobs\n";
} else {
echo " No premature sync jobs to cancel\n";
}
// 4. Reset failed product_sync, pricelist_sync, status_poll jobs
echo "\n=== Resetting other failed Apilo jobs ===\n";
$stmt = $pdo->prepare("UPDATE pp_cron_jobs SET attempts = 0, last_error = NULL, scheduled_at = NOW() WHERE job_type IN ('apilo_product_sync', 'apilo_pricelist_sync', 'apilo_status_poll') AND status = 'pending'");
$stmt->execute();
echo " Reset {$stmt->rowCount()} other Apilo pending jobs\n";
echo "\n=== AFTER FIX ===\n";
$stmt = $pdo->query("SELECT job_type, status, COUNT(*) as cnt FROM pp_cron_jobs WHERE status IN ('pending','processing','failed') GROUP BY job_type, status ORDER BY job_type");
foreach ($stmt as $row) {
echo " {$row['job_type']} {$row['status']} {$row['cnt']}\n";
}
echo "\n=== ORDERS NEEDING SEND (apilo_order_id IS NULL, after sync_start) ===\n";
$stmt = $pdo->query("SELECT COUNT(*) as cnt FROM pp_shop_orders WHERE apilo_order_id IS NULL AND date_order >= '2024-08-20'");
$row = $stmt->fetch();
echo " " . $row['cnt'] . " orders to send\n";
echo " (cron processes 1 per run, should catch up within " . $row['cnt'] . " cron cycles)\n";
echo "\nDone. Deploy fixed cron.php to instance, then run this script.\n";

View File

@@ -0,0 +1,70 @@
<?php
/**
* Rebuild changelog-data.html from docs/CHANGELOG.md
* One-time script — delete after use.
*/
$md = file_get_contents(__DIR__ . '/../docs/CHANGELOG.md');
$lines = explode("\n", $md);
$entries = [];
$currentVersion = null;
$currentDate = null;
$currentLines = [];
foreach ($lines as $line) {
// Match: ## ver. 0.341 (2026-03-16) - Description here
if (preg_match('/^## ver\. ([\d.]+) \((\d{4}-\d{2}-\d{2})\) - (.+)$/', $line, $m)) {
// Save previous entry
if ($currentVersion !== null) {
$entries[] = [
'version' => $currentVersion,
'date' => $currentDate,
'lines' => $currentLines,
];
}
$currentVersion = $m[1];
$currentDate = $m[2];
$currentLines = [];
} elseif ($currentVersion !== null && trim($line) !== '' && trim($line) !== '---') {
// Clean markdown formatting for HTML
$clean = $line;
$clean = preg_replace('/^\- \*\*([A-Z]+)\*\*: /', '$1 - ', $clean);
$clean = preg_replace('/`([^`]+)`/', '$1', $clean);
$clean = str_replace(['**', '__'], '', $clean);
$clean = trim($clean);
if ($clean) {
$currentLines[] = $clean;
}
}
}
// Last entry
if ($currentVersion !== null) {
$entries[] = [
'version' => $currentVersion,
'date' => $currentDate,
'lines' => $currentLines,
];
}
// Build HTML
$html = '';
foreach ($entries as $entry) {
$dateParts = explode('-', $entry['date']);
$dateFormatted = $dateParts[2] . '.' . $dateParts[1] . '.' . $dateParts[0];
$desc = implode("\n", $entry['lines']);
$desc = htmlspecialchars($desc, ENT_QUOTES, 'UTF-8');
$html .= '<b>ver. ' . $entry['version'] . ' - ' . $dateFormatted . '</b><br />' . "\n";
$html .= $desc . "\n";
$html .= '<hr>' . "\n";
}
$outPath = __DIR__ . '/../updates/changelog-data.html';
file_put_contents($outPath, $html);
$size = filesize($outPath);
echo "Generated " . count($entries) . " entries\n";
echo "File size: " . number_format($size) . " bytes\n";
echo "Output: $outPath\n";