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(); }