public
Created

Convert Drupal Audio content type to CCK Filefield

  • Download Gist
convert.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<?php
 
$user="USERNAME";
$password="PASSWORD";
$database="DATABASE";
mysql_connect('localhost',$user,$password);
mysql_select_db($database) or die( "Unable to select database");
// Query all the audio nodes.
$q = <<<SQL
SELECT * FROM node n
LEFT JOIN audio_file af on af.vid = n.vid
LEFT JOIN node_revisions nr on nr.vid = n.vid
WHERE type = 'audio'
SQL;
 
$result = mysql_query($q);
 
print '<pre>';
 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
 
//print_r($row);
$insert_file = sprintf("INSERT INTO `files` (`uid`, `filename`, `filepath`, `filemime`, `filesize`, `status`, `timestamp`) VALUES (%d, '%s', '%s', '%s', %d, 1, %d )",
$row['uid'],
$row['filename'],
$row['filepath'],
$row['filemime'],
$row['filesize'],
$row['timestamp']
);
//print $insert_file . "\n";
$temp = mysql_query($insert_file);
$fid = mysql_insert_id();
// INSERT INTO content_type_podcast
$insert_pod = sprintf("INSERT INTO `content_type_podcast` (`vid`, `nid`, `field_mp3_file_fid`, `field_mp3_file_list`) VALUES (%d, %d, %d, 1)",
$row['vid'],
$row['nid'],
$fid
);
 
print $insert_pod . "\n";
$temp = mysql_query($insert_pod);
 
}
 
// Update node table
$q = "UPDATE `node` n SET `type` = 'podcast' WHERE `type` = 'audio'";
mysql_query($q);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.