update1111

This commit is contained in:
Flatlogic Bot 2026-05-03 10:26:26 +00:00
parent d6a91619f4
commit 80416b952b
2 changed files with 186 additions and 2 deletions

View File

@ -14,7 +14,23 @@ if (PHP_SAPI !== 'cli') {
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/DatabaseInstaller.php';
require_once __DIR__ . '/includes/wablas_helper.php';
$wablasHelperPath = __DIR__ . '/includes/wablas_helper.php';
if (!is_file($wablasHelperPath)) {
$message = 'Wablas helper is missing from this deployment: includes/wablas_helper.php';
@file_put_contents(
__DIR__ . '/runtime_debug.log',
date('Y-m-d H:i:s') . " || [cron_wablas_missing_helper] || {$message}" . PHP_EOL,
FILE_APPEND
);
if (PHP_SAPI !== 'cli') {
http_response_code(503);
header('Content-Type: text/plain; charset=utf-8');
header('X-Robots-Tag: noindex, nofollow');
}
exit($message . PHP_EOL);
}
require_once $wablasHelperPath;
DatabaseInstaller::ensureCurrentSchema();

170
index.php
View File

@ -301,11 +301,179 @@ if (isset($_GET['action']) && $_GET['action'] === 'download_items_template') {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
app_debug_file_log('post_debug.log', date('Y-m-d H:i:s') . " - POST: " . json_encode($_POST));
}
if (!function_exists('wablas_helper_missing_message')) {
function wablas_helper_missing_message(): string {
return 'Wablas integration is temporarily unavailable because includes/wablas_helper.php is missing from this deployment.';
}
}
if (!function_exists('register_wablas_helper_fallback')) {
function register_wablas_helper_fallback(string $missingPath): void {
$GLOBALS['app_wablas_helper_missing'] = $missingPath;
runtime_debug_boot_mark('boot:wablas_helper_fallback', [
'missing' => basename($missingPath),
]);
@file_put_contents(
__DIR__ . '/runtime_debug.log',
date('Y-m-d H:i:s') . " || [wablas_helper_fallback] || Missing include={$missingPath} || uri=" . ($_SERVER['REQUEST_URI'] ?? 'cli') . PHP_EOL,
FILE_APPEND
);
if (!function_exists('wablasHelperAvailable')) {
function wablasHelperAvailable(): bool {
return false;
}
}
if (!function_exists('wablasSettingValue')) {
function wablasSettingValue(string $key, ?string $default = null): ?string {
return $default;
}
}
if (!function_exists('wablasNumbersFromText')) {
function wablasNumbersFromText(string $rawNumbers, string $defaultCountryCode = ''): array {
$parts = preg_split('/[\s,;]+/', str_replace(["\r", "\n", "\t"], ' ', $rawNumbers)) ?: [];
$normalized = [];
$defaultCountryCode = preg_replace('/[^0-9]/', '', $defaultCountryCode);
foreach ($parts as $part) {
$candidate = trim((string)$part);
if ($candidate === '') {
continue;
}
$candidate = preg_replace('/[^0-9+]/', '', $candidate);
if ($candidate === '') {
continue;
}
if (str_starts_with($candidate, '00')) {
$candidate = '+' . substr($candidate, 2);
}
if ($candidate[0] !== '+' && $defaultCountryCode !== '') {
$candidate = '+' . $defaultCountryCode . ltrim($candidate, '0');
}
$normalized[] = $candidate;
}
return array_values(array_unique(array_filter($normalized)));
}
}
if (!function_exists('wablasNow')) {
function wablasNow(): DateTimeImmutable {
return new DateTimeImmutable('now', new DateTimeZone(date_default_timezone_get()));
}
}
if (!function_exists('wablasSendManualTest')) {
function wablasSendManualTest(array $numbers, string $message): array {
return [
'success' => false,
'error' => wablas_helper_missing_message(),
];
}
}
if (!function_exists('wablasQueueDailySummaryIfDue')) {
function wablasQueueDailySummaryIfDue(?DateTimeImmutable $now = null): array {
return [
'queued' => false,
'reason' => 'helper_missing',
'error' => wablas_helper_missing_message(),
];
}
}
if (!function_exists('wablasProcessDueDispatches')) {
function wablasProcessDueDispatches(int $limit = 20): array {
return [
'success' => false,
'checked' => 0,
'sent' => 0,
'failed' => 0,
'skipped' => 0,
'messages' => [wablas_helper_missing_message()],
];
}
}
if (!function_exists('wablasQueueInvoiceNotification')) {
function wablasQueueInvoiceNotification(int $invoiceId): array {
return [
'success' => false,
'notice' => ' WhatsApp notification was skipped because includes/wablas_helper.php is missing from this deployment.',
];
}
}
if (!function_exists('wablasDispatchLogTableReady')) {
function wablasDispatchLogTableReady(): bool {
return false;
}
}
if (!function_exists('wablasFetchRecentDispatchLogs')) {
function wablasFetchRecentDispatchLogs(int $limit = 25): array {
return [];
}
}
if (!function_exists('wablasDispatchEventLabel')) {
function wablasDispatchEventLabel(string $eventType): string {
return ucfirst(str_replace('_', ' ', $eventType));
}
}
if (!function_exists('wablasDispatchStatusMeta')) {
function wablasDispatchStatusMeta(string $status): array {
$status = strtolower(trim($status));
if ($status === '') {
$status = 'pending';
}
$meta = [
'label' => ucfirst($status),
'class' => 'text-bg-light border',
];
if ($status === 'sent') {
$meta['class'] = 'bg-success bg-opacity-10 text-success';
} elseif ($status === 'failed') {
$meta['class'] = 'bg-danger bg-opacity-10 text-danger';
} elseif ($status === 'pending') {
$meta['class'] = 'bg-warning bg-opacity-10 text-warning';
}
return $meta;
}
}
if (!function_exists('wablasJsonDecode')) {
function wablasJsonDecode(?string $json): array {
$decoded = json_decode((string)$json, true);
return is_array($decoded) ? $decoded : [];
}
}
}
}
runtime_debug_boot_mark('boot:loading_core_dependencies');
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/SimpleXLSX.php';
require_once __DIR__ . '/includes/stock_helper.php';
require_once __DIR__ . '/includes/wablas_helper.php';
$wablasHelperPath = __DIR__ . '/includes/wablas_helper.php';
if (is_file($wablasHelperPath)) {
require_once $wablasHelperPath;
} else {
register_wablas_helper_fallback($wablasHelperPath);
}
require_once __DIR__ . '/db/BackupService.php';
runtime_debug_boot_mark('boot:core_dependencies_loaded');