chore(wp): registrar borrado de scripts de raíz WP
Los ficheros archivados/borrados ya están descritos en archive/README.md y el commit anterior. Este solo registra los deletes en git.
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
|
||||
// Define table names
|
||||
$fbv_table = $wpdb->prefix . 'fbv';
|
||||
$fbv_rel_table = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
// Folder ID from previous step (or hardcoded to 1)
|
||||
$folder_id = 1;
|
||||
|
||||
// Attachment ID (or list of IDs)
|
||||
$attachment_ids = [26913];
|
||||
|
||||
foreach ($attachment_ids as $attachment_id) {
|
||||
// Check if relationship exists
|
||||
$existing = $wpdb->get_row( $wpdb->prepare("SELECT folder_id FROM $fbv_rel_table WHERE attachment_id = %d", $attachment_id) );
|
||||
|
||||
if ($existing) {
|
||||
// Update existing relationship
|
||||
$wpdb->update(
|
||||
$fbv_rel_table,
|
||||
array('folder_id' => $folder_id),
|
||||
array('attachment_id' => $attachment_id)
|
||||
);
|
||||
echo "Updated attachment $attachment_id to folder $folder_id\n";
|
||||
} else {
|
||||
// Insert new relationship
|
||||
$wpdb->insert(
|
||||
$fbv_rel_table,
|
||||
array(
|
||||
'folder_id' => $folder_id,
|
||||
'attachment_id' => $attachment_id
|
||||
)
|
||||
);
|
||||
echo "Assigned attachment $attachment_id to folder $folder_id\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
// Bulk Import Script for FileBird Folders
|
||||
|
||||
$mappings = [
|
||||
7 => 'Musica',
|
||||
8 => 'Pensamientos',
|
||||
9 => 'Portadas',
|
||||
10 => 'homilias_fray_marcos',
|
||||
11 => 'stories',
|
||||
12 => '1jornada_feadulta'
|
||||
];
|
||||
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
foreach ($mappings as $folder_id => $relative_base) {
|
||||
echo "Processing Folder: $relative_base (ID: $folder_id)...\n";
|
||||
|
||||
$base_dir = '/var/www/html/wp-content/uploads/' . $relative_base;
|
||||
|
||||
if (!is_dir($base_dir)) {
|
||||
echo "Directory not found: $base_dir\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$files = scandir($base_dir);
|
||||
$count = 0;
|
||||
$errors = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
|
||||
$filepath = $base_dir . '/' . $file;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
// Find attachment ID
|
||||
// Try exact match on GUID first (most reliable for migrated files)
|
||||
// GUIDs usually store path relative to uploads, but sometimes absolute
|
||||
// We use LIKE to be safe: %relative_base/file
|
||||
$guid_search = '%' . $relative_base . '/' . $file;
|
||||
|
||||
// Check if exists in DB
|
||||
$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) {
|
||||
echo "Importing: $file\n";
|
||||
// Use wp media import
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$output = shell_exec($cmd);
|
||||
$attachment_id = trim($output);
|
||||
|
||||
if (!is_numeric($attachment_id)) {
|
||||
echo " ERROR: Failed to import $file. Output: $output\n";
|
||||
$errors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign to folder
|
||||
$current_folder = $wpdb->get_var( $wpdb->prepare( "SELECT folder_id FROM $table_name WHERE attachment_id = %d", $attachment_id ) );
|
||||
|
||||
if ($current_folder) {
|
||||
if ($current_folder != $folder_id) {
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET folder_id = %d WHERE attachment_id = %d", $folder_id, $attachment_id ) );
|
||||
echo " Moved ID $attachment_id from folder $current_folder to $folder_id\n";
|
||||
$count++;
|
||||
}
|
||||
} else {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
||||
echo " Assigned ID $attachment_id to folder $folder_id\n";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Completed $relative_base. Assigned/Moved: $count files. Errors: $errors.\n";
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
|
||||
// Define table names
|
||||
$fbv_table = $wpdb->prefix . 'fbv';
|
||||
$fbv_rel_table = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
// Folder details
|
||||
$folder_name = 'Publi';
|
||||
$parent_id = 0;
|
||||
$created_by = 1; // Assuming admin user ID 1
|
||||
|
||||
// Check if folder exists
|
||||
$existing = $wpdb->get_row( $wpdb->prepare("SELECT id FROM $fbv_table WHERE name = %s AND parent = %d", $folder_name, $parent_id) );
|
||||
|
||||
if ($existing) {
|
||||
echo "Folder 'Publi' already exists with ID: " . $existing->id . "\n";
|
||||
$folder_id = $existing->id;
|
||||
} else {
|
||||
// Insert new folder
|
||||
$wpdb->insert(
|
||||
$fbv_table,
|
||||
array(
|
||||
'name' => $folder_name,
|
||||
'parent' => $parent_id,
|
||||
'type' => 0,
|
||||
'ord' => 0,
|
||||
'created_by' => $created_by
|
||||
)
|
||||
);
|
||||
$folder_id = $wpdb->insert_id;
|
||||
echo "Created folder 'Publi' with ID: " . $folder_id . "\n";
|
||||
}
|
||||
|
||||
// Write the folder ID to a file so we can use it later
|
||||
file_put_contents('/tmp/fbv_folder_id.txt', $folder_id);
|
||||
?>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'fbv';
|
||||
$folder_name = 'Libros';
|
||||
$parent_id = 0;
|
||||
$created_by = 1;
|
||||
|
||||
$existing = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM $table_name WHERE name = %s AND parent = %d", $folder_name, $parent_id ) );
|
||||
|
||||
if ( $existing ) {
|
||||
echo "Folder 'Libros' already exists with ID: " . $existing->id;
|
||||
} else {
|
||||
$wpdb->insert(
|
||||
$table_name,
|
||||
array(
|
||||
'name' => $folder_name,
|
||||
'parent' => $parent_id,
|
||||
'type' => 0,
|
||||
'ord' => 0,
|
||||
'created_by' => $created_by
|
||||
)
|
||||
);
|
||||
echo "Created folder 'Libros' with ID: " . $wpdb->insert_id;
|
||||
}
|
||||
?>
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
// Fix attachments: Move from 2026/02/ back to original folder (e.g. Musica/)
|
||||
|
||||
$mappings = [
|
||||
7 => 'Musica',
|
||||
8 => 'Pensamientos',
|
||||
9 => 'Portadas',
|
||||
10 => 'homilias_fray_marcos',
|
||||
11 => 'stories',
|
||||
12 => '1jornada_feadulta'
|
||||
];
|
||||
|
||||
global $wpdb;
|
||||
|
||||
foreach ($mappings as $folder_id => $relative_base) {
|
||||
echo "Processing Folder: $relative_base (ID: $folder_id)...\n";
|
||||
|
||||
$base_dir = '/var/www/html/wp-content/uploads/' . $relative_base;
|
||||
|
||||
if (!is_dir($base_dir)) {
|
||||
echo "Directory not found: $base_dir\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$files = scandir($base_dir);
|
||||
$count = 0;
|
||||
$updated = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
|
||||
$filepath = $base_dir . '/' . $file;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
// Search for attachment with this filename (regardless of folder)
|
||||
// We look for %/file.mp3
|
||||
$guid_search = '%' . $file;
|
||||
|
||||
$attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, guid FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", $guid_search ) );
|
||||
|
||||
foreach ($attachments as $att) {
|
||||
// Check if it's in 2026/02/ or similar (not in target folder)
|
||||
if (strpos($att->guid, $relative_base . '/') === false) {
|
||||
// It is NOT in the target folder (e.g. it is in 2026/02/)
|
||||
// Move it back!
|
||||
|
||||
$new_guid = str_replace( '/2026/02/', '/' . $relative_base . '/', $att->guid );
|
||||
// Also handle other months if needed, but likely just 2026/02 based on date
|
||||
// Or construct GUID from site URL + uploads + relative path
|
||||
$upload_dir = wp_upload_dir();
|
||||
$new_guid = $upload_dir['baseurl'] . '/' . $relative_base . '/' . $file;
|
||||
|
||||
// Update GUID
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET guid = %s WHERE ID = %d", $new_guid, $att->ID ) );
|
||||
|
||||
// Update _wp_attached_file meta
|
||||
$new_attached_file = $relative_base . '/' . $file;
|
||||
update_post_meta( $att->ID, '_wp_attached_file', $new_attached_file );
|
||||
|
||||
// Delete the physical copy in 2026/02/ if exists
|
||||
// We need to parse the old path from old GUID or check _wp_attached_file before update
|
||||
// But for now, just update DB is enough to point to the correct file.
|
||||
// The correct file is in $filepath.
|
||||
|
||||
echo "Updated ID $att->ID: $att->guid -> $new_guid\n";
|
||||
$updated++;
|
||||
|
||||
// Ensure assigned to FileBird folder
|
||||
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
$current_folder = $wpdb->get_var( $wpdb->prepare( "SELECT folder_id FROM $table_name WHERE attachment_id = %d", $att->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, $att->ID ) );
|
||||
} else {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $att->ID ) );
|
||||
}
|
||||
echo " Assigned to folder $folder_id\n";
|
||||
}
|
||||
} else {
|
||||
// Already correct path
|
||||
// Check folder assignment
|
||||
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
$current_folder = $wpdb->get_var( $wpdb->prepare( "SELECT folder_id FROM $table_name WHERE attachment_id = %d", $att->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, $att->ID ) );
|
||||
} else {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $att->ID ) );
|
||||
}
|
||||
echo " Assigned ID $att->ID to folder $folder_id (path was OK)\n";
|
||||
$updated++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($attachments)) {
|
||||
// Import it if not found at all
|
||||
echo "Importing missing file: $file\n";
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$output = shell_exec($cmd);
|
||||
$attachment_id = trim($output);
|
||||
|
||||
if (is_numeric($attachment_id)) {
|
||||
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
||||
echo " Imported & Assigned ID $attachment_id\n";
|
||||
$updated++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Completed $relative_base. Updated/Imported: $updated files.\n\n";
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
|
||||
// Config: filebird folder ID for 'quienes_somos'
|
||||
$fbv_folder_id = 4;
|
||||
|
||||
// 1. Find all attachments where the _wp_attached_file (physical path)
|
||||
// contains 'quienes_somos'. This will catch all images you just imported,
|
||||
// because they came from /uploads/quienes_somos/...
|
||||
// Note: 'wp media import' creates a COPY in YYYY/MM, BUT often keeps the original filename
|
||||
// OR if you imported in place (which I didn't specify --porcelain in all cases), let's check.
|
||||
// Wait, the previous command was: wp media import ...
|
||||
// That defaults to copying to YYYY/MM. So the path in DB will be '2026/02/imagen.jpg'.
|
||||
// We lost the 'quienes_somos' path reference in the DB!
|
||||
|
||||
// PLAN B:
|
||||
// Since we JUST imported them, they have ID > X.
|
||||
// Or we can match by filename against the files in the source directory.
|
||||
// Let's iterate the source directory 'quienes_somos', get the filenames,
|
||||
// and find attachments with those filenames created TODAY.
|
||||
|
||||
$target_rel_path = 'quienes_somos';
|
||||
$uploads = wp_upload_dir();
|
||||
$base_dir = $uploads['basedir'];
|
||||
$target_dir = $base_dir . '/' . $target_rel_path;
|
||||
|
||||
if (!file_exists($target_dir)) {
|
||||
die("Directory not found: $target_dir\n");
|
||||
}
|
||||
|
||||
$files = glob("$target_dir/*");
|
||||
$filenames = [];
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file) && !in_array(pathinfo($file, PATHINFO_EXTENSION), ['html', 'php'])) {
|
||||
$filenames[] = basename($file);
|
||||
}
|
||||
}
|
||||
|
||||
echo "Found " . count($filenames) . " files in source directory.\n";
|
||||
|
||||
if (empty($filenames)) {
|
||||
die("No files to process.\n");
|
||||
}
|
||||
|
||||
// Prepare SQL to find attachments with these filenames
|
||||
// We filter by post_date LIKE '2026-02-14%' to only catch today's imports
|
||||
// to avoid messing with older files that might have same names.
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($filenames), '%s'));
|
||||
$sql = "SELECT ID, post_title FROM {$wpdb->posts}
|
||||
WHERE post_type = 'attachment'
|
||||
AND post_date LIKE '2026-02-14%'
|
||||
AND (
|
||||
post_title IN ($placeholders)
|
||||
OR guid REGEXP '" . implode('|', array_map('preg_quote', array_slice($filenames, 0, 50))) . "'
|
||||
)";
|
||||
// REGEXP is risky with 1000 files. Let's stick to post_title/post_name matching.
|
||||
// WordPress sanitizes filenames, so 'My Image.jpg' becomes 'my-image'.
|
||||
// This is tricky.
|
||||
|
||||
// BETTER APPROACH:
|
||||
// Just match by 'post_name' (slug) being similar to filename-without-extension.
|
||||
// OR: 'guid' ending in filename.
|
||||
|
||||
$count = 0;
|
||||
$fbv_rel_table = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
foreach ($filenames as $filename) {
|
||||
// Sanitize filename to potential post_name
|
||||
$name_part = pathinfo($filename, PATHINFO_FILENAME);
|
||||
$sanitized = sanitize_title($name_part);
|
||||
|
||||
// Find attachment created today with this name
|
||||
// We use LIKE because WP might append -1, -2 if duplicate
|
||||
$attachment = $wpdb->get_row( $wpdb->prepare(
|
||||
"SELECT ID FROM {$wpdb->posts}
|
||||
WHERE post_type = 'attachment'
|
||||
AND post_date LIKE %s
|
||||
AND (post_title = %s OR post_name = %s)
|
||||
ORDER BY ID DESC LIMIT 1",
|
||||
'2026-02-14%', $name_part, $sanitized
|
||||
));
|
||||
|
||||
if ($attachment) {
|
||||
$att_id = $attachment->ID;
|
||||
|
||||
// Assign to folder
|
||||
$exists = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $fbv_rel_table WHERE attachment_id = %d", $att_id) );
|
||||
|
||||
if (!$exists) {
|
||||
$wpdb->insert(
|
||||
$fbv_rel_table,
|
||||
array(
|
||||
'folder_id' => $fbv_folder_id,
|
||||
'attachment_id' => $att_id
|
||||
)
|
||||
);
|
||||
// echo "Assigned $filename (ID: $att_id)\n";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "Successfully assigned $count images to folder 'quienes_somos' (ID: $fbv_folder_id).\n";
|
||||
?>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
$post_id = 17907;
|
||||
$post = get_post($post_id);
|
||||
$content = $post->post_content;
|
||||
|
||||
// Regex to match joomla links with slug
|
||||
$content = preg_replace('/index\.php\?option=com_content(?:&|&)view=article(?:&|&)id=\d+;([^&"]+).*?">/', '/fea/$1/">', $content);
|
||||
|
||||
wp_update_post(array('ID'=>$post_id, 'post_content'=>$content));
|
||||
echo "Updated post $post_id\n";
|
||||
?>
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
// Config: folder name and FileBird ID
|
||||
$target_rel_path = 'quienes_somos';
|
||||
$fbv_folder_id = 4; // Confirmed 'quienes_somos' folder ID
|
||||
|
||||
$uploads = wp_upload_dir();
|
||||
$base_dir = $uploads['basedir'];
|
||||
$target_dir = $base_dir . '/' . $target_rel_path;
|
||||
|
||||
if (!file_exists($target_dir)) {
|
||||
die("Directory not found: $target_dir\n");
|
||||
}
|
||||
|
||||
$files = glob("$target_dir/*");
|
||||
$count = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!is_file($file) || in_array(pathinfo($file, PATHINFO_EXTENSION), ['html', 'php'])) {
|
||||
continue;
|
||||
}
|
||||
// We will echo commands to run directly
|
||||
echo "wp media import " . escapeshellarg($file) . " --porcelain | xargs -I {} wp db query \"INSERT INTO wp_fbv_attachment_folder (folder_id, attachment_id) VALUES ($fbv_folder_id, {})\" --allow-root\n";
|
||||
$count++;
|
||||
}
|
||||
echo "# Generated $count commands\n";
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
$folder_id = 10;
|
||||
$base_dir = '/var/www/html/wp-content/uploads/homilias_fray_marcos';
|
||||
$name = 'homilias';
|
||||
global $wpdb; $t = $wpdb->prefix.'fbv_attachment_folder';
|
||||
$files = scandir($base_dir); $c=0; foreach($files as $f){if($f=='.'||$f=='..')continue; $p=$base_dir.'/'.$f; if(is_dir($p))continue; $id=$wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type='attachment'",'%'.$name.'/'.$f)); if(!$id){$id=trim(shell_exec("wp media import ".escapeshellarg($p)." --porcelain --allow-root")); if(is_numeric($id)){$wpdb->query("INSERT INTO $t (folder_id, attachment_id) VALUES ($folder_id, $id)"); $c++;}} } echo "Done. Imported: $c\n";
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
// Bulk Import Script for FileBird (Jornada)
|
||||
// ID: 12
|
||||
// Check for existing files (GUID) before import
|
||||
|
||||
$folder_id = 12;
|
||||
$relative_base = '1jornada_feadulta';
|
||||
$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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "\nCompleted $relative_base.\nTotal: " . ($count_existing + $count_new) . "\nNew: $count_new\nErrors: $errors\n";
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
// Import libros subfolders: 100, 120, 200, 220, 400
|
||||
|
||||
$parent_id = 5; // libros (Libros)
|
||||
$base_path = '/var/www/html/wp-content/uploads/libros';
|
||||
|
||||
$subfolders = ['100', '120', '200', '220', '400'];
|
||||
|
||||
global $wpdb;
|
||||
$fbv = $wpdb->prefix . 'fbv';
|
||||
$fbv_att = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
foreach ($subfolders as $sub) {
|
||||
// Create or get subfolder
|
||||
$exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $fbv WHERE name = %s AND parent = %d", $sub, $parent_id));
|
||||
if (!$exists) {
|
||||
$wpdb->query($wpdb->prepare("INSERT INTO $fbv (name, parent, type) VALUES (%s, %d, 0)", $sub, $parent_id));
|
||||
$folder_id = $wpdb->insert_id;
|
||||
echo "Created: $sub (ID $folder_id)\n";
|
||||
} else {
|
||||
$folder_id = $exists;
|
||||
echo "Exists: $sub (ID $folder_id)\n";
|
||||
}
|
||||
|
||||
$dir = $base_path . '/' . $sub;
|
||||
if (!is_dir($dir)) continue;
|
||||
|
||||
$files = scandir($dir);
|
||||
$count = 0;
|
||||
foreach ($files as $f) {
|
||||
if ($f === '.' || $f === '..') continue;
|
||||
$filepath = $dir . '/' . $f;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
// Check if exists
|
||||
$guid_search = '%libros/' . $sub . '/' . $f;
|
||||
$att_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", $guid_search));
|
||||
|
||||
if (!$att_id) {
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$out = shell_exec($cmd);
|
||||
$att_id = trim($out);
|
||||
if (is_numeric($att_id)) {
|
||||
$wpdb->query("INSERT INTO $fbv_att (folder_id, attachment_id) VALUES ($folder_id, $att_id)");
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Imported $count files to libros/$sub\n";
|
||||
}
|
||||
echo "DONE\n";
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
// Script to import/assign files in wp-content/uploads/Musica to FileBird folder 7
|
||||
|
||||
$folder_id = 7;
|
||||
$base_dir = '/var/www/html/wp-content/uploads/Musica';
|
||||
|
||||
if (!is_dir($base_dir)) {
|
||||
die("Directory not found: $base_dir\n");
|
||||
}
|
||||
|
||||
$files = scandir($base_dir);
|
||||
$count = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
|
||||
$filepath = $base_dir . '/' . $file;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
// Check if attachment exists by GUID (approximate check for imported files)
|
||||
// The GUID usually contains "wp-content/uploads/Musica/filename.mp3"
|
||||
global $wpdb;
|
||||
|
||||
// We search for the file name in GUID to find existing attachment ID
|
||||
$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", '%' . $file ) );
|
||||
|
||||
if (!$attachment_id) {
|
||||
// Not found, import it
|
||||
// We use media_handle_sideload or similar internal functions, but since the file is already there, we can simulate an import.
|
||||
// Or simpler: just use shell_exec to call wp media import for this file if we are running in CLI context.
|
||||
// Given we are running via `wp eval-file`, we can shell out to `wp`.
|
||||
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$output = shell_exec($cmd);
|
||||
$attachment_id = trim($output);
|
||||
|
||||
if (!is_numeric($attachment_id)) {
|
||||
echo "Failed to import $file: $output\n";
|
||||
continue;
|
||||
}
|
||||
echo "Imported $file as ID $attachment_id\n";
|
||||
} else {
|
||||
echo "Found existing ID $attachment_id for $file\n";
|
||||
}
|
||||
|
||||
// Now assign to FileBird folder
|
||||
// Table: wp_fbv_attachment_folder (prefix might be different, let's use $wpdb->prefix)
|
||||
$table_name = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
// Check if entry exists
|
||||
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT folder_id FROM $table_name WHERE attachment_id = %d", $attachment_id ) );
|
||||
|
||||
if ($exists) {
|
||||
if ($exists != $folder_id) {
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET folder_id = %d WHERE attachment_id = %d", $folder_id, $attachment_id ) );
|
||||
echo "Updated folder for ID $attachment_id to $folder_id\n";
|
||||
$count++;
|
||||
}
|
||||
} else {
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
||||
echo "Assigned ID $attachment_id to folder $folder_id\n";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
echo "Done. Processed/Assigned $count files.\n";
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
// Bulk Import Script for FileBird (Safe & Fast - Pensamientos)
|
||||
|
||||
$folder_id = 8;
|
||||
$relative_base = 'Pensamientos';
|
||||
$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;
|
||||
|
||||
// Search existing by GUID
|
||||
$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) {
|
||||
// Not found -> Import
|
||||
$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++;
|
||||
|
||||
// Assign newly imported
|
||||
$wpdb->query( $wpdb->prepare( "INSERT INTO $table_name (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $attachment_id ) );
|
||||
$count_assigned++;
|
||||
|
||||
} else {
|
||||
$count_existing++;
|
||||
|
||||
// Assign 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";
|
||||
@@ -1,65 +0,0 @@
|
||||
<?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";
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
// Import remaining folders: recursos, libros, fotos_conchita, miguel_angel_martin, 1jornadafa, headers, sampledata
|
||||
|
||||
$folders = [
|
||||
'recursos' => 14, // New ID
|
||||
'libros' => 15, // New ID
|
||||
'fotos_conchita' => 16,
|
||||
'miguel_angel_martin' => 17,
|
||||
'1jornadafa' => 18,
|
||||
'headers' => 19,
|
||||
'sampledata' => 20
|
||||
];
|
||||
|
||||
global $wpdb;
|
||||
$fbv_table = $wpdb->prefix . 'fbv';
|
||||
$fbv_att_table = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
foreach ($folders as $folder_name => $folder_id) {
|
||||
// Create folder if not exists
|
||||
$exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM $fbv_table WHERE name = %s", $folder_name));
|
||||
if (!$exists) {
|
||||
$wpdb->query($wpdb->prepare("INSERT INTO $fbv_table (name) VALUES (%s)", $folder_name));
|
||||
$folder_id = $wpdb->insert_id;
|
||||
echo "Created folder: $folder_name (ID: $folder_id)\n";
|
||||
} else {
|
||||
$folder_id = $exists;
|
||||
echo "Folder exists: $folder_name (ID: $folder_id)\n";
|
||||
}
|
||||
|
||||
$base_dir = '/var/www/html/wp-content/uploads/' . $folder_name;
|
||||
if (!is_dir($base_dir)) {
|
||||
echo "Dir not found: $base_dir\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$files = scandir($base_dir);
|
||||
$count = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
$filepath = $base_dir . '/' . $file;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
// Check if exists
|
||||
$guid_search = '%' . $folder_name . '/' . $file;
|
||||
$att_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", $guid_search));
|
||||
|
||||
if (!$att_id) {
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$output = shell_exec($cmd);
|
||||
$att_id = trim($output);
|
||||
if (is_numeric($att_id)) {
|
||||
$wpdb->query($wpdb->prepare("INSERT INTO $fbv_att_table (folder_id, attachment_id) VALUES (%d, %d)", $folder_id, $att_id));
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Imported $count files to $folder_name\n";
|
||||
}
|
||||
echo "ALL DONE\n";
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
// Import small folders into Carpetas_varias (ID 26)
|
||||
|
||||
$folders = ['home', 'jornada', 'pdf', 'presentaciones', 'publi', 'sobipro', 'titulos'];
|
||||
$folder_id = 26;
|
||||
|
||||
global $wpdb;
|
||||
$fbv_att = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
foreach ($folders as $name) {
|
||||
$base_dir = '/var/www/html/wp-content/uploads/' . $name;
|
||||
if (!is_dir($base_dir)) continue;
|
||||
|
||||
$files = scandir($base_dir);
|
||||
$count = 0;
|
||||
|
||||
foreach ($files as $f) {
|
||||
if ($f === '.' || $f === '..') continue;
|
||||
$filepath = $base_dir . '/' . $f;
|
||||
if (is_dir($filepath)) continue;
|
||||
|
||||
$guid_search = '%' . $name . '/' . $f;
|
||||
$att_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type = 'attachment'", $guid_search));
|
||||
|
||||
if (!$att_id) {
|
||||
$cmd = "wp media import " . escapeshellarg($filepath) . " --porcelain --allow-root";
|
||||
$out = shell_exec($cmd);
|
||||
$att_id = trim($out);
|
||||
if (is_numeric($att_id)) {
|
||||
$wpdb->query("INSERT INTO $fbv_att (folder_id, attachment_id) VALUES ($folder_id, $att_id)");
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "$name: $count files\n";
|
||||
}
|
||||
echo "DONE\n";
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
$folder_id = 11;
|
||||
$base_dir = '/var/www/html/wp-content/uploads/stories';
|
||||
$name = 'stories';
|
||||
global $wpdb; $t = $wpdb->prefix.'fbv_attachment_folder';
|
||||
$files = scandir($base_dir); $c=0; foreach($files as $f){if($f=='.'||$f=='..')continue; $p=$base_dir.'/'.$f; if(is_dir($p))continue; $id=$wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid LIKE %s AND post_type='attachment'",'%'.$name.'/'.$f)); if(!$id){$id=trim(shell_exec("wp media import ".escapeshellarg($p)." --porcelain --allow-root")); if(is_numeric($id)){$wpdb->query("INSERT INTO $t (folder_id, attachment_id) VALUES ($folder_id, $id)"); $c++;}} } echo "Done. Imported: $c\n";
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
$results = $wpdb->get_results("SELECT id, name FROM {$wpdb->prefix}fbv");
|
||||
foreach ($results as $row) {
|
||||
echo $row->id . " : " . $row->name . "\n";
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
global $wpdb;
|
||||
$results = $wpdb->get_results("SELECT id, name FROM {$wpdb->prefix}fbv ORDER BY id ASC");
|
||||
foreach ($results as $row) {
|
||||
echo str_pad($row->id, 4) . " : " . $row->name . "\n";
|
||||
}
|
||||
?>
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Migrar metadatos Autor (que es un user_id) a categorias
|
||||
*/
|
||||
require_once('/var/www/html/wp-load.php');
|
||||
|
||||
echo "=== Migrando AUTORES a categorias ===\n\n";
|
||||
|
||||
$users = $wpdb->get_results("SELECT ID, display_name FROM wp_users WHERE ID > 1");
|
||||
|
||||
$created = 0;
|
||||
$assigned = 0;
|
||||
|
||||
foreach ($users as $user) {
|
||||
$user_id = $user->ID;
|
||||
$name = $user->display_name;
|
||||
|
||||
if (empty($name)) continue;
|
||||
|
||||
// Crear categoria
|
||||
$term = get_term_by('name', $name, 'category');
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($name, 'category', array(
|
||||
'slug' => sanitize_title($name),
|
||||
'description' => 'Autor: ' . $name
|
||||
));
|
||||
if (is_wp_error($result)) {
|
||||
echo "Error: $name\n";
|
||||
continue;
|
||||
}
|
||||
$term_id = $result['term_id'];
|
||||
$created++;
|
||||
} else {
|
||||
$term_id = $term->term_id;
|
||||
}
|
||||
|
||||
// Buscar posts con este autor (meta_value = user_id)
|
||||
$posts = $wpdb->get_col($wpdb->prepare("
|
||||
SELECT DISTINCT pm.post_id
|
||||
FROM wp_postmeta pm
|
||||
JOIN wp_posts p ON pm.post_id = p.ID
|
||||
WHERE pm.meta_key = 'Autor' AND pm.meta_value = %s
|
||||
AND p.post_type = 'post' AND p.post_status = 'publish'
|
||||
", $user_id));
|
||||
|
||||
foreach ($posts as $post_id) {
|
||||
wp_set_object_terms($post_id, $term_id, 'category', true);
|
||||
$assigned++;
|
||||
}
|
||||
|
||||
if (count($posts) > 0) {
|
||||
echo "$name: " . count($posts) . " posts\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "\nCategorias creadas: $created\n";
|
||||
echo "Asignaciones: $assigned\n";
|
||||
echo "=== FIN ===\n";
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Script simple para migrar metadatos - version rapida
|
||||
* Ejecutar: php migrate_fast.php
|
||||
*/
|
||||
|
||||
require_once('/var/www/html/wp-load.php');
|
||||
|
||||
echo "=== Migracion rapida de metadata ===\n\n";
|
||||
|
||||
// Solo procesar AUTORES (el mas importante)
|
||||
echo "Procesando AUTORES como categorias...\n";
|
||||
|
||||
$autores = $wpdb->get_results("
|
||||
SELECT meta_value as autor, COUNT(*) as cnt
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Autor' AND meta_value != '' AND meta_value IS NOT NULL
|
||||
GROUP BY meta_value
|
||||
ORDER BY cnt DESC
|
||||
LIMIT 100
|
||||
");
|
||||
|
||||
$cat_created = 0;
|
||||
$assignments = 0;
|
||||
|
||||
foreach ($autores as $row) {
|
||||
$autor = trim($row->autor);
|
||||
if (empty($autor)) continue;
|
||||
|
||||
// Crear o encontrar categoria
|
||||
$term = get_term_by('name', $autor, 'category');
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($autor, 'category', array(
|
||||
'slug' => sanitize_title($autor)
|
||||
));
|
||||
if (is_wp_error($result)) continue;
|
||||
$term_id = $result['term_id'];
|
||||
$cat_created++;
|
||||
} else {
|
||||
$term_id = $term->term_id;
|
||||
}
|
||||
|
||||
// Asignar a posts
|
||||
$post_ids = $wpdb->get_col($wpdb->prepare("
|
||||
SELECT DISTINCT post_id FROM wp_postmeta
|
||||
WHERE meta_key = 'Autor' AND meta_value = %s
|
||||
", $autor));
|
||||
|
||||
foreach ($post_ids as $post_id) {
|
||||
wp_set_object_terms($post_id, $term_id, 'category', true);
|
||||
$assignments++;
|
||||
}
|
||||
|
||||
echo "$autor: $row->cnt posts\n";
|
||||
}
|
||||
|
||||
echo "\nCategorias creadas: $cat_created\n";
|
||||
echo "Asignaciones: $assignments\n";
|
||||
echo "=== FIN ===\n";
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Migrar IDIOMA a tags
|
||||
*/
|
||||
require_once('/var/www/html/wp-load.php');
|
||||
|
||||
echo "=== Migrando IDIOMA a tags ===\n\n";
|
||||
|
||||
// Mapeo de IDs de Joomla a nombres
|
||||
$idiomas_map = array(
|
||||
1 => 'English',
|
||||
2 => 'Galego',
|
||||
3 => 'Español',
|
||||
4 => 'Português',
|
||||
5 => 'Català'
|
||||
);
|
||||
|
||||
$created = 0;
|
||||
$assigned = 0;
|
||||
|
||||
foreach ($idiomas_map as $id => $nombre) {
|
||||
// Crear o encontrar tag
|
||||
$term = get_term_by('name', $nombre, 'post_tag');
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($nombre, 'post_tag', array(
|
||||
'slug' => sanitize_title($nombre)
|
||||
));
|
||||
if (is_wp_error($result)) continue;
|
||||
$term_id = $result['term_id'];
|
||||
$created++;
|
||||
} else {
|
||||
$term_id = $term->term_id;
|
||||
}
|
||||
|
||||
// Buscar posts
|
||||
$posts = $wpdb->get_col($wpdb->prepare("
|
||||
SELECT DISTINCT pm.post_id
|
||||
FROM wp_postmeta pm
|
||||
JOIN wp_posts p ON pm.post_id = p.ID
|
||||
WHERE pm.meta_key = 'Idioma' AND pm.meta_value = %s
|
||||
AND p.post_type = 'post' AND p.post_status = 'publish'
|
||||
", $id));
|
||||
|
||||
foreach ($posts as $post_id) {
|
||||
wp_set_object_terms($post_id, $term_id, 'post_tag', true);
|
||||
$assigned++;
|
||||
}
|
||||
|
||||
echo "$nombre: " . count($posts) . " posts\n";
|
||||
}
|
||||
|
||||
echo "\nTags creados: $created\n";
|
||||
echo "Asignaciones: $assigned\n";
|
||||
echo "=== FIN ===\n";
|
||||
@@ -1,210 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Script para migrar metadatos de Joomla a categories/tags de WordPress
|
||||
* Ejecutar: wp eval-file migrate_metadata.php
|
||||
*/
|
||||
|
||||
// Cargar WordPress
|
||||
require_once('/var/www/html/wp-load.php');
|
||||
|
||||
echo "=== Iniciando migracion de metadatos ===\n\n";
|
||||
|
||||
// 1. Migrar AUTOR -> category
|
||||
echo "1. Procesando AUTORES...\n";
|
||||
$autores = $wpdb->get_results("
|
||||
SELECT DISTINCT meta_value as autor, COUNT(*) as cnt
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Autor' AND meta_value IS NOT NULL AND meta_value != ''
|
||||
ORDER BY cnt DESC
|
||||
");
|
||||
|
||||
$created = 0;
|
||||
$assigned = 0;
|
||||
foreach ($autores as $autor) {
|
||||
if (empty($autor->autor)) continue;
|
||||
|
||||
// Buscar si ya existe la categoria
|
||||
$term = get_term_by('name', $autor->autor, 'category');
|
||||
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($autor->autor, 'category', array(
|
||||
'description' => 'Autor migrado desde Joomla: ' . $autor->autor,
|
||||
'slug' => sanitize_title($autor->autor)
|
||||
));
|
||||
if (is_wp_error($result)) {
|
||||
echo " - Error creando categoria '$autor->autor': " . $result->get_error_message() . "\n";
|
||||
continue;
|
||||
}
|
||||
$term_id = $result['term_id'];
|
||||
$created++;
|
||||
} else {
|
||||
$term_id = $term->term_id;
|
||||
}
|
||||
|
||||
// Asignar a todos los posts que tienen este autor
|
||||
$posts = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT post_id
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Autor' AND meta_value = %s
|
||||
", $autor->autor));
|
||||
|
||||
foreach ($posts as $post) {
|
||||
wp_set_object_terms($post->post_id, $term_id, 'category', true);
|
||||
$assigned++;
|
||||
}
|
||||
|
||||
echo " - $autor->autor: $autor->cnt posts -> categoria ID $term_id\n";
|
||||
}
|
||||
|
||||
echo " Categorias de autor creadas: $created\n";
|
||||
echo " Asignaciones realizadas: $assigned\n\n";
|
||||
|
||||
// 2. Migrar IDIOMA -> post_tag
|
||||
echo "2. Procesando IDIOMAS...\n";
|
||||
$idiomas = $wpdb->get_results("
|
||||
SELECT DISTINCT meta_value as idioma, COUNT(*) as cnt
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Idioma' AND meta_value IS NOT NULL AND meta_value != ''
|
||||
ORDER BY cnt DESC
|
||||
");
|
||||
|
||||
$created_tags = 0;
|
||||
$assigned_tags = 0;
|
||||
foreach ($idiomas as $idioma) {
|
||||
if (empty($idioma->idioma)) continue;
|
||||
|
||||
$term = get_term_by('name', $idioma->idioma, 'post_tag');
|
||||
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($idioma->idioma, 'post_tag', array(
|
||||
'description' => 'Idioma migrado desde Joomla',
|
||||
'slug' => sanitize_title($idioma->idioma)
|
||||
));
|
||||
if (is_wp_error($result)) {
|
||||
echo " - Error creando tag '$idioma->idioma': " . $result->get_error_message() . "\n";
|
||||
continue;
|
||||
}
|
||||
$term_id = $result['term_id'];
|
||||
$created_tags++;
|
||||
} else {
|
||||
$term_id = $term->term_id;
|
||||
}
|
||||
|
||||
$posts = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT post_id
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Idioma' AND meta_value = %s
|
||||
", $idioma->idioma));
|
||||
|
||||
foreach ($posts as $post) {
|
||||
wp_set_object_terms($post->post_id, $term_id, 'post_tag', true);
|
||||
$assigned_tags++;
|
||||
}
|
||||
|
||||
echo " - $idioma->idioma: $idioma->cnt posts\n";
|
||||
}
|
||||
|
||||
echo " Tags de idioma creados: $created_tags\n";
|
||||
echo " Asignaciones: $assigned_tags\n\n";
|
||||
|
||||
// 3. Migrar TEMA -> category (subcategoria de TEMAS)
|
||||
echo "3. Procesando TEMAS...\n";
|
||||
// Crear categoria padre TEMAS si no existe
|
||||
$temas_parent = get_term_by('name', 'TEMAS', 'category');
|
||||
if (!$temas_parent) {
|
||||
$result = wp_insert_term('TEMAS', 'category', array(
|
||||
'description' => 'Categoria padre para temas',
|
||||
'slug' => 'temas'
|
||||
));
|
||||
$temas_parent = get_term_by('name', 'TEMAS', 'category');
|
||||
}
|
||||
|
||||
$temas = $wpdb->get_results("
|
||||
SELECT DISTINCT meta_value as tema, COUNT(*) as cnt
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Tema' AND meta_value IS NOT NULL AND meta_value != ''
|
||||
ORDER BY cnt DESC
|
||||
LIMIT 50
|
||||
");
|
||||
|
||||
$created_temas = 0;
|
||||
foreach ($temas as $tema) {
|
||||
if (empty($tema->tema)) continue;
|
||||
|
||||
$term = get_term_by('name', $tema->tema, 'category');
|
||||
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($tema->tema, 'category', array(
|
||||
'description' => 'Tema migrado desde Joomla',
|
||||
'slug' => sanitize_title($tema->tema),
|
||||
'parent' => $temas_parent->term_id
|
||||
));
|
||||
if (!is_wp_error($result)) {
|
||||
$created_temas++;
|
||||
}
|
||||
}
|
||||
|
||||
// Asignar
|
||||
$posts = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT post_id
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Tema' AND meta_value = %s
|
||||
", $tema->tema));
|
||||
|
||||
$term = get_term_by('name', $tema->tema, 'category');
|
||||
if ($term) {
|
||||
foreach ($posts as $post) {
|
||||
wp_set_object_terms($post->post_id, $term->term_id, 'category', true);
|
||||
}
|
||||
}
|
||||
|
||||
echo " - $tema->tema: $tema->cnt posts\n";
|
||||
}
|
||||
|
||||
echo " Categorias de tema creadas: $created_temas\n\n";
|
||||
|
||||
// 4. Migrar LIBRO DE LA BIBLIA -> category
|
||||
echo "4. Procesando LIBROS DE LA BIBLIA...\n";
|
||||
$libros = $wpdb->get_results("
|
||||
SELECT DISTINCT meta_value as libro, COUNT(*) as cnt
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Libro de la biblia' AND meta_value IS NOT NULL AND meta_value != ''
|
||||
ORDER BY cnt DESC
|
||||
LIMIT 100
|
||||
");
|
||||
|
||||
$created_libros = 0;
|
||||
foreach ($libros as $libro) {
|
||||
if (empty($libro->libro)) continue;
|
||||
|
||||
$term = get_term_by('name', $libro->libro, 'category');
|
||||
|
||||
if (!$term) {
|
||||
$result = wp_insert_term($libro->libro, 'category', array(
|
||||
'description' => 'Libro biblico migrado desde Joomla',
|
||||
'slug' => sanitize_title($libro->libro)
|
||||
));
|
||||
if (!is_wp_error($result)) {
|
||||
$created_libros++;
|
||||
}
|
||||
}
|
||||
|
||||
$posts = $wpdb->get_results($wpdb->prepare("
|
||||
SELECT DISTINCT post_id
|
||||
FROM wp_postmeta
|
||||
WHERE meta_key = 'Libro de la biblia' AND meta_value = %s
|
||||
", $libro->libro));
|
||||
|
||||
$term = get_term_by('name', $libro->libro, 'category');
|
||||
if ($term) {
|
||||
foreach ($posts as $post) {
|
||||
wp_set_object_terms($post->post_id, $term->term_id, 'category', true);
|
||||
}
|
||||
}
|
||||
|
||||
echo " - $libro->libro: $libro->cnt posts\n";
|
||||
}
|
||||
|
||||
echo " Categorias de libros biblicos creadas: $created_libros\n\n";
|
||||
|
||||
echo "=== Migracion completada ===\n";
|
||||
@@ -1 +0,0 @@
|
||||
<?php include("/var/www/html/wp-load.php"); wp_set_password("Logan1234", 1); ?>
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
// Configuration
|
||||
$target_folder_name = 'libros';
|
||||
$fbv_folder_id = 5; // ID for 'Libros'
|
||||
|
||||
global $wpdb;
|
||||
$fbv_rel_table = $wpdb->prefix . 'fbv_attachment_folder';
|
||||
|
||||
// Define paths
|
||||
$uploads = wp_upload_dir();
|
||||
$base_dir = $uploads['basedir'];
|
||||
$source_dir = $base_dir . '/' . $target_folder_name;
|
||||
|
||||
if (!is_dir($source_dir)) {
|
||||
die("Error: Source directory '$source_dir' not found.\n");
|
||||
}
|
||||
|
||||
// Get all files
|
||||
$files = glob($source_dir . '/*');
|
||||
echo "Found " . count($files) . " files in '$target_folder_name'.\n";
|
||||
|
||||
$count_imported = 0;
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) continue;
|
||||
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
if (in_array($ext, ['html', 'php', 'ds_store'])) continue;
|
||||
|
||||
$filename = basename($file);
|
||||
// echo "Processing: $filename... ";
|
||||
|
||||
// Run wp media import via shell_exec using FULL PATH
|
||||
// Note: Since we are running as www-data via docker exec, wp should be executable.
|
||||
// We add --porcelain to get just the ID.
|
||||
// We add --allow-root because in some contexts inside docker it might be needed, though we run as www-data.
|
||||
// Actually, running 'wp' inside 'wp eval-file' might be tricky due to recursion locks or environment.
|
||||
// But let's try.
|
||||
|
||||
$cmd = "/usr/local/bin/wp media import " . escapeshellarg($file) . " --porcelain --allow-root 2>&1";
|
||||
$output = shell_exec($cmd);
|
||||
$attachment_id = trim($output);
|
||||
|
||||
if (is_numeric($attachment_id) && $attachment_id > 0) {
|
||||
// Success! Now assign to FileBird folder
|
||||
$wpdb->insert(
|
||||
$fbv_rel_table,
|
||||
array(
|
||||
'folder_id' => $fbv_folder_id,
|
||||
'attachment_id' => $attachment_id
|
||||
)
|
||||
);
|
||||
// echo "Imported (ID: $attachment_id) & Assigned.\n";
|
||||
$count_imported++;
|
||||
} else {
|
||||
echo "Failed to import $filename. Output: $output\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo "------------------------------------------------\n";
|
||||
echo "Total imported and assigned to folder '$target_folder_name' (ID: $fbv_folder_id): $count_imported\n";
|
||||
?>
|
||||
@@ -1,139 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* The base configuration for WordPress
|
||||
*
|
||||
* The wp-config.php creation script uses this file during the installation.
|
||||
* You don't have to use the website, you can copy this file to "wp-config.php"
|
||||
* and fill in the values.
|
||||
*
|
||||
* This file contains the following configurations:
|
||||
*
|
||||
* * Database settings
|
||||
* * Secret keys
|
||||
* * Database table prefix
|
||||
* * ABSPATH
|
||||
*
|
||||
* This has been slightly modified (to read environment variables) for use in Docker.
|
||||
*
|
||||
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
// IMPORTANT: this file needs to stay in-sync with https://github.com/WordPress/WordPress/blob/master/wp-config-sample.php
|
||||
// (it gets parsed by the upstream wizard in https://github.com/WordPress/WordPress/blob/f27cb65e1ef25d11b535695a660e7282b98eb742/wp-admin/setup-config.php#L356-L392)
|
||||
|
||||
// a helper function to lookup "env_FILE", "env", then fallback
|
||||
if (!function_exists('getenv_docker')) {
|
||||
// https://github.com/docker-library/wordpress/issues/588 (WP-CLI will load this file 2x)
|
||||
function getenv_docker($env, $default) {
|
||||
if ($fileEnv = getenv($env . '_FILE')) {
|
||||
return rtrim(file_get_contents($fileEnv), "\r\n");
|
||||
}
|
||||
else if (($val = getenv($env)) !== false) {
|
||||
return $val;
|
||||
}
|
||||
else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ** Database settings - You can get this info from your web host ** //
|
||||
/** The name of the database for WordPress */
|
||||
define( 'DB_NAME', getenv_docker('WORDPRESS_DB_NAME', 'wordpress') );
|
||||
|
||||
/** Database username */
|
||||
define( 'DB_USER', getenv_docker('WORDPRESS_DB_USER', 'example username') );
|
||||
|
||||
/** Database password */
|
||||
define( 'DB_PASSWORD', getenv_docker('WORDPRESS_DB_PASSWORD', 'example password') );
|
||||
|
||||
/**
|
||||
* Docker image fallback values above are sourced from the official WordPress installation wizard:
|
||||
* https://github.com/WordPress/WordPress/blob/1356f6537220ffdc32b9dad2a6cdbe2d010b7a88/wp-admin/setup-config.php#L224-L238
|
||||
* (However, using "example username" and "example password" in your database is strongly discouraged. Please use strong, random credentials!)
|
||||
*/
|
||||
|
||||
/** Database hostname */
|
||||
define( 'DB_HOST', getenv_docker('WORDPRESS_DB_HOST', 'mysql') );
|
||||
|
||||
/** Database charset to use in creating database tables. */
|
||||
define( 'DB_CHARSET', getenv_docker('WORDPRESS_DB_CHARSET', 'utf8mb4') );
|
||||
|
||||
/** The database collate type. Don't change this if in doubt. */
|
||||
define( 'DB_COLLATE', getenv_docker('WORDPRESS_DB_COLLATE', '') );
|
||||
|
||||
/**#@+
|
||||
* Authentication unique keys and salts.
|
||||
*
|
||||
* Change these to different unique phrases! You can generate these using
|
||||
* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
|
||||
*
|
||||
* You can change these at any point in time to invalidate all existing cookies.
|
||||
* This will force all users to have to log in again.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*/
|
||||
define( 'AUTH_KEY', getenv_docker('WORDPRESS_AUTH_KEY', 'put your unique phrase here') );
|
||||
define( 'SECURE_AUTH_KEY', getenv_docker('WORDPRESS_SECURE_AUTH_KEY', 'put your unique phrase here') );
|
||||
define( 'LOGGED_IN_KEY', getenv_docker('WORDPRESS_LOGGED_IN_KEY', 'put your unique phrase here') );
|
||||
define( 'NONCE_KEY', getenv_docker('WORDPRESS_NONCE_KEY', 'put your unique phrase here') );
|
||||
define( 'AUTH_SALT', getenv_docker('WORDPRESS_AUTH_SALT', 'put your unique phrase here') );
|
||||
define( 'SECURE_AUTH_SALT', getenv_docker('WORDPRESS_SECURE_AUTH_SALT', 'put your unique phrase here') );
|
||||
define( 'LOGGED_IN_SALT', getenv_docker('WORDPRESS_LOGGED_IN_SALT', 'put your unique phrase here') );
|
||||
define( 'NONCE_SALT', getenv_docker('WORDPRESS_NONCE_SALT', 'put your unique phrase here') );
|
||||
// (See also https://wordpress.stackexchange.com/a/152905/199287)
|
||||
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* WordPress database table prefix.
|
||||
*
|
||||
* You can have multiple installations in one database if you give each
|
||||
* a unique prefix. Only numbers, letters, and underscores please!
|
||||
*
|
||||
* At the installation time, database tables are created with the specified prefix.
|
||||
* Changing this value after WordPress is installed will make your site think
|
||||
* it has not been installed.
|
||||
*
|
||||
* @link https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#table-prefix
|
||||
*/
|
||||
$table_prefix = getenv_docker('WORDPRESS_TABLE_PREFIX', 'wp_');
|
||||
|
||||
/**
|
||||
* For developers: WordPress debugging mode.
|
||||
*
|
||||
* Change this to true to enable the display of notices during development.
|
||||
* It is strongly recommended that plugin and theme developers use WP_DEBUG
|
||||
* in their development environments.
|
||||
*
|
||||
* For information on other constants that can be used for debugging,
|
||||
* visit the documentation.
|
||||
*
|
||||
* @link https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
|
||||
*/
|
||||
define( 'WP_DEBUG', !!getenv_docker('WORDPRESS_DEBUG', '') );
|
||||
|
||||
/* Add any custom values between this line and the "stop editing" line. */
|
||||
|
||||
// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
|
||||
// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
}
|
||||
// (we include this by default because reverse proxying is extremely common in container environments)
|
||||
|
||||
if ($configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '')) {
|
||||
eval($configExtra);
|
||||
}
|
||||
|
||||
/* That's all, stop editing! Happy publishing. */
|
||||
|
||||
/** Absolute path to the WordPress directory. */
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
define( 'ABSPATH', __DIR__ . '/' );
|
||||
}
|
||||
|
||||
/** Sets up WordPress vars and included files. */
|
||||
require_once ABSPATH . 'wp-settings.php';
|
||||
Reference in New Issue
Block a user