Skip to main content

Lekukotzak inportatu

<?php
if(!user_access('toponimo admin')){
drupal_access_denied();
exit;
}

if(isset($_GET['ekin'])){

doit();
$output .= '<p>Lekukotzak inportatu dira.</p>';

} else {
print '<p>Lekukotasunak nodo bihurtu: '.l('ekin', $_GET['q'], array('query' => 'ekin=1')).'</p>';
}

/* // nodoak sortu
function doit(){
$result = db_query('SELECT id, 3 uid, 1 status, "lekukotasun" type, TOPONIMOA title, OHARRAK body FROM topo_ahozko WHERE nid = "" LIMIT 0, 1000');
while($row = db_fetch_object($result)){
node_save($row);
db_query('UPDATE topo_ahozko SET nid = %d WHERE id = %d', $row->nid, $row->id);
}

}
*/

/*
function doit(){
$result = db_query('SELECT nid, DATA1, DATA2 FROM topo_ahozko');
while($row = db_fetch_object($result)){
db_query('UPDATE content_type_lekukotasun SET field_urtea_value = %d, field_urtea2_value = %d WHERE nid = %d', $row->DATA1, $row->DATA2, $row->nid);
}

}
*/

// bikoiztutako lekukotasunak nodo-loturatan erantsi
function doit(){
$result = db_query('SELECT nr.pnid, nr.type, l.nid FROM `content_type_lekukotasun` l LEFT JOIN node_relations nr ON nr.nid = l.nid WHERE field_errefbibl_value LIKE "%,%" AND field_iturri_value = "A" ORDER BY field_gaurko_value, l.nid');
while($row = db_fetch_object($result)){
$pnid = isset($row->pnid) ? $row->pnid : $pnid;
$type = isset($row->type) ? $row->type : $type;
// print "$pnid $type $row->nid<br>";
db_query('REPLACE INTO node_relations(pnid, type, nid) VALUES(%d, %d, %d)', $pnid, $type, $row->nid);
}
}

/*
function doit(){
$result = db_query('SELECT n.*, l.field_errefbibl_value FROM node n LEFT JOIN node_revisions nr ON n.vid = nr.vid LEFT JOIN content_type_lekukotasun l ON n.vid = l.vid WHERE l.field_iturri_value ="0" AND LENGTH(l.field_errefbibl_value) > 2');

while($row = db_fetch_object($result)){
$berriemale = explode(',', $row->field_errefbibl_value);
array_shift($berriemale);
foreach($berriemale as $v){
$vid = $row->vid;
unset($row->nid); unset($row->vid); // nodo berria sortu behar dugu
node_save($row); // vid berria erantsiko dio
db_query('REPLACE into content_type_lekukotasun SELECT '.$row->vid.' vid, '.$row->nid.' nid, `field_sinonimo_value`, `field_gaurko_value`, `field_objetu_value`, `field_auzo_value`, `field_auzune_value`, `field_errefbibl_value`, `field_ohar_value`, `field_berriemale_value`, `field_biltzaile_value`, `field_errefkart_value`, `field_iturri_value`, `field_audio_fid`, `field_audio_list`, `field_audio_data`, `field_urtea_value`, `field_urtea2_value` FROM content_type_lekukotasun WHERE vid = %d', $vid);
db_query('UPDATE content_type_lekukotasun SET field_berriemale_value = %d WHERE vid = %d', $v, $row->nid);

}
}
}
*/

/* // Moldaketak
function doit(){
$result = db_query('SELECT nid, moldaketak FROM topo_ahozko WHERE !ISNULL(moldaketak)');
while($row = db_fetch_object($result)){
preg_match_all('/[0-9]/', $row->moldaketak, $zaku);
foreach($zaku[0] as $k => $v){
//print "$k > $v <br>";
db_query('REPLACE INTO content_field_moldaketa (vid, nid, delta, field_moldaketa_value) VALUES(%d, %d, %d, %d)', $row->nid, $row->nid, $k, $v);
}
}

}
*/

?>