Created
November 3, 2011 00:27
-
-
Save shanestillwell/1335420 to your computer and use it in GitHub Desktop.
Convert Drupal Audio content type to CCK Filefield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment