<?php
/**
 * Clear old hero copy; brand = آبلیموی شیراز
 * php run-update-lemon-hero-settings.php
 */
declare(strict_types=1);

define('ACC_BASE_PATH', __DIR__);
require_once __DIR__ . '/standalone/bootstrap.php';
require_once ACC_PATH . 'includes/helpers/arag-shop.php';

global $wpdb;
$t = $wpdb->prefix . 'arag_shop_settings';
$exists = $wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $t));
if (!$exists) {
    echo "No table {$t}\n";
    exit(0);
}

$data = [
    'brand_name'       => 'آبلیموی شیراز',
    'platform_tagline' => 'فروشگاه آبلیموی شیراز',
    'hero_eyebrow'     => '',
    'hero_title'       => 'آبلیموی شیراز',
    'hero_subtitle'    => '',
];

$cols = $wpdb->get_col("DESCRIBE `{$t}`", 0);
$payload = [];
foreach ($data as $k => $v) {
    if (in_array($k, $cols, true)) {
        $payload[$k] = $v;
    }
}

$r = $wpdb->update($t, $payload, ['id' => 1]);
echo "updated=" . var_export($r, true) . "\n";
$row = $wpdb->get_row("SELECT brand_name, hero_title, hero_subtitle, hero_eyebrow, platform_tagline FROM `{$t}` WHERE id=1", ARRAY_A);
echo json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n";
