? archive/import/1193421600.cue
? archive/import/1193421600.mp3
Index: archive/station_archive.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/archive/station_archive.install,v
retrieving revision 1.10
diff -u -p -r1.10 station_archive.install
--- archive/station_archive.install	26 Oct 2007 17:40:00 -0000	1.10
+++ archive/station_archive.install	26 Oct 2007 18:14:13 -0000
@@ -10,9 +10,10 @@ function station_archive_install() {
     case 'mysql':
     case 'mysqli':
       db_query("
-        CREATE TABLE {station_archive} (
+        CREATE TABLE {station_archive_item} (
           `audio_nid` INTEGER UNSIGNED NOT NULL DEFAULT 0,
           `program_nid` INTEGER UNSIGNED NOT NULL DEFAULT 0,
+          `aired` INTEGER UNSIGNED NOT NULL DEFAULT 0,
           `imported` INTEGER UNSIGNED NOT NULL DEFAULT 0,
           `permanent` int(2) UNSIGNED NOT NULL DEFAULT '0',
           PRIMARY KEY(`audio_nid`, `program_nid`),
@@ -34,8 +35,8 @@ function station_archive_install() {
  * Implementation of hook_uninstall().
  */
 function station_archive_uninstall() {
-  // Remvoe our tables.
-  db_query('DROP TABLE {station_archive}');
+  // Remove our tables.
+  db_query('DROP TABLE {station_archive_item}');
   db_query('DROP TABLE {station_archive_program}');
 
   // Remove our taxonomy.
@@ -160,3 +161,21 @@ function station_archive_update_5200() {
   }
   return $ret;
 }
+
+/**
+ * Add rename {station_archive} to {station_archive_item} and add a .aired
+ * column to record the node's original air date. Use the node's creation date
+ * as a default value.
+ */
+function station_archive_update_5201() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {station_archive} RENAME TO {station_archive_item}");
+      $ret[] = update_sql("ALTER TABLE {station_archive_item} ADD COLUMN `aired` INTEGER UNSIGNED NOT NULL DEFAULT 0 AFTER `program_nid`");
+      $ret[] = update_sql("UPDATE {station_archive_item} sai INNER JOIN {node} n ON sai.audio_nid = n.nid SET sai.aired = n.created WHERE n.type = 'audio'");
+      break;
+  }
+  return $ret;
+}
Index: archive/station_archive.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/archive/station_archive.module,v
retrieving revision 1.35
diff -u -p -r1.35 station_archive.module
--- archive/station_archive.module	26 Oct 2007 17:22:37 -0000	1.35
+++ archive/station_archive.module	26 Oct 2007 18:14:13 -0000
@@ -302,8 +302,7 @@ function station_archive_nodeapi(&$node,
       case 'prepare':
         // if they clicked the button, reload the program information
         if (t('Reload Program') == $_POST['op']) {
-          // use the create timestamp as the
-          $gmt_timestamp = (integer) $node->created;
+          $gmt_timestamp = $node->station_archive['aired'];
           // get a timestamp that's correct for the timezone
           $local_timestamp = station_local_ts($gmt_timestamp);
           $prettydate = date('ga \o\n M jS, Y', $local_timestamp);
@@ -352,16 +351,17 @@ function station_archive_nodeapi(&$node,
 
       case 'update':
         if (isset($node->station_archive) && user_access('administer archive')) {
-          // If there was an existing import time use that, if not use the
-          // current time.
-          $imported = db_result(db_query('SELECT imported AS imported FROM {station_archive} WHERE audio_nid = %d', $node->nid));
-          $imported = !empty($imported) ? $imported : time();
-
-          // Remove any existing records and if this is in the archive, create
-          // a new record.
-          db_query("DELETE FROM {station_archive} WHERE audio_nid = %d", $node->nid);
+          // Remove any existing records.
+          db_query("DELETE FROM {station_archive_item} WHERE audio_nid = %d", $node->nid);
+          // If this should be in the archive, create a new record.
           if ($node->station_archive['archived']) {
-            db_query("INSERT INTO {station_archive} (audio_nid, program_nid, imported, permanent) VALUES (%d, %d, %d, %d)", $node->nid, $node->station_archive['program_nid'], $imported, $node->station_archive['permanent']);
+            if (empty($node->station_archive['aired'])) {
+              $node->station_archive['aired'] = (integer) $node->created;
+            }
+            if (empty($node->station_archive['imported'])) {
+              $node->station_archive['imported'] = time();
+            }
+            db_query("INSERT INTO {station_archive_item} (audio_nid, program_nid, aired, imported, permanent) VALUES (%d, %d, %d, %d, %d)", $node->nid, $node->station_archive['program_nid'], $node->station_archive['aired'], $node->station_archive['imported'], $node->station_archive['permanent']);
           }
         }
         break;
@@ -370,13 +370,13 @@ function station_archive_nodeapi(&$node,
         // remove our tracking records when the audio node is deleted. we only
         // assume that audio node are on this machine, the program nodes could
         // be on a remote server.
-        db_query('DELETE FROM {station_archive} WHERE audio_nid = %d', $node->nid);
+        db_query('DELETE FROM {station_archive_item} WHERE audio_nid = %d', $node->nid);
         break;
 
       case 'load':
         // Sneak the '1 AS archived' in so we've got a value to indicate that
         // this node is in the archive. 
-        $row = db_fetch_array(db_query("SELECT 1 AS archived, sa.program_nid, sap.title AS program_title, sa.imported, sa.permanent FROM {station_archive} sa LEFT OUTER JOIN {station_archive_program} sap ON sa.program_nid = sap.program_nid WHERE sa.audio_nid = %d", $node->nid));
+        $row = db_fetch_array(db_query("SELECT 1 AS archived, sa.program_nid, sa.aired, sap.title AS program_title, sa.imported, sa.permanent FROM {station_archive_item} sa LEFT OUTER JOIN {station_archive_program} sap ON sa.program_nid = sap.program_nid WHERE sa.audio_nid = %d", $node->nid));
         if ($row) {
           return array('station_archive' => $row);
         }
@@ -447,7 +447,13 @@ function station_archive_form_alter($for
         foreach (station_archive_get_programs() as $nid => $program) {
           $program_options[$nid] = $program->title;
         }
-
+        $form['station_archive']['aired'] = array(
+          '#type' => 'item',
+          '#title' => t('Air date'),
+          '#default_value' => $node->station_archive['aired'],
+          '#description' => t("The date the program first aired."),
+          '#weight' => -1,
+        );
         $form['station_archive']['archived'] = array(
           '#type' => 'checkbox',
           '#title' => t('In Station Archive'),
@@ -562,7 +568,7 @@ function station_archive_cron() {
  */
 function _station_archive_delete_old_nodes() {
   $cutoff = time() - variable_get('station_archive_max_age', 604800);
-  $result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {station_archive} sa ON n.nid = sa.audio_nid WHERE sa.permanent = 0 AND sa.imported < %d', $cutoff);
+  $result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {station_archive_item} sa ON n.nid = sa.audio_nid WHERE sa.permanent = 0 AND sa.imported < %d', $cutoff);
   while ($node = db_fetch_object($result)) {
     watchdog('stationarchive', t('Removing %title from the archive.', array('%title' => $node->title)), WATCHDOG_NOTICE);
     node_delete($node->nid);
@@ -585,6 +591,7 @@ function _station_archive_import_files()
       // if there's a .cue file, it's still being downloaded, we'll get it on
       // the next cron call.
       if (!file_exists($cuefile)) {
+        watchdog('stationarchive', t('Attempting to import %filename into the archive.', array('%filename' => $file->filename)), WATCHDOG_NOTICE);
         $status = _station_archive_add_file($file);
         // if there was a problem stop the import
         if (!$status) {
@@ -645,7 +652,7 @@ function _station_archive_update_program
 function _station_archive_add_file($file) {
   // extract the timestamp from the filename (should be simply timestamp.mp3)
   $basename = explode('.', $file->basename);
-  $gmt_timestamp = $basename[0];
+  $gmt_timestamp = (int) $basename[0];
   $file_format = $basename[1];
   // get a timestamp that's correct for the timezone
   $local_timestamp = station_local_ts($gmt_timestamp);
@@ -679,7 +686,7 @@ function _station_archive_add_file($file
   }
   else {
     // we've got program information
-    $program_nid = $program->nid;
+    $program_nid = (int) $program->nid;
     $program_title = $program->title;
     $audio_tags['artist'] = station_anded_list($program->djs);
     $audio_tags['genre'] = $program->genre;
@@ -694,6 +701,13 @@ function _station_archive_add_file($file
   $node = audio_api_insert($file->filename, $title_format, $audio_tags);
 
   // make any other changes to the node...
+  $node->station_archive = array(
+    'archived' => 1,
+    'program_nid' => $program_nid,
+    'aired' => $gmt_timestamp,
+    'imported' => time(),
+    'permanent' => 0,
+  );
   $node->audio_file['downloadable'] = 1;
   $node->created = $gmt_timestamp;
   // find/create the proper taxonomic terms based on day and hour
@@ -702,16 +716,12 @@ function _station_archive_add_file($file
   $node->promote = (int) ($program && variable_get('station_archive_promote_scheduled', 1));
   // keep the timestamp as the filename so we can re-import again if needed but
   // store a more readable filename for the user.
-  $prettyname = str_replace(' ', '_', $audio_tags['title'] ." ($prettydate).$file_format");
-  $node->audio_file['file_name'] = $prettyname;
+  $node->audio_file['file_name'] = str_replace(' ', '_', $audio_tags['title'] ." ($prettydate).$file_format");
 
   // ... and save it
   $node = node_submit($node);
   node_save($node);
 
-  // record an association of the audio and program node ids and the time it was imported.
-  db_query("INSERT INTO {station_archive} (audio_nid, program_nid, imported) VALUES (%d, %d, %d)", $node->nid, $program_nid, time());
-
   watchdog('stationarchive', t('Added %title to the archive.', array('%title' => $program_title)), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid));
 
   return TRUE;
Index: archive/views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/archive/views.inc,v
retrieving revision 1.7
diff -u -p -r1.7 views.inc
--- archive/views.inc	22 Aug 2007 04:56:21 -0000	1.7
+++ archive/views.inc	26 Oct 2007 18:14:13 -0000
@@ -6,8 +6,8 @@
  * Implementation of hook_views_tables().
  */
 function station_archive_views_tables() {
-  $tables['station_archive'] = array(
-    'name' => 'station_archive',
+  $tables['station_archive_item'] = array(
+    'name' => 'station_archive_item',
     'join' => array(
       'left' => array(
         'table' => 'node',
@@ -18,8 +18,15 @@ function station_archive_views_tables() 
       )
     ),
     'fields' => array(
+      'aired' => array(
+        'name' => t('Station Archive: Air date'),
+        'sortable' => TRUE,
+        'handler' => views_handler_field_dates(),
+        'option' => 'string',
+        'help' => t('Date the audio was aired.'),
+      ),
       'imported' => array(
-        'name' => t('Station Archive: Import Date'),
+        'name' => t('Station Archive: Import date'),
         'sortable' => TRUE,
         'handler' => views_handler_field_dates(),
         'option' => 'string',
@@ -40,7 +47,7 @@ function station_archive_views_tables() 
     'name' => 'station_archive_program',
     'join' => array(
       'left' => array(
-        'table' => 'station_archive',
+        'table' => 'station_archive_item',
         'field' => 'program_nid'
       ),
       'right' => array(
@@ -88,7 +95,7 @@ function station_archive_arg_program_nid
       $query->ensure_table('node');
       $query->add_field('nid', 'node');
       // now onto our regularly scheduled program
-      $query->ensure_table('station_archive');
+      $query->ensure_table('station_archive_item');
       $query->ensure_table('station_archive_program');
       $query->add_field('title', 'station_archive_program');
       $query->add_field('program_nid', 'station_archive_program');
@@ -100,7 +107,7 @@ function station_archive_arg_program_nid
       $query->add_orderby('station_archive_program', 'title', $argtype);
       break;
     case 'filter':
-      $query->ensure_table("station_archive");
+      $query->ensure_table("station_archive_item");
       $query->add_where("station_archive.program_nid = %d", $arg);
       break;
     case 'link':
Index: archive/scripts/ripper.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/station/archive/scripts/ripper.inc,v
retrieving revision 1.4
diff -u -p -r1.4 ripper.inc
--- archive/scripts/ripper.inc	10 Aug 2007 17:13:14 -0000	1.4
+++ archive/scripts/ripper.inc	26 Oct 2007 18:14:13 -0000
@@ -8,7 +8,7 @@ stream_url = "http://127.0.0.1:8000/high
 streamripper_path = "/usr/local/bin/streamripper"
 
 ; Full path to station archive module's import directory (no trailing slash)
-import_path = "/usr/local/www/drupal/modules/station/archive/import"
+import_path = "/usr/local/www/drupal/sites/all/modules/station/archive/import"
 
 ; Because shows tend to start early or finish late, the overlap_seconds
 ; setting allows you to determine how much the recording should overlap at the
