From 355b0ad35dabcf190dae56af5ae250e6020aac95 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:02:39 -0400 Subject: [PATCH 1/8] cc-4292: Initial fix of the MD5 issue. Now MD5's are only collected not really used for anything. Moves are handled completely through paths. --- airtime_mvc/application/controllers/ApiController.php | 7 ++++--- airtime_mvc/application/models/Webstream.php | 2 +- python_apps/media-monitor2/media/monitor/events.py | 11 +++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 57b4efddd..5bdbd298a 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -513,11 +513,11 @@ class ApiController extends Zend_Controller_Action $file->setMetadata($md); } } elseif ($mode == "moved") { - $md5 = $md['MDATA_KEY_MD5']; - $file = Application_Model_StoredFile::RecallByMd5($md5); + $file = Application_Model_StoredFile::RecallByFilepath( + $md['MDATA_KEY_ORIGINAL_PATH']); if (is_null($file)) { - return "File doesn't exist in Airtime."; + $return_hash['error'] = 'File does not exist in Airtime'; } else { $filepath = $md['MDATA_KEY_FILEPATH']; //$filepath = str_replace("\\", "", $filepath); @@ -661,6 +661,7 @@ class ApiController extends Zend_Controller_Action } } elseif ($mode == "moved") { $md5 = $md['MDATA_KEY_MD5']; + Logging::info("Original path: {$md['MDATA_KEY_ORIGINAL_PATH']}"); $file = Application_Model_StoredFile::RecallByMd5($md5); if (is_null($file)) { diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index 9b054fa04..838de4235 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -46,7 +46,7 @@ class Application_Model_Webstream implements Application_Model_LibraryEditable $di = new DateInterval("PT{$hours}H{$min}M{$sec}S"); return $di->format("%Hh %Im"); - } + } return ""; } diff --git a/python_apps/media-monitor2/media/monitor/events.py b/python_apps/media-monitor2/media/monitor/events.py index 1941ea5b1..88c7c1b30 100644 --- a/python_apps/media-monitor2/media/monitor/events.py +++ b/python_apps/media-monitor2/media/monitor/events.py @@ -110,7 +110,7 @@ class BaseEvent(Loggable): # nothing to see here, please move along def morph_into(self, evt): self.logger.info("Morphing %s into %s" % ( str(self), str(evt) ) ) - self._raw_event = evt + self._raw_event = evt._raw_event self.path = evt.path self.__class__ = evt.__class__ # Clean up old hook and transfer the new events hook @@ -181,11 +181,14 @@ class MoveFile(BaseEvent, HasMetaData): """ def __init__(self, *args, **kwargs): super(MoveFile, self).__init__(*args, **kwargs) + def old_path(self): + return self._raw_event.src_pathname def pack(self): - req_dict = {} - req_dict['mode'] = u'moved' + req_dict = {} + req_dict['mode'] = u'moved' + req_dict['MDATA_KEY_ORIGINAL_PATH'] = self.old_path() + req_dict['MDATA_KEY_FILEPATH'] = unicode( self.path ) req_dict['MDATA_KEY_MD5'] = self.metadata.extract()['MDATA_KEY_MD5'] - req_dict['MDATA_KEY_FILEPATH'] = unicode( self.path ) return [req_dict] class ModifyFile(BaseEvent, HasMetaData): From d95731f2f382915de8ace1c6361b134ce7ed19df Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:13:39 -0400 Subject: [PATCH 2/8] Reformatted sql to use heredoc --- airtime_mvc/application/models/StoredFile.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index e69599ce8..3d1956b8c 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1101,10 +1101,14 @@ class Application_Model_StoredFile try { $con = Propel::getConnection(); - $sql = "SELECT soundcloud_id as id, soundcloud_upload_time" - ." FROM CC_FILES" - ." WHERE (id != -2 and id != -3) and" - ." (soundcloud_upload_time >= (now() - (INTERVAL '1 day')))"; + $sql = <<= (now() - (INTERVAL '1 day'))) +SQL; $rows = $con->query($sql)->fetchAll(); From 51d4f35c55404e58335254042d8f54fece6ebba0 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:15:15 -0400 Subject: [PATCH 3/8] Removed unused global variable --- airtime_mvc/application/models/StoredFile.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 3d1956b8c..92eecca8f 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -1024,11 +1024,8 @@ class Application_Model_StoredFile public static function getFileCount() { - global $CC_CONFIG; $con = Propel::getConnection(); - $sql = "SELECT count(*) as cnt FROM cc_files WHERE file_exists"; - return $con->query($sql)->fetchColumn(0); } From 0dd38920a35e31942d66de9614451d89e8b16646 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:20:59 -0400 Subject: [PATCH 4/8] Cosmetic changes. --- airtime_mvc/application/models/StoredFile.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 92eecca8f..211c1d9e4 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -315,12 +315,13 @@ class Application_Model_StoredFile */ public function getPlaylists() { - global $CC_CONFIG; $con = Propel::getConnection(); - $sql = "SELECT playlist_id " - ." FROM cc_playlist" - ." WHERE file_id = :file_id"; + $sql = <<prepare($sql); $stmt->bindParam(':file_id', $this->id, PDO::PARAM_INT); @@ -332,14 +333,13 @@ class Application_Model_StoredFile throw new Exception("Error: $msg"); } - $playlists = array(); if (is_array($ids) && count($ids) > 0) { - foreach ($ids as $id) { - $playlists[] = Application_Model_Playlist::Recall($id); - } + return array_map( function ($id) { + return Application_Model_Playlist::Recall($id); + }, $ids); + } else { + return array(); } - - return $playlists; } /** @@ -593,7 +593,6 @@ class Application_Model_StoredFile public function getName() { $info = pathinfo($this->getFilePath()); - return $info['filename']; } From 728a0dd7368b1fe2e501e5c818a7b667596c2697 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:24:59 -0400 Subject: [PATCH 5/8] Added todo documenting slight inefficiency --- airtime_mvc/application/controllers/ApiController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airtime_mvc/application/controllers/ApiController.php b/airtime_mvc/application/controllers/ApiController.php index 5bdbd298a..a352fd677 100644 --- a/airtime_mvc/application/controllers/ApiController.php +++ b/airtime_mvc/application/controllers/ApiController.php @@ -454,6 +454,8 @@ class ApiController extends Zend_Controller_Action $showCanceled = true; } + // TODO : the following is inefficient because it calls save on both + // fields $file->setMetadataValue('MDATA_KEY_CREATOR', "Airtime Show Recorder"); $file->setMetadataValue('MDATA_KEY_TRACKNUMBER', $show_instance_id); From 72a424bb7ebf9f820c67e14907d6639caed7d749 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:25:45 -0400 Subject: [PATCH 6/8] Added todo to fix crust --- airtime_mvc/application/models/StoredFile.php | 1 + 1 file changed, 1 insertion(+) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 211c1d9e4..62f2afc82 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -226,6 +226,7 @@ class Application_Model_StoredFile return; } if (isset($this->_dbMD[$p_category])) { + // TODO : fix this crust -- RG $propelColumn = $this->_dbMD[$p_category]; $method = "set$propelColumn"; $this->_file->$method($p_value); From b0a7f60b10d8f8a8d132cb60a42098c4d478cdb9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 16:29:45 -0400 Subject: [PATCH 7/8] Fixed typo --- python_apps/media-monitor2/media/monitor/airtime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python_apps/media-monitor2/media/monitor/airtime.py b/python_apps/media-monitor2/media/monitor/airtime.py index 1cd81b3dc..5e31dbfe4 100644 --- a/python_apps/media-monitor2/media/monitor/airtime.py +++ b/python_apps/media-monitor2/media/monitor/airtime.py @@ -135,7 +135,7 @@ class AirtimeMessageReceiver(Loggable): msg['directory']) self.new_watch(msg) else: - self.__reFalsequest_now_bootstrap( directory=msg['directory'], + self.__request_now_bootstrap( directory=msg['directory'], all_files=restart) self.manager.add_watch_directory(msg['directory']) From 03d3dc831275fd69320659f8663668fa4ede2621 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 11 Sep 2012 17:03:49 -0400 Subject: [PATCH 8/8] Added good debugging for removed_watch_directory --- python_apps/media-monitor2/media/monitor/manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python_apps/media-monitor2/media/monitor/manager.py b/python_apps/media-monitor2/media/monitor/manager.py index 53599f3cb..78a5c8d92 100644 --- a/python_apps/media-monitor2/media/monitor/manager.py +++ b/python_apps/media-monitor2/media/monitor/manager.py @@ -231,6 +231,8 @@ class Manager(Loggable): else: self.logger.info("'%s' is not being watched, hence cannot be \ removed" % watch_dir) + self.logger.info("The directories we are watching now are:") + self.logger.info( self.__wd_path ) def loop(self): """