Exemplo n.º 1
0
 public static function addImportJob(BatchJob $parentJob = null, $entryId, $partnerId, $entryUrl, asset $asset = null, $subType = null, kImportJobData $jobData = null, $keepCurrentVersion = false)
 {
     $entryUrl = str_replace('//', '/', $entryUrl);
     $entryUrl = preg_replace('/^((https?)|(ftp)|(scp)|(sftp)):\\//', '$1://', $entryUrl);
     if (is_null($subType)) {
         if (stripos($entryUrl, 'sftp:') === 0) {
             $subType = kFileTransferMgrType::SFTP;
         } elseif (stripos($entryUrl, 'scp:') === 0) {
             $subType = kFileTransferMgrType::SCP;
         } elseif (stripos($entryUrl, 'ftp:') === 0) {
             $subType = kFileTransferMgrType::FTP;
         } elseif (stripos($entryUrl, 'https:') === 0) {
             $subType = kFileTransferMgrType::HTTPS;
         } else {
             $subType = kFileTransferMgrType::HTTP;
         }
     }
     if (!$jobData) {
         $jobData = new kImportJobData();
     }
     $jobData->setSrcFileUrl($entryUrl);
     if ($asset) {
         if ($keepCurrentVersion) {
             if (!$asset->isLocalReadyStatus()) {
                 $asset->setStatus(asset::FLAVOR_ASSET_STATUS_IMPORTING);
             }
         } else {
             $asset->incrementVersion();
             $asset->setStatus(asset::FLAVOR_ASSET_STATUS_IMPORTING);
         }
         $asset->save();
         $jobData->setFlavorAssetId($asset->getId());
     }
     $entry = entryPeer::retrieveByPK($entryId);
     if ($entry) {
         $higherStatuses = array(entryStatus::PRECONVERT, entryStatus::READY);
         if (!in_array($entry->getStatus(), $higherStatuses)) {
             $entry->setStatus(entryStatus::IMPORT);
             $entry->save();
         }
     }
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::IMPORT, $subType);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($entryId);
         $batchJob->setPartnerId($partnerId);
     }
     $batchJob->setObjectId($jobData->getFlavorAssetId());
     $batchJob->setObjectType(BatchJobObjectType::ASSET);
     return self::addJob($batchJob, $jobData, BatchJobType::IMPORT, $subType);
 }
 public function save(PropelPDO $con = null)
 {
     // check if flavor asset is new before saving
     $isNew = $this->isNew();
     $statusModified = $this->isColumnModified(assetPeer::STATUS);
     $flavorParamsIdModified = $this->isColumnModified(assetPeer::FLAVOR_PARAMS_ID);
     // save the asset
     $saveResult = parent::save();
     // update associated entry's flavorParamsId list
     if ($this->getStatus() == self::ASSET_STATUS_READY && ($isNew || $statusModified || $flavorParamsIdModified)) {
         $entry = $this->getentry();
         if (!$entry) {
             KalturaLog::err('Cannot get entry object for flavor asset id [' . $this->getId() . ']');
         } else {
             KalturaLog::debug('Adding flavor params id [' . $this->getFlavorParamsId() . '] to entry id [' . $entry->getId() . ']');
             $entry->addFlavorParamsId($this->getFlavorParamsId());
             if ($flavorParamsIdModified) {
                 $entry->removeFlavorParamsId($this->getColumnsOldValue(assetPeer::FLAVOR_PARAMS_ID));
             }
             $entry->save();
         }
     }
     // return the parent::save result
     return $saveResult;
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aasset !== null) {
             if ($this->aasset->isModified() || $this->aasset->isNew()) {
                 $affectedRows += $this->aasset->save($con);
             }
             $this->setasset($this->aasset);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = mediaInfoPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         $this->objectSaved = false;
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = mediaInfoPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
                 $this->objectSaved = true;
             } else {
                 $affectedObjects = mediaInfoPeer::doUpdate($this, $con);
                 if ($affectedObjects) {
                     $this->objectSaved = true;
                 }
                 $affectedRows += $affectedObjects;
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 4
0
 private static function conditionalAssetLocalFileSyncsDelete(FileSync $fileSync, asset $asset)
 {
     $unClosedStatuses = array(asset::ASSET_STATUS_QUEUED, asset::ASSET_STATUS_CONVERTING, asset::ASSET_STATUS_WAIT_FOR_CONVERT, asset::ASSET_STATUS_EXPORTING);
     $unClosedAssets = assetPeer::retrieveReadyByEntryId($asset->getEntryId(), null, $unClosedStatuses);
     if (count($unClosedAssets)) {
         $asset->setFileSyncVersionsToDelete(array($fileSync->getVersion()));
         $asset->save();
         return;
     }
     $assetsToDelete = assetPeer::retrieveReadyByEntryId($asset->getEntryId());
     self::deleteAssetLocalFileSyncsByAssetArray($assetsToDelete);
     self::deleteAssetLocalFileSyncs($fileSync->getVersion(), $asset);
 }