Decouple pypo from Airtime install

-first commit
This commit is contained in:
Martin Konecny 2013-04-19 20:10:51 -04:00
parent 7cf11b820a
commit f39f9329cc
4 changed files with 116 additions and 87 deletions

View file

@ -20,6 +20,11 @@ class Application_Model_StoredFile
*/
private $_file;
/**
* @holds PDO object reference
*/
private $_con;
/**
* array of db metadata -> propel
*/
@ -53,6 +58,11 @@ class Application_Model_StoredFile
"cueout" => "DbCueOut",
);
function __construct($file, $con) {
$this->_file = $file;
$this->_con = $con;
}
public function getId()
{
return $this->_file->getDbId();
@ -86,9 +96,8 @@ class Application_Model_StoredFile
$this->_file->save();
}
public static function createWithFile($f) {
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $f;
public static function createWithFile($f, $con) {
$storedFile = new Application_Model_StoredFile($f, $con);
return $storedFile;
}
@ -218,7 +227,7 @@ class Application_Model_StoredFile
}
$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->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();
}
public static function Insert($md)
public static function Insert($md, $con)
{
// save some work by checking if filepath is given right away
if ( !isset($md['MDATA_KEY_FILEPATH']) ) {
@ -556,8 +565,7 @@ SQL;
$file->setDbUtime($now);
$file->setDbMtime($now);
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $file;
$storedFile = new Application_Model_StoredFile($file, $con);
// removed "//" in the path. Always use '/' for path separator
// 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,
$p_filepath=null) {
if( isset($p_id ) ) {
$f = CcFilesQuery::create()->findPK(intval($p_id));
return is_null($f) ? null : self::createWithFile($f);
$p_filepath=null, $con=null) {
//TODO
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) ) {
throw new Exception("You should never use gunid ($gunid) anymore");
} elseif ( isset($p_md5sum) ) {
throw new Exception("Searching by md5($p_md5sum) is disabled");
} elseif ( isset($p_filepath) ) {
return is_null($f) ? null : self::createWithFile(
Application_Model_StoredFile::RecallByFilepath($p_filepath));
return is_null($f) ? null : Application_Model_StoredFile::RecallByFilepath($p_filepath, $con);
} 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.
* @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);
@ -615,11 +628,11 @@ SQL;
$file = CcFilesQuery::create()
->filterByDbDirectory($music_dir->getId())
->filterByDbFilepath($path_info[1])
->findOne();
return is_null($file) ? null : self::createWithFile($file);
->findOne($con);
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);
@ -631,11 +644,10 @@ SQL;
$files = CcFilesQuery::create()
->filterByDbDirectory($music_dir->getId())
->filterByDbFilepath("$path_info[1]%")
->find();
->find($con);
$res = array();
foreach ($files as $file) {
$storedFile = new Application_Model_StoredFile();
$storedFile->_file = $file;
$storedFile = new Application_Model_StoredFile($file, $con);
$res[] = $storedFile;
}