break; // Si es un tipo de datos booleano // Si es un tipo de datos booleano case 'boolean': $valor = $valor == 'True' ? 1 : 0; break; // Si es summary, no lo insertamos, lo insertaremos en el body // Si es summary, no lo insertamos, lo insertaremos en el body case 'summary': $etiqueta = ''; break; default: } if ($etiqueta) { // Creamos un elemento para añadir al array $elem = array($etiqueta => utf8_encode($valor)); // Si el tipo de campo es basic_html if ($eq_campos[$campos][1] == 'basic_html') { $elem['summary'] = utf8_encode(limpiar_estilos(html_entity_decode($contenido['Summary'][0]))); $elem['format'] = 'basic_html'; } // Añadimos el dato al array $json[$eq_campos[$campos][0]] = array($elem); } } } // Creamos el json $json = crear_json($uid, $entidad, $json); // Hacemos el POST a la API de Drupal $result = insertar_contenido($entidad, $json); echo $result['nid'][0]['value'] > 0 ? 'ok' : 'Error en registro: ArticleID = ' . $db->record['ArticleID'];
// *** This script affects your database // // CONFIGURATION // Change the value below to TRUE when you want to run the script After running, immediately // change back to FALSE in order to prevent accidentally executing this script twice. $active = FALSE; // CODE include_once "includes/bootstrap.inc"; include_once "includes/common.inc"; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $content_type = 'contacto'; $content_name = 'Contacto'; $archivo_datos = 'backup/test.csv'; if ($active) { if (user_access("administer content types")) { insertar_contenido($content_type, $archivo_datos); } else { print "No tiene permisos para administer content types"; } } else { print "exportar-empresas no ha sido activado. Ver variable {$active} al principio del c—digo fuente"; } function insertar_contenido($content_type, $archivo_datos) { $handle = fopen($archivo_datos, "r"); $theHeaders = fgetcsv($handle, 4096, "\t"); $lineno = 0; while ($line = fgetcsv($handle, 4096, "\t")) { $output .= ''; $valueno = 0; $lineno++;