backup: estado antes de limpieza de defaults
This commit is contained in:
281
admin/pages/migration.php
Normal file
281
admin/pages/migration.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin Panel - Theme Options Migration Page
|
||||
*
|
||||
* Interfaz para migrar Theme Options de wp_options a tabla personalizada
|
||||
*
|
||||
* @package Apus_Theme
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Instanciar migrator
|
||||
$migrator = new APUS_Theme_Options_Migrator();
|
||||
|
||||
// Obtener estadísticas
|
||||
$stats = $migrator->get_migration_stats();
|
||||
|
||||
// Procesar acciones
|
||||
$message = '';
|
||||
$message_type = '';
|
||||
|
||||
if (isset($_POST['apus_migrate_action'])) {
|
||||
check_admin_referer('apus_migration_action', 'apus_migration_nonce');
|
||||
|
||||
$action = sanitize_text_field($_POST['apus_migrate_action']);
|
||||
|
||||
switch ($action) {
|
||||
case 'migrate':
|
||||
$result = $migrator->migrate();
|
||||
$message = $result['message'];
|
||||
$message_type = $result['success'] ? 'success' : 'error';
|
||||
|
||||
// Actualizar estadísticas
|
||||
$stats = $migrator->get_migration_stats();
|
||||
break;
|
||||
|
||||
case 'rollback':
|
||||
$backup_name = isset($_POST['backup_name']) ? sanitize_text_field($_POST['backup_name']) : null;
|
||||
$result = $migrator->rollback($backup_name);
|
||||
$message = $result['message'];
|
||||
$message_type = $result['success'] ? 'success' : 'error';
|
||||
|
||||
// Actualizar estadísticas
|
||||
$stats = $migrator->get_migration_stats();
|
||||
break;
|
||||
|
||||
case 'delete_backup':
|
||||
$backup_name = isset($_POST['backup_name']) ? sanitize_text_field($_POST['backup_name']) : '';
|
||||
if ($backup_name && $migrator->delete_backup($backup_name)) {
|
||||
$message = 'Backup eliminado correctamente';
|
||||
$message_type = 'success';
|
||||
} else {
|
||||
$message = 'Error al eliminar backup';
|
||||
$message_type = 'error';
|
||||
}
|
||||
|
||||
// Actualizar estadísticas
|
||||
$stats = $migrator->get_migration_stats();
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||
<p class="description">Migración de Theme Options desde wp_options a tabla personalizada wp_apus_theme_components</p>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="notice notice-<?php echo esc_attr($message_type); ?> is-dismissible">
|
||||
<p><?php echo esc_html($message); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Migration Status Card -->
|
||||
<div class="card mt-4" style="max-width: 800px;">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0">
|
||||
<i class="bi bi-info-circle me-2"></i>
|
||||
Estado de la Migración
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong>Estado:</strong>
|
||||
<?php if ($stats['is_migrated']): ?>
|
||||
<span class="badge bg-success">
|
||||
<i class="bi bi-check-circle me-1"></i>
|
||||
Migrado
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<span class="badge bg-warning text-dark">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>
|
||||
Pendiente
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong>Backups disponibles:</strong>
|
||||
<span class="badge bg-info"><?php echo esc_html($stats['backups_count']); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong>Opciones en wp_options:</strong>
|
||||
<span class="badge bg-secondary"><?php echo esc_html($stats['old_options_count']); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<strong>Configs en tabla nueva:</strong>
|
||||
<span class="badge bg-primary"><?php echo esc_html($stats['new_config_count']); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Progress Bar (si hay migración parcial) -->
|
||||
<?php if (!$stats['is_migrated'] && $stats['new_config_count'] > 0): ?>
|
||||
<div class="progress mt-3" style="height: 25px;">
|
||||
<?php
|
||||
$total = max($stats['old_options_count'], $stats['new_config_count']);
|
||||
$percentage = $total > 0 ? ($stats['new_config_count'] / $total) * 100 : 0;
|
||||
?>
|
||||
<div class="progress-bar bg-warning" role="progressbar"
|
||||
style="width: <?php echo esc_attr($percentage); ?>%;"
|
||||
aria-valuenow="<?php echo esc_attr($percentage); ?>"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100">
|
||||
<?php echo esc_html(round($percentage, 1)); ?>%
|
||||
</div>
|
||||
</div>
|
||||
<small class="text-muted">Migración parcial detectada</small>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons Card -->
|
||||
<div class="card mt-4" style="max-width: 800px;">
|
||||
<div class="card-header bg-secondary text-white">
|
||||
<h5 class="mb-0">
|
||||
<i class="bi bi-gear me-2"></i>
|
||||
Acciones
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (!$stats['is_migrated']): ?>
|
||||
<!-- Migrate Button -->
|
||||
<form method="post" style="display: inline;">
|
||||
<?php wp_nonce_field('apus_migration_action', 'apus_migration_nonce'); ?>
|
||||
<input type="hidden" name="apus_migrate_action" value="migrate">
|
||||
<button type="submit" class="btn btn-primary" onclick="return confirm('¿Está seguro de ejecutar la migración? Se creará un backup automático.');">
|
||||
<i class="bi bi-arrow-right-circle me-1"></i>
|
||||
Ejecutar Migración
|
||||
</button>
|
||||
</form>
|
||||
<p class="text-muted mt-2 mb-0">
|
||||
<small>
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
Se creará un backup automático antes de la migración. Total de configuraciones: <?php echo esc_html($stats['old_options_count']); ?>
|
||||
</small>
|
||||
</p>
|
||||
<?php else: ?>
|
||||
<div class="alert alert-success mb-0">
|
||||
<i class="bi bi-check-circle me-2"></i>
|
||||
La migración ya ha sido completada. Las opciones del tema ahora se leen desde la tabla personalizada.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Backups Card -->
|
||||
<?php if ($stats['backups_count'] > 0): ?>
|
||||
<div class="card mt-4" style="max-width: 800px;">
|
||||
<div class="card-header bg-info text-white">
|
||||
<h5 class="mb-0">
|
||||
<i class="bi bi-archive me-2"></i>
|
||||
Backups Disponibles (<?php echo esc_html($stats['backups_count']); ?>)
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nombre del Backup</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($stats['backups'] as $backup): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<code><?php echo esc_html($backup); ?></code>
|
||||
</td>
|
||||
<td>
|
||||
<!-- Rollback -->
|
||||
<form method="post" style="display: inline;" class="me-2">
|
||||
<?php wp_nonce_field('apus_migration_action', 'apus_migration_nonce'); ?>
|
||||
<input type="hidden" name="apus_migrate_action" value="rollback">
|
||||
<input type="hidden" name="backup_name" value="<?php echo esc_attr($backup); ?>">
|
||||
<button type="submit" class="btn btn-sm btn-warning" onclick="return confirm('¿Está seguro de restaurar este backup? Esto revertirá la migración.');">
|
||||
<i class="bi bi-arrow-counterclockwise me-1"></i>
|
||||
Restaurar
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<!-- Delete -->
|
||||
<form method="post" style="display: inline;">
|
||||
<?php wp_nonce_field('apus_migration_action', 'apus_migration_nonce'); ?>
|
||||
<input type="hidden" name="apus_migrate_action" value="delete_backup">
|
||||
<input type="hidden" name="backup_name" value="<?php echo esc_attr($backup); ?>">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('¿Está seguro de eliminar este backup?');">
|
||||
<i class="bi bi-trash me-1"></i>
|
||||
Eliminar
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Technical Information -->
|
||||
<div class="card mt-4" style="max-width: 800px;">
|
||||
<div class="card-header bg-light">
|
||||
<h5 class="mb-0">
|
||||
<i class="bi bi-code-square me-2"></i>
|
||||
Información Técnica
|
||||
</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-sm-4">Componente:</dt>
|
||||
<dd class="col-sm-8"><code>theme</code></dd>
|
||||
|
||||
<dt class="col-sm-4">Tabla antigua:</dt>
|
||||
<dd class="col-sm-8"><code>wp_options</code> (opción: <code>apus_theme_options</code>)</dd>
|
||||
|
||||
<dt class="col-sm-4">Tabla nueva:</dt>
|
||||
<dd class="col-sm-8"><code>wp_apus_theme_components</code></dd>
|
||||
|
||||
<dt class="col-sm-4">Versión Admin Panel:</dt>
|
||||
<dd class="col-sm-8"><code><?php echo esc_html(APUS_ADMIN_PANEL_VERSION); ?></code></dd>
|
||||
|
||||
<dt class="col-sm-4">Archivo Helper:</dt>
|
||||
<dd class="col-sm-8"><code>inc/theme-settings.php</code></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.card {
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 0.375rem;
|
||||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 0.75rem 1rem;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.125);
|
||||
border-radius: calc(0.375rem - 1px) calc(0.375rem - 1px) 0 0;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 1rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user