668d973889
Incluye: mu-plugins custom (fea-homepage, carta-semana), scripts de migración/traducción/deploy, documentación de auditoría, análisis de cartas y HTML de evangelios exportados desde Joomla. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
// Bulk Import Script for FileBird (Portadas)
|
|
// ID: 9
|
|
// Check for existing files (GUID) before import
|
|
|
|
$folder_id = 9;
|
|
$relative_base = 'Portadas';
|
|
$base_dir = '/var/www/html/wp-content/uploads/' . $relative_base;
|
|
|
|
global $wpdb;
|
|
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
|
|
|
if (!is_dir($base_dir)) {
|
|
die("Directory not found: $base_dir\n");
|
|
}
|
|
|
|
echo "Starting Import for $relative_base (ID: $folder_id)...\n";
|
|
|
|
$files = scandir($base_dir);
|
|
$count_existing = 0;
|
|
$count_new = 0;
|
|
$count_assigned = 0;
|
|
$errors = 0;
|
|
|
|
foreach ($files as $file) {
|
|
if ($file === '.' || $file === '..') continue;
|
|
|
|
$filepath = $base_dir . '/' . $file;
|
|
if (is_dir($filepath)) continue;
|
|
|
|
$guid_search = '%' . $relative_base . '/' . $file;
|
|
$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", $guid_search ) );
|
|
|
|
if (!$attachment_id) {
|
|
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
|
$output = shell_exec($cmd);
|
|
$attachment_id = trim($output);
|
|
|
|
if (!is_numeric($attachment_id)) {
|
|
$errors++;
|
|
continue;
|
|
}
|
|
$count_new++;
|
|
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
|
$count_assigned++;
|
|
} else {
|
|
$count_existing++;
|
|
$current_folder = $wpdb->get_var( $wpdb->prepare( "SELECT folder_id FROM $table_name WHERE attachment_id = %d", $attachment_id ) );
|
|
|
|
if ($current_folder != $folder_id) {
|
|
if ($current_folder) {
|
|
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET folder_id = %d WHERE attachment_id = %d", $folder_id, $attachment_id ) );
|
|
} else {
|
|
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
|
}
|
|
$count_assigned++;
|
|
}
|
|
}
|
|
|
|
if (($count_existing + $count_new) % 100 == 0) {
|
|
echo "Processed " . ($count_existing + $count_new) . " files...\n";
|
|
}
|
|
}
|
|
|
|
echo "\nCompleted $relative_base.\nTotal: " . ($count_existing + $count_new) . "\nNew: $count_new\nErrors: $errors\n";
|