CC-4992:
Decouple pypo from Airtime install -first commit
This commit is contained in:
parent
7cf11b820a
commit
f39f9329cc
|
@ -511,81 +511,88 @@ class ApiController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
$return_hash = array();
|
$return_hash = array();
|
||||||
Application_Model_Preference::SetImportTimestamp();
|
Application_Model_Preference::SetImportTimestamp();
|
||||||
//Logging::info("--->Mode: $mode || file: {$md['MDATA_KEY_FILEPATH']} ");
|
|
||||||
//Logging::info( $md );
|
|
||||||
|
|
||||||
// create also modifies the file if it exists
|
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
||||||
if ($mode == "create") {
|
$con->beginTransaction();
|
||||||
$filepath = $md['MDATA_KEY_FILEPATH'];
|
try {
|
||||||
$filepath = Application_Common_OsPath::normpath($filepath);
|
// create also modifies the file if it exists
|
||||||
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
|
if ($mode == "create") {
|
||||||
if (is_null($file)) {
|
$filepath = $md['MDATA_KEY_FILEPATH'];
|
||||||
$file = Application_Model_StoredFile::Insert($md);
|
$filepath = Application_Common_OsPath::normpath($filepath);
|
||||||
} else {
|
$file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
|
||||||
// If the file already exists we will update and make sure that
|
if (is_null($file)) {
|
||||||
// it's marked as 'exists'.
|
$file = Application_Model_StoredFile::Insert($md, $con);
|
||||||
$file->setFileExistsFlag(true);
|
} else {
|
||||||
$file->setFileHiddenFlag(false);
|
// If the file already exists we will update and make sure that
|
||||||
$file->setMetadata($md);
|
// it's marked as 'exists'.
|
||||||
}
|
$file->setFileExistsFlag(true);
|
||||||
if ($md['is_record'] != 0) {
|
$file->setFileHiddenFlag(false);
|
||||||
$this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
|
$file->setMetadata($md);
|
||||||
}
|
}
|
||||||
|
if ($md['is_record'] != 0) {
|
||||||
} elseif ($mode == "modify") {
|
$this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
|
||||||
$filepath = $md['MDATA_KEY_FILEPATH'];
|
}
|
||||||
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
|
|
||||||
|
} elseif ($mode == "modify") {
|
||||||
|
$filepath = $md['MDATA_KEY_FILEPATH'];
|
||||||
|
$file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
|
||||||
|
|
||||||
//File is not in database anymore.
|
//File is not in database anymore.
|
||||||
if (is_null($file)) {
|
if (is_null($file)) {
|
||||||
$return_hash['error'] = _("File does not exist in Airtime.");
|
$return_hash['error'] = _("File does not exist in Airtime.");
|
||||||
|
|
||||||
return $return_hash;
|
return $return_hash;
|
||||||
}
|
}
|
||||||
//Updating a metadata change.
|
//Updating a metadata change.
|
||||||
else {
|
else {
|
||||||
$file->setMetadata($md);
|
$file->setMetadata($md);
|
||||||
}
|
}
|
||||||
} elseif ($mode == "moved") {
|
} elseif ($mode == "moved") {
|
||||||
$file = Application_Model_StoredFile::RecallByFilepath(
|
$file = Application_Model_StoredFile::RecallByFilepath(
|
||||||
$md['MDATA_KEY_ORIGINAL_PATH']);
|
$md['MDATA_KEY_ORIGINAL_PATH'], $con);
|
||||||
|
|
||||||
if (is_null($file)) {
|
if (is_null($file)) {
|
||||||
$return_hash['error'] = _('File does not exist in Airtime');
|
$return_hash['error'] = _('File does not exist in Airtime');
|
||||||
} else {
|
} 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.
|
||||||
|
Path: '$filepath'");
|
||||||
|
|
||||||
|
return $return_hash;
|
||||||
|
} else {
|
||||||
|
$file->deleteByMediaMonitor();
|
||||||
|
}
|
||||||
|
} elseif ($mode == "delete_dir") {
|
||||||
$filepath = $md['MDATA_KEY_FILEPATH'];
|
$filepath = $md['MDATA_KEY_FILEPATH'];
|
||||||
//$filepath = str_replace("\\", "", $filepath);
|
//$filepath = str_replace("\\", "", $filepath);
|
||||||
$file->setFilePath($filepath);
|
$files = Application_Model_StoredFile::RecallByPartialFilepath($filepath, $con);
|
||||||
}
|
|
||||||
} elseif ($mode == "delete") {
|
|
||||||
$filepath = $md['MDATA_KEY_FILEPATH'];
|
|
||||||
$filepath = str_replace("\\", "", $filepath);
|
|
||||||
$file = Application_Model_StoredFile::RecallByFilepath($filepath);
|
|
||||||
|
|
||||||
if (is_null($file)) {
|
foreach ($files as $file) {
|
||||||
$return_hash['error'] = _("File doesn't exist in Airtime.");
|
$file->deleteByMediaMonitor();
|
||||||
Logging::warn("Attempt to delete file that doesn't exist.
|
}
|
||||||
Path: '$filepath'");
|
$return_hash['success'] = 1;
|
||||||
|
|
||||||
return $return_hash;
|
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) {
|
$return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
|
||||||
$file->deleteByMediaMonitor();
|
$con->commit();
|
||||||
}
|
} catch (Exception $e) {
|
||||||
$return_hash['success'] = 1;
|
Logging::warn("rolling back");
|
||||||
|
Logging::warn($e->getMessage());
|
||||||
return $return_hash;
|
$con->rollback();
|
||||||
|
$return_hash['error'] = $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
$return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
|
|
||||||
|
|
||||||
return $return_hash;
|
return $return_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,6 +611,10 @@ class ApiController extends Zend_Controller_Action
|
||||||
// least 1 digit
|
// least 1 digit
|
||||||
if ( !preg_match('/^md\d+$/', $k) ) { continue; }
|
if ( !preg_match('/^md\d+$/', $k) ) { continue; }
|
||||||
$info_json = json_decode($raw_json, $assoc = true);
|
$info_json = json_decode($raw_json, $assoc = true);
|
||||||
|
|
||||||
|
Logging::info($info_json);
|
||||||
|
//$info_json['MDATA_KEY_TRACKNUMBER'] = '4294967295';
|
||||||
|
|
||||||
// Log invalid requests
|
// Log invalid requests
|
||||||
if ( !array_key_exists('mode', $info_json) ) {
|
if ( !array_key_exists('mode', $info_json) ) {
|
||||||
Logging::info("Received bad request(key=$k), no 'mode' parameter. Bad request is:");
|
Logging::info("Received bad request(key=$k), no 'mode' parameter. Bad request is:");
|
||||||
|
@ -627,7 +638,12 @@ class ApiController extends Zend_Controller_Action
|
||||||
// Removing 'mode' key from $info_json might not be necessary...
|
// Removing 'mode' key from $info_json might not be necessary...
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
unset( $info_json['mode'] );
|
unset( $info_json['mode'] );
|
||||||
$response = $this->dispatchMetadata($info_json, $mode);
|
try {
|
||||||
|
$response = $this->dispatchMetadata($info_json, $mode);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Logging::warn($e->getMessage());
|
||||||
|
Logging::warn(gettype($e));
|
||||||
|
}
|
||||||
// We tack on the 'key' back to every request in case the would like to associate
|
// We tack on the 'key' back to every request in case the would like to associate
|
||||||
// his requests with particular responses
|
// his requests with particular responses
|
||||||
$response['key'] = $k;
|
$response['key'] = $k;
|
||||||
|
|
|
@ -838,6 +838,7 @@ SQL;
|
||||||
{
|
{
|
||||||
$utcTimeZone = new DateTimeZone("UTC");
|
$utcTimeZone = new DateTimeZone("UTC");
|
||||||
$items = self::getItems($range_start, $range_end);
|
$items = self::getItems($range_start, $range_end);
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
$showEndDateTime = new DateTime($item["show_end"], $utcTimeZone);
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ class Application_Model_Scheduler
|
||||||
|
|
||||||
if ($type === "audioclip") {
|
if ($type === "audioclip") {
|
||||||
$file = CcFilesQuery::create()->findPK($id, $this->con);
|
$file = CcFilesQuery::create()->findPK($id, $this->con);
|
||||||
$storedFile = new Application_Model_StoredFile($file->getDbId());
|
$storedFile = new Application_Model_StoredFile($file, $this->con);
|
||||||
|
|
||||||
if (is_null($file) || !$file->visible()) {
|
if (is_null($file) || !$file->visible()) {
|
||||||
throw new Exception(_("A selected File does not exist!"));
|
throw new Exception(_("A selected File does not exist!"));
|
||||||
|
|
|
@ -20,6 +20,11 @@ class Application_Model_StoredFile
|
||||||
*/
|
*/
|
||||||
private $_file;
|
private $_file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @holds PDO object reference
|
||||||
|
*/
|
||||||
|
private $_con;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of db metadata -> propel
|
* array of db metadata -> propel
|
||||||
*/
|
*/
|
||||||
|
@ -53,6 +58,11 @@ class Application_Model_StoredFile
|
||||||
"cueout" => "DbCueOut",
|
"cueout" => "DbCueOut",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function __construct($file, $con) {
|
||||||
|
$this->_file = $file;
|
||||||
|
$this->_con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
return $this->_file->getDbId();
|
return $this->_file->getDbId();
|
||||||
|
@ -86,9 +96,8 @@ class Application_Model_StoredFile
|
||||||
$this->_file->save();
|
$this->_file->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createWithFile($f) {
|
public static function createWithFile($f, $con) {
|
||||||
$storedFile = new Application_Model_StoredFile();
|
$storedFile = new Application_Model_StoredFile($f, $con);
|
||||||
$storedFile->_file = $f;
|
|
||||||
return $storedFile;
|
return $storedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +227,7 @@ class Application_Model_StoredFile
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
$this->_file->setDbMtime(new DateTime("now", new DateTimeZone("UTC")));
|
||||||
$this->_file->save();
|
$this->_file->save($this->_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -491,7 +500,7 @@ SQL;
|
||||||
|
|
||||||
$this->_file->setDbDirectory($musicDir->getId());
|
$this->_file->setDbDirectory($musicDir->getId());
|
||||||
$this->_file->setDbFilepath($path_info[1]);
|
$this->_file->setDbFilepath($path_info[1]);
|
||||||
$this->_file->save();
|
$this->_file->save($this->_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -544,7 +553,7 @@ SQL;
|
||||||
return $baseUrl."api/get-media/file/".$this->getId().".".$this->getFileExtension();
|
return $baseUrl."api/get-media/file/".$this->getId().".".$this->getFileExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Insert($md)
|
public static function Insert($md, $con)
|
||||||
{
|
{
|
||||||
// save some work by checking if filepath is given right away
|
// save some work by checking if filepath is given right away
|
||||||
if ( !isset($md['MDATA_KEY_FILEPATH']) ) {
|
if ( !isset($md['MDATA_KEY_FILEPATH']) ) {
|
||||||
|
@ -556,8 +565,7 @@ SQL;
|
||||||
$file->setDbUtime($now);
|
$file->setDbUtime($now);
|
||||||
$file->setDbMtime($now);
|
$file->setDbMtime($now);
|
||||||
|
|
||||||
$storedFile = new Application_Model_StoredFile();
|
$storedFile = new Application_Model_StoredFile($file, $con);
|
||||||
$storedFile->_file = $file;
|
|
||||||
|
|
||||||
// removed "//" in the path. Always use '/' for path separator
|
// removed "//" in the path. Always use '/' for path separator
|
||||||
// TODO : it might be better to just call OsPath::normpath on the file
|
// TODO : it might be better to just call OsPath::normpath on the file
|
||||||
|
@ -575,19 +583,24 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null,
|
public static function Recall($p_id=null, $p_gunid=null, $p_md5sum=null,
|
||||||
$p_filepath=null) {
|
$p_filepath=null, $con=null) {
|
||||||
if( isset($p_id ) ) {
|
|
||||||
$f = CcFilesQuery::create()->findPK(intval($p_id));
|
//TODO
|
||||||
return is_null($f) ? null : self::createWithFile($f);
|
if (is_null($con)) {
|
||||||
|
$con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($p_id)) {
|
||||||
|
$f = CcFilesQuery::create()->findPK(intval($p_id), $con);
|
||||||
|
return is_null($f) ? null : self::createWithFile($f, $con);
|
||||||
} elseif ( isset($p_gunid) ) {
|
} elseif ( isset($p_gunid) ) {
|
||||||
throw new Exception("You should never use gunid ($gunid) anymore");
|
throw new Exception("You should never use gunid ($gunid) anymore");
|
||||||
} elseif ( isset($p_md5sum) ) {
|
} elseif ( isset($p_md5sum) ) {
|
||||||
throw new Exception("Searching by md5($p_md5sum) is disabled");
|
throw new Exception("Searching by md5($p_md5sum) is disabled");
|
||||||
} elseif ( isset($p_filepath) ) {
|
} elseif ( isset($p_filepath) ) {
|
||||||
return is_null($f) ? null : self::createWithFile(
|
return is_null($f) ? null : Application_Model_StoredFile::RecallByFilepath($p_filepath, $con);
|
||||||
Application_Model_StoredFile::RecallByFilepath($p_filepath));
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("No arguments passsed to Recall");
|
throw new Exception("No arguments passed to Recall");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,7 +616,7 @@ SQL;
|
||||||
* @param string $p_filepath path of file stored in Airtime.
|
* @param string $p_filepath path of file stored in Airtime.
|
||||||
* @return Application_Model_StoredFile|NULL
|
* @return Application_Model_StoredFile|NULL
|
||||||
*/
|
*/
|
||||||
public static function RecallByFilepath($p_filepath)
|
public static function RecallByFilepath($p_filepath, $con)
|
||||||
{
|
{
|
||||||
$path_info = Application_Model_MusicDir::splitFilePath($p_filepath);
|
$path_info = Application_Model_MusicDir::splitFilePath($p_filepath);
|
||||||
|
|
||||||
|
@ -615,11 +628,11 @@ SQL;
|
||||||
$file = CcFilesQuery::create()
|
$file = CcFilesQuery::create()
|
||||||
->filterByDbDirectory($music_dir->getId())
|
->filterByDbDirectory($music_dir->getId())
|
||||||
->filterByDbFilepath($path_info[1])
|
->filterByDbFilepath($path_info[1])
|
||||||
->findOne();
|
->findOne($con);
|
||||||
return is_null($file) ? null : self::createWithFile($file);
|
return is_null($file) ? null : self::createWithFile($file, $con);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function RecallByPartialFilepath($partial_path)
|
public static function RecallByPartialFilepath($partial_path, $con)
|
||||||
{
|
{
|
||||||
$path_info = Application_Model_MusicDir::splitFilePath($partial_path);
|
$path_info = Application_Model_MusicDir::splitFilePath($partial_path);
|
||||||
|
|
||||||
|
@ -631,11 +644,10 @@ SQL;
|
||||||
$files = CcFilesQuery::create()
|
$files = CcFilesQuery::create()
|
||||||
->filterByDbDirectory($music_dir->getId())
|
->filterByDbDirectory($music_dir->getId())
|
||||||
->filterByDbFilepath("$path_info[1]%")
|
->filterByDbFilepath("$path_info[1]%")
|
||||||
->find();
|
->find($con);
|
||||||
$res = array();
|
$res = array();
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$storedFile = new Application_Model_StoredFile();
|
$storedFile = new Application_Model_StoredFile($file, $con);
|
||||||
$storedFile->_file = $file;
|
|
||||||
$res[] = $storedFile;
|
$res[] = $storedFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue