'bmp', 'image/jpeg' => 'jpg', 'image/png' => 'png', 'image/gif' => 'gif' ); function convertQueues() { global $globaldbh; $query = "DELETE FROM " . NEWQUEUESTABLE . " WHERE type='user'"; $sth = $globaldbh->prepare($query); $sth->execute(); $query = "INSERT INTO " . NEWQUEUESTABLE . " (name) SELECT qname FROM " . OLDQUEUESTABLE . " WHERE qtype='user'"; $sth = $globaldbh->prepare($query); $sth->execute(); } function convertQueueContents() { global $globaldbh; $totalcount = 0; $convertedcount = 0; $queues = array(); $query = "DELETE " . QUEUECONTENTSTABLE . " FROM " . QUEUECONTENTSTABLE . " LEFT JOIN " . NEWQUEUESTABLE . " ON qid=id WHERE type='user'"; $sth = $globaldbh->prepare($query); $sth->execute(); $query = "SELECT id, name FROM " . NEWQUEUESTABLE; $sth = $globaldbh->prepare($query); $sth->execute(); while ( $row = $sth->fetch() ) { $queues[$row['name']] = $row['id']; } $query = "SELECT fullpath, qname FROM " . OLDSONGSTABLE . " LEFT JOIN " . OLDQUEUESTABLE . " ON qid=id WHERE qtype='user'"; $sth = $globaldbh->prepare($query); $sth->execute(); $query_new = "INSERT INTO " . QUEUECONTENTSTABLE . " (qid, songid) VALUES(:qid, :songid)"; $sth_new = $globaldbh->prepare($query_new); $query_search = "SELECT id FROM " . SONGSTABLE . " WHERE song=:song AND genre=:genre"; $sth_search = $globaldbh->prepare($query_search); while ( $row = $sth->fetch() ) { $fields_search = array(); $fields_search[':song'] = basename($row['fullpath']); list($fields_search[':genre'], $junk) = explode("/", substr($row['fullpath'], strlen(MP3ROOTDIR)), 2); $sth_search->execute($fields_search); $totalcount++; if ( $row_search = $sth_search->fetch() ) { $fields_new = array(); $fields_new[':qid'] = $queues[$row['qname']]; $fields_new[':songid'] = $row_search['id']; $sth_new->execute($fields_new); $convertedcount++; if ( ($convertedcount % 100) == 0 ) echo "."; } else { echo "Couldn't find: ", $fields_search[':song'], " in ", $fields_search[':genre'], "\n"; } } return array($totalcount, $convertedcount); } echo "Converting DB:\n\n"; echo "Converting user queues...\n"; convertQueues(); echo "Converting user queue contents..."; $convcount = convertQueueContents(); echo " converted ", $convcount[1], " out of ", $convcount[0], " songs in old queues.\n"; ?>