if (!function_exists('zvi_b20260804_base_dir')) { function zvi_b20260804_base_dir() { $dir = WP_CONTENT_DIR . '/novamira-sandbox/zvi-backup-20260804'; if (!file_exists($dir)) { wp_mkdir_p($dir); } return $dir; } function zvi_b20260804_state_file() { return zvi_b20260804_base_dir() . '/db-state.json'; } function zvi_b20260804_load_state() { $f = zvi_b20260804_state_file(); if (file_exists($f)) { $s = json_decode(file_get_contents($f), true); if (is_array($s)) return $s; } global $wpdb; $tables = $wpdb->get_col('SHOW TABLES'); sort($tables); return array( 'tables' => $tables, 'table_idx' => 0, 'row_offset' => 0, 'phase' => 'header', 'part_num' => 1, 'part_bytes' => 0, 'ready_parts' => array(), 'done' => false, 'total_rows_written' => 0, ); } function zvi_b20260804_save_state($s) { file_put_contents(zvi_b20260804_state_file(), json_encode($s)); } function zvi_b20260804_part_path($num) { return zvi_b20260804_base_dir() . '/db-part-' . str_pad($num, 4, '0', STR_PAD_LEFT) . '.sql'; } function zvi_b20260804_finalize_part($s) { $raw = zvi_b20260804_part_path($s['part_num']); if (file_exists($raw) && filesize($raw) > 0) { $gz = $raw . '.gz'; $in = fopen($raw, 'rb'); $out = gzopen($gz, 'wb9'); while (!feof($in)) { $chunk = fread($in, 1024 * 1024); if ($chunk !== false && strlen($chunk) > 0) gzwrite($out, $chunk); } fclose($in); gzclose($out); $size = filesize($gz); unlink($raw); $s['ready_parts'][] = array('num' => $s['part_num'], 'path' => $gz, 'size' => $size); } elseif (file_exists($raw)) { unlink($raw); } $s['part_num'] = $s['part_num'] + 1; $s['part_bytes'] = 0; return $s; } function zvi_b20260804_esc($v) { global $wpdb; if ($v === null) return 'NULL'; return "'" . $wpdb->_real_escape($v) . "'"; } function zvi_b20260804_db_step($budget = 22) { global $wpdb; $start = microtime(true); $s = zvi_b20260804_load_state(); $PART_THRESHOLD = 12 * 1024 * 1024; $BATCH = 200; if ($s['done']) { return array('done' => true, 'state' => $s); } while ((microtime(true) - $start) < $budget) { if ($s['table_idx'] >= count($s['tables'])) { $s = zvi_b20260804_finalize_part($s); $s['done'] = true; zvi_b20260804_save_state($s); break; } $table = $s['tables'][$s['table_idx']]; $raw = zvi_b20260804_part_path($s['part_num']); if ($s['phase'] === 'header') { $create = $wpdb->get_row('SHOW CREATE TABLE `' . $table . '`', ARRAY_N); $sql = "\n-- ----------------------------\n-- Table: {$table}\n-- ----------------------------\n"; $sql .= "DROP TABLE IF EXISTS `{$table}`;\n"; $sql .= $create[1] . ";\n\n"; file_put_contents($raw, $sql, FILE_APPEND); $s['part_bytes'] += strlen($sql); $s['phase'] = 'rows'; } if ($s['phase'] === 'rows') { $rows = $wpdb->get_results("SELECT * FROM `{$table}` LIMIT {$s['row_offset']}, {$BATCH}", ARRAY_A); if (empty($rows)) { $s['table_idx'] += 1; $s['row_offset'] = 0; $s['phase'] = 'header'; } else { $cols = array_keys($rows[0]); $colList = '`' . implode('`,`', $cols) . '`'; $valueGroups = array(); foreach ($rows as $row) { $vals = array(); foreach ($cols as $c) { $vals[] = zvi_b20260804_esc($row[$c]); } $valueGroups[] = '(' . implode(',', $vals) . ')'; } $sql = "INSERT INTO `{$table}` ({$colList}) VALUES\n" . implode(",\n", $valueGroups) . ";\n"; file_put_contents($raw, $sql, FILE_APPEND); $s['part_bytes'] += strlen($sql); $s['row_offset'] += count($rows); $s['total_rows_written'] += count($rows); } } if ($s['part_bytes'] >= $PART_THRESHOLD) { $s = zvi_b20260804_finalize_part($s); } zvi_b20260804_save_state($s); } return array( 'done' => $s['done'], 'table_idx' => $s['table_idx'], 'tables_total' => count($s['tables']), 'current_table' => isset($s['tables'][$s['table_idx']]) ? $s['tables'][$s['table_idx']] : null, 'row_offset' => $s['row_offset'], 'part_num' => $s['part_num'], 'ready_parts_count' => count($s['ready_parts']), 'ready_parts' => $s['ready_parts'], 'total_rows_written' => $s['total_rows_written'], 'elapsed' => round(microtime(true) - $start, 2), ); } function zvi_b20260804_clear_ready_parts() { $s = zvi_b20260804_load_state(); $s['ready_parts'] = array(); zvi_b20260804_save_state($s); return true; } } https://www.francophilesanonymes.com/post-sitemap1.xml 2026-08-04T05:32:57+00:00 https://www.francophilesanonymes.com/post-sitemap2.xml 2026-08-03T10:08:10+00:00 https://www.francophilesanonymes.com/post-sitemap3.xml 2026-08-03T08:29:19+00:00 https://www.francophilesanonymes.com/post-sitemap4.xml 2026-08-03T03:52:40+00:00 https://www.francophilesanonymes.com/post-sitemap5.xml 2026-08-02T13:51:17+00:00 https://www.francophilesanonymes.com/post-sitemap6.xml 2026-08-02T13:39:24+00:00 https://www.francophilesanonymes.com/page-sitemap.xml 2026-07-28T12:33:11+00:00 https://www.francophilesanonymes.com/category-sitemap.xml 2026-08-04T05:32:57+00:00 https://www.francophilesanonymes.com/post_tag-sitemap.xml 2026-08-03T10:08:10+00:00