Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("config.php");
- $db = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
- // verificar si hay conexión con la base de datos
- if ($db->connect_errno) {
- echo "Error: Fallo al conectarse a MySQL debido a:", EOL;
- echo "Errno: " . $db->connect_errno . EOL;
- echo "Error: " . $db->connect_error . EOL;
- exit;
- }
- // // Consulta para extraer los registros a importar
- // $sqlOriginPosts = "SELECT * FROM wp5x_posts WHERE ID > 1116; ";
- // // Ejecución de consulta
- // $rsPostA = $db->query($sqlOriginPosts);
- // // Mensaje debug
- // echo " Se encontraron: {$rsPostA->num_rows} artículos ", EOL;
- // // fecha de hoy
- // $today = Date('Y-m-d h:i:s');
- // // Si hay registros
- // if ($rsPostA->num_rows) {
- // // Mientras el recordset pueda obtener objetos
- // while ($postOrigen = $rsPostA->fetch_object()) {
- // // Debug para el post que se elige
- // echo "postOrigen->ID: {$postOrigen->ID}", EOL;
- // // Consulta SQL para insertar el registro actual en la tabla de wp5x_posts
- // $sqlInsertPost = "INSERT INTO `wp5x_posts`
- // (`ID`,`post_author`, `post_date`, `post_date_gmt`, `post_content`,
- // `post_title`, `post_excerpt`, `post_status`, `comment_status`,
- // `ping_status`, `post_password`, `post_name`, `to_ping`,
- // `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`,
- // `post_parent`, `guid`, `menu_order`, `post_type`,
- // `post_mime_type`, `comment_count`)
- // VALUES
- // ('".mysqli_escape_string($db, $postOrigen->ID)."', 1, '{$today}', '{$today}', '".mysqli_escape_string($db, $postOrigen->post_content)."',
- // '".mysqli_escape_string($db, $postOrigen->post_title)."', '".mysqli_escape_string($db, $postOrigen->post_date_gmt)."', '".mysqli_escape_string($db, $postOrigen->post_status)."', '".mysqli_escape_string($db, $postOrigen->comment_status)."',
- // '".mysqli_escape_string($db, $postOrigen->ping_status)."', '".mysqli_escape_string($db, $postOrigen->post_password)."', '".mysqli_escape_string($db, $postOrigen->post_name)."', '".mysqli_escape_string($db, $postOrigen->to_ping)."',
- // '".mysqli_escape_string($db, $postOrigen->pinged)."', '".mysqli_escape_string($db, $postOrigen->post_modified)."', '".mysqli_escape_string($db, $postOrigen->post_modified_gmt)."', '".mysqli_escape_string($db, $postOrigen->post_content_filtered)."',
- // '".mysqli_escape_string($db, $postOrigen->post_parent)."', '".mysqli_escape_string($db, $postOrigen->guid)."', '".mysqli_escape_string($db, $postOrigen->menu_order)."', '".mysqli_escape_string($db, $postOrigen->post_type)."',
- // '".mysqli_escape_string($db, $postOrigen->post_mime_type)."', '".mysqli_escape_string($db, $postOrigen->comment_count)."');";
- //
- // // Ejecución de la primer inserción
- // if (!mysqli_query($db, $sqlInsertPost)) {
- // printf("\$sqlInsertPost: Errormessage: %s\n", mysqli_error($db));
- // } else {
- // echo " --- --- \t POST: Registro insertado ".EOL;
- // }
- //
- // // Consulta para insertar las relaciones del post con los terms de destino;
- // $sqlInsertTermRelationship = "INSERT INTO `wp5x_term_relationships`
- // (`object_id`, `term_taxonomy_id`)
- // VALUES
- // ('".mysqli_escape_string($db, $postOrigen->ID)."', '".mysqli_escape_string($db, $postOrigen->post_parent)."');";
- //
- //
- // if (!mysqli_query($db, $sqlInsertTermRelationship)) {
- // printf("\$sqlInsertTermRelationship: Errormessage: %s\n", mysqli_error($link));
- // } else {
- // echo " --- --- \t RELATIONSHIP: Registro insertado ".EOL;
- // }
- //
- //
- // }
- // }
- function slugify($text)
- {
- // replace non letter or digits by -
- $text = preg_replace('~[^\pL\d]+~u', '-', $text);
- // transliterate
- $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
- // remove unwanted characters
- $text = preg_replace('~[^-\w]+~', '', $text);
- // trim
- $text = trim($text, '-');
- // remove duplicate -
- $text = preg_replace('~-+~', '-', $text);
- // lowercase
- $text = strtolower($text);
- if (empty($text)) {
- return 'n-a';
- }
- return $text;
- }
- $db = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
- // verificar si hay conexión con la base de datos
- if ($db->connect_errno) {
- echo "Error: Fallo al conectarse a MySQL debido a:", EOL;
- echo "Errno: " . $db->connect_errno . EOL;
- echo "Error: " . $db->connect_error . EOL;
- exit;
- }
- // Consulta para extraer los registros a importar
- $sqlOriginPosts = "SELECT * FROM wp5x_posts WHERE ID > 1116; ";
- // Ejecución de consulta
- $rsPostA = $db->query($sqlOriginPosts);
- // Mensaje debug
- echo " Se encontraron: {$rsPostA->num_rows} artículos ", EOL;
- // fecha de hoy
- // $today = Date('Y-m-d h:i:s');
- // Si hay registros
- if ($rsPostA->num_rows) {
- // Mientras el recordset pueda obtener objetos
- echo " START TRANSACTION ; ", EOL;
- while ($postOrigen = $rsPostA->fetch_object()) {
- // Debug para el post que se elige
- // echo "postOrigen->ID: {$postOrigen->ID}", EOL;
- // Consulta SQL para insertar el registro actual en la tabla de wp5x_posts
- if (slugify($postOrigen->post_name) == 'n-a') {
- // Si el guid tiene extensión png o jpg
- if (strstr($postOrigen->guid, 'png') || strstr($postOrigen->guid, 'jpg')) {
- // le quito todo lo que no ocupo hasta donde empieza la ruta del artículo de social engine
- $tmpImgName = substr($postOrigen->guid, 15);
- echo $sqlUpdateSlug = "UPDATE wp5x_posts SET guid = 'http://studiopigmento.com/bodycultures/".mysqli_escape_string($db, $tmpImgName)."' WHERE ID = '".mysqli_escape_string($db, $postOrigen->ID)."' ;";
- echo EOL;
- }
- }
- }
- echo " COMMIT;", EOL;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement