CC-5896: Store cloud files in separate table, inherited from cc_files
This commit is contained in:
parent
b38f3d7e03
commit
f1ea100411
11 changed files with 165 additions and 130 deletions
|
@ -70,4 +70,34 @@ class CcFiles extends BaseCcFiles {
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function getFileSize()
|
||||
{
|
||||
return filesize($this->getAbsoluteFilePath());
|
||||
}
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
$info = pathinfo($this->getAbsoluteFilePath());
|
||||
return $info['filename'];
|
||||
}
|
||||
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
$music_dir = Application_Model_MusicDir::getDirByPK($this->
|
||||
_file->getDbDirectory());
|
||||
if (!$music_dir) {
|
||||
throw new Exception("Invalid music_dir for file in database.");
|
||||
}
|
||||
$directory = $music_dir->getDirectory();
|
||||
$filepath = $this->_file->getDbFilepath();
|
||||
|
||||
return Application_Common_OsPath::join($directory, $filepath);
|
||||
}
|
||||
|
||||
public function isValidFile()
|
||||
{
|
||||
return is_file($this->getAbsoluteFilePath());
|
||||
}
|
||||
|
||||
} // CcFiles
|
||||
|
|
|
@ -15,4 +15,39 @@
|
|||
*/
|
||||
class CloudFile extends BaseCloudFile
|
||||
{
|
||||
public function getAbsoluteFilePath()
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
return $CC_CONFIG["cloud_storage"]["host"]."/".$CC_CONFIG["cloud_storage"]["bucket"]."/" . urlencode($this->getResourceId());
|
||||
}
|
||||
|
||||
public function getFileSize()
|
||||
{
|
||||
return strlen(file_get_contents($this->getAbsoluteFilePath()));
|
||||
}
|
||||
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->getResourceId();
|
||||
}
|
||||
|
||||
public function isValidFile()
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, array(
|
||||
CURLOPT_URL => $this->getAbsoluteFilePath(),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_VERBOSE => false
|
||||
));
|
||||
curl_exec($ch);
|
||||
$http_status = curl_getinfo($ch);
|
||||
|
||||
if ($http_status["http_code"] === 200)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
public function getDbId()
|
||||
{
|
||||
|
||||
return $this->id;
|
||||
|
@ -111,7 +111,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
* @param int $v new value
|
||||
* @return CloudFile The current object (for fluent API support)
|
||||
*/
|
||||
public function setId($v)
|
||||
public function setDbId($v)
|
||||
{
|
||||
if ($v !== null && is_numeric($v)) {
|
||||
$v = (int) $v;
|
||||
|
@ -124,7 +124,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
|
||||
|
||||
return $this;
|
||||
} // setId()
|
||||
} // setDbId()
|
||||
|
||||
/**
|
||||
* Set the value of [resource_id] column.
|
||||
|
@ -623,7 +623,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
{
|
||||
switch ($pos) {
|
||||
case 0:
|
||||
return $this->getId();
|
||||
return $this->getDbId();
|
||||
break;
|
||||
case 1:
|
||||
return $this->getResourceId();
|
||||
|
@ -660,7 +660,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
$alreadyDumpedObjects['CloudFile'][$this->getPrimaryKey()] = true;
|
||||
$keys = CloudFilePeer::getFieldNames($keyType);
|
||||
$result = array(
|
||||
$keys[0] => $this->getId(),
|
||||
$keys[0] => $this->getDbId(),
|
||||
$keys[1] => $this->getResourceId(),
|
||||
$keys[2] => $this->getCcFileId(),
|
||||
);
|
||||
|
@ -708,7 +708,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
{
|
||||
switch ($pos) {
|
||||
case 0:
|
||||
$this->setId($value);
|
||||
$this->setDbId($value);
|
||||
break;
|
||||
case 1:
|
||||
$this->setResourceId($value);
|
||||
|
@ -740,7 +740,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
{
|
||||
$keys = CloudFilePeer::getFieldNames($keyType);
|
||||
|
||||
if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
|
||||
if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]);
|
||||
if (array_key_exists($keys[1], $arr)) $this->setResourceId($arr[$keys[1]]);
|
||||
if (array_key_exists($keys[2], $arr)) $this->setCcFileId($arr[$keys[2]]);
|
||||
}
|
||||
|
@ -783,7 +783,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
*/
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->getId();
|
||||
return $this->getDbId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -794,7 +794,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
*/
|
||||
public function setPrimaryKey($key)
|
||||
{
|
||||
$this->setId($key);
|
||||
$this->setDbId($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -804,7 +804,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
public function isPrimaryKeyNull()
|
||||
{
|
||||
|
||||
return null === $this->getId();
|
||||
return null === $this->getDbId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -836,7 +836,7 @@ abstract class BaseCloudFile extends BaseObject implements Persistent
|
|||
|
||||
if ($makeNew) {
|
||||
$copyObj->setNew(true);
|
||||
$copyObj->setId(NULL); // this is a auto-increment column, so set to default value
|
||||
$copyObj->setDbId(NULL); // this is a auto-increment column, so set to default value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,8 @@ abstract class BaseCloudFilePeer
|
|||
* e.g. CloudFilePeer::$fieldNames[CloudFilePeer::TYPE_PHPNAME][0] = 'Id'
|
||||
*/
|
||||
protected static $fieldNames = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('Id', 'ResourceId', 'CcFileId', ),
|
||||
BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'resourceId', 'ccFileId', ),
|
||||
BasePeer::TYPE_PHPNAME => array ('DbId', 'ResourceId', 'CcFileId', ),
|
||||
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'resourceId', 'ccFileId', ),
|
||||
BasePeer::TYPE_COLNAME => array (CloudFilePeer::ID, CloudFilePeer::RESOURCE_ID, CloudFilePeer::CC_FILE_ID, ),
|
||||
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'RESOURCE_ID', 'CC_FILE_ID', ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('id', 'resource_id', 'cc_file_id', ),
|
||||
|
@ -75,8 +75,8 @@ abstract class BaseCloudFilePeer
|
|||
* e.g. CloudFilePeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
|
||||
*/
|
||||
protected static $fieldKeys = array (
|
||||
BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'ResourceId' => 1, 'CcFileId' => 2, ),
|
||||
BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'resourceId' => 1, 'ccFileId' => 2, ),
|
||||
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'ResourceId' => 1, 'CcFileId' => 2, ),
|
||||
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'resourceId' => 1, 'ccFileId' => 2, ),
|
||||
BasePeer::TYPE_COLNAME => array (CloudFilePeer::ID => 0, CloudFilePeer::RESOURCE_ID => 1, CloudFilePeer::CC_FILE_ID => 2, ),
|
||||
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'RESOURCE_ID' => 1, 'CC_FILE_ID' => 2, ),
|
||||
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'resource_id' => 1, 'cc_file_id' => 2, ),
|
||||
|
@ -287,7 +287,7 @@ abstract class BaseCloudFilePeer
|
|||
{
|
||||
if (Propel::isInstancePoolingEnabled()) {
|
||||
if ($key === null) {
|
||||
$key = (string) $obj->getId();
|
||||
$key = (string) $obj->getDbId();
|
||||
} // if key === null
|
||||
CloudFilePeer::$instances[$key] = $obj;
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ abstract class BaseCloudFilePeer
|
|||
{
|
||||
if (Propel::isInstancePoolingEnabled() && $value !== null) {
|
||||
if (is_object($value) && $value instanceof CloudFile) {
|
||||
$key = (string) $value->getId();
|
||||
$key = (string) $value->getDbId();
|
||||
} elseif (is_scalar($value)) {
|
||||
// assume we've been passed a primary key
|
||||
$key = (string) $value;
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
* @method CloudFileQuery orderById($order = Criteria::ASC) Order by the id column
|
||||
* @method CloudFileQuery orderByDbId($order = Criteria::ASC) Order by the id column
|
||||
* @method CloudFileQuery orderByResourceId($order = Criteria::ASC) Order by the resource_id column
|
||||
* @method CloudFileQuery orderByCcFileId($order = Criteria::ASC) Order by the cc_file_id column
|
||||
*
|
||||
* @method CloudFileQuery groupById() Group by the id column
|
||||
* @method CloudFileQuery groupByDbId() Group by the id column
|
||||
* @method CloudFileQuery groupByResourceId() Group by the resource_id column
|
||||
* @method CloudFileQuery groupByCcFileId() Group by the cc_file_id column
|
||||
*
|
||||
|
@ -28,7 +28,7 @@
|
|||
* @method CloudFile findOneByResourceId(string $resource_id) Return the first CloudFile filtered by the resource_id column
|
||||
* @method CloudFile findOneByCcFileId(int $cc_file_id) Return the first CloudFile filtered by the cc_file_id column
|
||||
*
|
||||
* @method array findById(int $id) Return CloudFile objects filtered by the id column
|
||||
* @method array findByDbId(int $id) Return CloudFile objects filtered by the id column
|
||||
* @method array findByResourceId(string $resource_id) Return CloudFile objects filtered by the resource_id column
|
||||
* @method array findByCcFileId(int $cc_file_id) Return CloudFile objects filtered by the cc_file_id column
|
||||
*
|
||||
|
@ -121,7 +121,7 @@ abstract class BaseCloudFileQuery extends ModelCriteria
|
|||
* @return CloudFile A model object, or null if the key is not found
|
||||
* @throws PropelException
|
||||
*/
|
||||
public function findOneById($key, $con = null)
|
||||
public function findOneByDbId($key, $con = null)
|
||||
{
|
||||
return $this->findPk($key, $con);
|
||||
}
|
||||
|
@ -232,13 +232,13 @@ abstract class BaseCloudFileQuery extends ModelCriteria
|
|||
*
|
||||
* Example usage:
|
||||
* <code>
|
||||
* $query->filterById(1234); // WHERE id = 1234
|
||||
* $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
|
||||
* $query->filterById(array('min' => 12)); // WHERE id >= 12
|
||||
* $query->filterById(array('max' => 12)); // WHERE id <= 12
|
||||
* $query->filterByDbId(1234); // WHERE id = 1234
|
||||
* $query->filterByDbId(array(12, 34)); // WHERE id IN (12, 34)
|
||||
* $query->filterByDbId(array('min' => 12)); // WHERE id >= 12
|
||||
* $query->filterByDbId(array('max' => 12)); // WHERE id <= 12
|
||||
* </code>
|
||||
*
|
||||
* @param mixed $id The value to use as filter.
|
||||
* @param mixed $dbId The value to use as filter.
|
||||
* Use scalar values for equality.
|
||||
* Use array values for in_array() equivalent.
|
||||
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
|
||||
|
@ -246,16 +246,16 @@ abstract class BaseCloudFileQuery extends ModelCriteria
|
|||
*
|
||||
* @return CloudFileQuery The current query, for fluid interface
|
||||
*/
|
||||
public function filterById($id = null, $comparison = null)
|
||||
public function filterByDbId($dbId = null, $comparison = null)
|
||||
{
|
||||
if (is_array($id)) {
|
||||
if (is_array($dbId)) {
|
||||
$useMinMax = false;
|
||||
if (isset($id['min'])) {
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $id['min'], Criteria::GREATER_EQUAL);
|
||||
if (isset($dbId['min'])) {
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $dbId['min'], Criteria::GREATER_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if (isset($id['max'])) {
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $id['max'], Criteria::LESS_EQUAL);
|
||||
if (isset($dbId['max'])) {
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $dbId['max'], Criteria::LESS_EQUAL);
|
||||
$useMinMax = true;
|
||||
}
|
||||
if ($useMinMax) {
|
||||
|
@ -266,7 +266,7 @@ abstract class BaseCloudFileQuery extends ModelCriteria
|
|||
}
|
||||
}
|
||||
|
||||
return $this->addUsingAlias(CloudFilePeer::ID, $id, $comparison);
|
||||
return $this->addUsingAlias(CloudFilePeer::ID, $dbId, $comparison);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,7 +428,7 @@ abstract class BaseCloudFileQuery extends ModelCriteria
|
|||
public function prune($cloudFile = null)
|
||||
{
|
||||
if ($cloudFile) {
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $cloudFile->getId(), Criteria::NOT_EQUAL);
|
||||
$this->addUsingAlias(CloudFilePeer::ID, $cloudFile->getDbId(), Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue