Example #1
0
 public function dispatchMetadata($md, $mode)
 {
     $return_hash = array();
     Application_Model_Preference::SetImportTimestamp();
     //Logging::info("--->Mode: $mode || file: {$md['MDATA_KEY_FILEPATH']} ");
     //Logging::info( $md );
     // create also modifies the file if it exists
     if ($mode == "create") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = Application_Common_OsPath::normpath($filepath);
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $file = Application_Model_StoredFile::Insert($md);
         } else {
             // If the file already exists we will update and make sure that
             // it's marked as 'exists'.
             $file->setFileExistsFlag(true);
             $file->setMetadata($md);
         }
         if ($md['is_record'] != 0) {
             $this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
         }
     } elseif ($mode == "modify") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         //File is not in database anymore.
         if (is_null($file)) {
             $return_hash['error'] = "File does not exist in Airtime.";
             return $return_hash;
         } else {
             $file->setMetadata($md);
         }
     } elseif ($mode == "moved") {
         $file = Application_Model_StoredFile::RecallByFilepath($md['MDATA_KEY_ORIGINAL_PATH']);
         if (is_null($file)) {
             $return_hash['error'] = 'File does not exist in Airtime';
         } else {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             //$filepath = str_replace("\\", "", $filepath);
             $file->setFilePath($filepath);
         }
     } elseif ($mode == "delete") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = str_replace("\\", "", $filepath);
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $return_hash['error'] = "File doesn't exist in Airtime.";
             Logging::warn("Attempt to delete file that doesn't exist.\n                    Path: '{$filepath}'");
             return $return_hash;
         } else {
             $file->deleteByMediaMonitor();
         }
     } elseif ($mode == "delete_dir") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         //$filepath = str_replace("\\", "", $filepath);
         $files = Application_Model_StoredFile::RecallByPartialFilepath($filepath);
         foreach ($files as $file) {
             $file->deleteByMediaMonitor();
         }
         $return_hash['success'] = 1;
         return $return_hash;
     }
     $return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
     return $return_hash;
 }
 public function dispatchMetadata($md, $mode)
 {
     $return_hash = array();
     Application_Model_Preference::SetImportTimestamp();
     $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
     $con->beginTransaction();
     try {
         // create also modifies the file if it exists
         if ($mode == "create") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = Application_Common_OsPath::normpath($filepath);
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             if (is_null($file)) {
                 $file = Application_Model_StoredFile::Insert($md, $con);
             } else {
                 // If the file already exists we will update and make sure that
                 // it's marked as 'exists'.
                 $file->setFileExistsFlag(true);
                 $file->setFileHiddenFlag(false);
                 $file->setMetadata($md);
             }
             if ($md['is_record'] != 0) {
                 $this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
             }
         } elseif ($mode == "modify") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             //File is not in database anymore.
             if (is_null($file)) {
                 $return_hash['error'] = _("File does not exist in Airtime.");
             } else {
                 //CC-5207 - restart media-monitor causes it to reevaluate all
                 //files in watched directories, and reset their cue-in/cue-out
                 //values. Since media-monitor has nothing to do with cue points
                 //let's unset it here. Note that on mode == "create", we still
                 //want media-monitor sending info about cue_out which by default
                 //will be equal to length of track until silan can take over.
                 unset($md['MDATA_KEY_CUE_IN']);
                 unset($md['MDATA_KEY_CUE_OUT']);
                 $file->setMetadata($md);
             }
         } elseif ($mode == "moved") {
             $file = Application_Model_StoredFile::RecallByFilepath($md['MDATA_KEY_ORIGINAL_PATH'], $con);
             if (is_null($file)) {
                 $return_hash['error'] = _('File does not exist in Airtime');
             } else {
                 $filepath = $md['MDATA_KEY_FILEPATH'];
                 //$filepath = str_replace("\\", "", $filepath);
                 $file->setFilePath($filepath);
             }
         } elseif ($mode == "delete") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = str_replace("\\", "", $filepath);
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             if (is_null($file)) {
                 $return_hash['error'] = _("File doesn't exist in Airtime.");
                 Logging::warn("Attempt to delete file that doesn't exist.\n                        Path: '{$filepath}'");
             } else {
                 $file->deleteByMediaMonitor();
             }
         } elseif ($mode == "delete_dir") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             //$filepath = str_replace("\\", "", $filepath);
             $files = Application_Model_StoredFile::RecallByPartialFilepath($filepath, $con);
             foreach ($files as $file) {
                 $file->deleteByMediaMonitor();
             }
             $return_hash['success'] = 1;
         }
         if (!isset($return_hash['error'])) {
             $return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
         }
         $con->commit();
     } catch (Exception $e) {
         Logging::warn("rolling back");
         Logging::warn($e->getMessage());
         $con->rollback();
         $return_hash['error'] = $e->getMessage();
     }
     return $return_hash;
 }
Example #3
0
 public function reloadMetadataAction()
 {
     global $CC_CONFIG;
     $request = $this->getRequest();
     $api_key = $request->getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     $mode = $request->getParam('mode');
     $params = $request->getParams();
     $md = array();
     //extract all file metadata params from the request.
     foreach ($params as $key => $value) {
         if (preg_match('/^MDATA_KEY/', $key)) {
             $md[$key] = $value;
         }
     }
     // update import timestamp
     Application_Model_Preference::SetImportTimestamp();
     if ($mode == "create") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = str_replace("\\", "", $filepath);
         $file = StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $file = StoredFile::Insert($md);
         } else {
             $this->view->error = "File already exists in Airtime.";
             return;
         }
     } else {
         if ($mode == "modify") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = str_replace("\\", "", $filepath);
             $file = StoredFile::RecallByFilepath($filepath);
             //File is not in database anymore.
             if (is_null($file)) {
                 $this->view->error = "File does not exist in Airtime.";
                 return;
             } else {
                 $file->setMetadata($md);
             }
         } else {
             if ($mode == "moved") {
                 $md5 = $md['MDATA_KEY_MD5'];
                 $file = StoredFile::RecallByMd5($md5);
                 if (is_null($file)) {
                     $this->view->error = "File doesn't exist in Airtime.";
                     return;
                 } else {
                     $filepath = $md['MDATA_KEY_FILEPATH'];
                     $filepath = str_replace("\\", "", $filepath);
                     $file->setFilePath($filepath);
                     //$file->setMetadata($md);
                 }
             } else {
                 if ($mode == "delete") {
                     $filepath = $md['MDATA_KEY_FILEPATH'];
                     $filepath = str_replace("\\", "", $filepath);
                     $file = StoredFile::RecallByFilepath($filepath);
                     if (is_null($file)) {
                         $this->view->error = "File doesn't exist in Airtime.";
                         return;
                     } else {
                         $file->delete();
                     }
                 }
             }
         }
     }
     $this->view->id = $file->getId();
 }