CC-1799 Put Airtime Storage into a Human Readable File Naming Convention

plupload is now working how I want with moving files.
stub files are added then their metadata updated as the web receives info.
This commit is contained in:
Naomi Aro 2011-06-14 18:35:07 +02:00
parent 17d895861d
commit af4ec7b872
3 changed files with 37 additions and 17 deletions

View File

@ -370,8 +370,15 @@ class ApiController extends Zend_Controller_Action
exit;
}
$plupload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
//need to make sure plupload dir exists so we can watch it.
if(!file_exists($plupload_dir)) {
@mkdir($plupload_dir, 0755);
}
$this->view->stor = $CC_CONFIG['storageDir'];
$this->view->plupload = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$this->view->plupload = $plupload_dir;
}
public function mediaItemStatusAction() {
@ -414,7 +421,6 @@ class ApiController extends Zend_Controller_Action
if ($mode == "create") {
$md5 = $md['MDATA_KEY_MD5'];
$file = StoredFile::RecallByMd5($md5);
if (is_null($file)) {
@ -441,16 +447,15 @@ class ApiController extends Zend_Controller_Action
}
}
else if ($mode == "moved") {
$filepath = $md['MDATA_KEY_FILEPATH'];
$filepath = str_replace("\\", "", $filepath);
$file = StoredFile::RecallByFilepath($filepath);
$md5 = $md['MDATA_KEY_MD5'];
$file = StoredFile::RecallByMd5($md5);
if (is_null($file)) {
$this->view->error = "File doesn't exist in Airtime.";
return;
}
else {
$file->setMetadataValue('MDATA_KEY_FILEPATH', $md['new_filepath']);
$file->setMetadata($md);
}
}
else if ($mode == "delete") {

View File

@ -737,7 +737,6 @@ class StoredFile {
global $CC_CONFIG;
$stor = $CC_CONFIG["storageDir"];
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
$r = @rename($audio_file, $audio_stor);
$md = array();
$md['MDATA_KEY_MD5'] = $md5;
@ -745,6 +744,7 @@ class StoredFile {
$md['MDATA_KEY_TITLE'] = $fileName;
StoredFile::Insert($md);
$r = @rename($audio_file, $audio_stor);
}
}

View File

@ -266,10 +266,10 @@ class MediaMonitor(ProcessEvent):
return md
def update_airtime(self, **kwargs):
def update_airtime(self, d):
filepath = kwargs['filepath']
mode = kwargs['mode']
filepath = d['filepath']
mode = d['mode']
data = None
md = {}
@ -284,7 +284,8 @@ class MediaMonitor(ProcessEvent):
md.update(mutagen)
data = {'md': md}
elif (mode == MODE_MOVED):
md['new_filepath'] = kwargs['new_filepath']
mutagen = self.get_mutagen_info(filepath)
md.update(mutagen)
data = {'md': md}
elif (mode == MODE_DELETE):
data = {'md': md}
@ -322,7 +323,7 @@ class MediaMonitor(ProcessEvent):
else :
global plupload_directory
#files that have been added through plupload have a placeholder already put in Airtime's database.
if not self.is_parent_directory(event.pathname, plupload_directory)
if not self.is_parent_directory(event.pathname, plupload_directory):
md5 = self.get_md5(event.pathname)
response = self.api_client.check_media_status(md5)
@ -334,6 +335,9 @@ class MediaMonitor(ProcessEvent):
def process_IN_MODIFY(self, event):
if not event.dir:
self.logger.info("%s: %s", event.maskname, event.pathname)
global plupload_directory
#files that have been added through plupload have a placeholder already put in Airtime's database.
if not self.is_parent_directory(event.pathname, plupload_directory):
if self.is_audio_file(event.name) :
self.file_events.append({'filepath': event.pathname, 'mode': MODE_MODIFY})
@ -353,9 +357,20 @@ class MediaMonitor(ProcessEvent):
elif event.cookie in self.moved_files:
old_filepath = self.moved_files[event.cookie]
del self.moved_files[event.cookie]
self.file_events.append({'filepath': old_filepath,'new_filepath': event.pathname, 'mode': MODE_MOVED})
global plupload_directory
#add a modify event to send md to Airtime for the plupload file.
if self.is_parent_directory(old_filepath, plupload_directory):
#file renamed from /tmp/plupload does not have a path in our naming scheme yet.
md_filepath = self.create_file_path(event.pathname)
#move the file a second time to its correct Airtime naming schema.
os.rename(event.pathname, md_filepath)
self.file_events.append({'filepath': md_filepath, 'mode': MODE_MOVED})
else:
self.file_events.append({'filepath': event.pathname, 'mode': MODE_MOVED})
def process_IN_DELETE(self, event):
if not event.dir:
self.logger.info("%s: %s", event.maskname, event.pathname)
self.file_events.append({'filepath': event.pathname, 'mode': MODE_DELETE})