Ejemplo n.º 1
0
 /**
  * Function constructs a core object of type kBulkUploadJobData
  * @param int $conversionProfileId
  * @param string $filePath
  * @param string $userId
  * @param int $bulkUploadType
  * @param string $uploadedBy
  * @param string $fileName
  * @throws KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND
  */
 protected function constructJobData($filePath, $fileName, Partner $partner, $puserId, $uploadedBy, $conversionProfileId = null, $coreBulkUploadType = null)
 {
     $data = KalturaPluginManager::loadObject('kBulkUploadJobData', $coreBulkUploadType);
     if (is_null($data)) {
         throw new KalturaAPIException(KalturaErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $coreBulkUploadType);
     }
     $data->setFilePath($filePath);
     $data->setUserId($puserId);
     $data->setUploadedBy($uploadedBy);
     $data->setFileName($fileName);
     if (!$conversionProfileId) {
         $conversionProfileId = $partner->getDefaultConversionProfileId();
     }
     $kmcVersion = $partner->getKmcVersion();
     $check = null;
     if ($kmcVersion < 2) {
         $check = ConversionProfilePeer::retrieveByPK($conversionProfileId);
     } else {
         $check = conversionProfile2Peer::retrieveByPK($conversionProfileId);
     }
     if (!$check) {
         throw new KalturaAPIException(KalturaErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $conversionProfileId);
     }
     $objectData = new kBulkUploadEntryData();
     $objectData->setConversionProfileId($conversionProfileId);
     $data->setObjectData($objectData);
     return $data;
 }
Ejemplo n.º 2
0
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner, $permissionRequiredOnly = false)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         /* @var $conversionProfile conversionProfile2 */
         if ($permissionRequiredOnly && !count($conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         if (!self::isPartnerPermittedForCopy($toPartner, $conversionProfile->getRequiredCopyTemplatePermissions())) {
             continue;
         }
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         try {
             $newConversionProfile->save();
         } catch (Exception $e) {
             KalturaLog::info("Exception occured, conversion profile was not copied. Message: [" . $e->getMessage() . "]");
             continue;
         }
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
         }
     }
     if (!$toPartner->getDefaultLiveConversionProfileId()) {
         $fromPartnerDefaultLiveProfile = $fromPartner->getDefaultLiveConversionProfileId();
         if ($fromPartnerDefaultLiveProfile && key_exists($fromPartnerDefaultLiveProfile, $copiedList)) {
             $toPartner->setDefaultLiveConversionProfileId($copiedList[$fromPartnerDefaultLiveProfile]);
         }
     }
     $toPartner->save();
 }
Ejemplo n.º 3
0
 /**
  * Function adds bulk upload job to the queue
  * @param Partner $partner
  * @param kBulkUploadJobData $jobData
  * @param string $bulkUploadType
  * @throws APIException
  * @return BatchJob
  */
 public static function addBulkUploadJob(Partner $partner, kBulkUploadJobData $jobData, $bulkUploadType = null, $objectId = null, $objectType = null)
 {
     KalturaLog::debug("adding BulkUpload job");
     $job = new BatchJob();
     $job->setPartnerId($partner->getId());
     $job->setJobType(BatchJobType::BULKUPLOAD);
     $job->setJobSubType($bulkUploadType);
     if (!is_null($objectId) && !is_null($objectType)) {
         $job->setObjectId($objectId);
         $job->setObjectType($objectType);
     }
     if (is_null($jobData)) {
         throw new APIException(APIErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $bulkUploadType);
     }
     $job->setStatus(BatchJob::BATCHJOB_STATUS_DONT_PROCESS);
     $job = kJobsManager::addJob($job, $jobData, BatchJobType::BULKUPLOAD, $bulkUploadType);
     if (!is_null($jobData->getFilePath())) {
         $syncKey = $job->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD);
         //		kFileSyncUtils::file_put_contents($syncKey, file_get_contents($csvFileData["tmp_name"]));
         try {
             kFileSyncUtils::moveFromFile($jobData->getFilePath(), $syncKey, true);
         } catch (Exception $e) {
             KalturaLog::err($e);
             throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
         }
         $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
         $jobData->setFilePath($filePath);
     }
     if (!$jobData->getBulkUploadObjectType()) {
         $jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY);
     }
     if ($jobData->getBulkUploadObjectType() == BulkUploadObjectType::ENTRY && !$jobData->getObjectData()->getConversionProfileId()) {
         $jobData->setConversionProfileId($partner->getDefaultConversionProfileId());
         $kmcVersion = $partner->getKmcVersion();
         $check = null;
         if ($kmcVersion < 2) {
             $check = ConversionProfilePeer::retrieveByPK($jobData->getConversionProfileId());
         } else {
             $check = conversionProfile2Peer::retrieveByPK($jobData->getConversionProfileId());
         }
         if (!$check) {
             throw new APIException(APIErrors::CONVERSION_PROFILE_ID_NOT_FOUND, $jobData->getConversionProfileId());
         }
     }
     $job->setData($jobData);
     return kJobsManager::updateBatchJob($job, BatchJob::BATCHJOB_STATUS_PENDING);
 }
 public static function copyConversionProfiles(Partner $fromPartner, Partner $toPartner)
 {
     $copiedList = array();
     KalturaLog::log("Copying conversion profiles from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     $c = new Criteria();
     $c->add(conversionProfile2Peer::PARTNER_ID, $fromPartner->getId());
     $conversionProfiles = conversionProfile2Peer::doSelect($c);
     foreach ($conversionProfiles as $conversionProfile) {
         $newConversionProfile = $conversionProfile->copy();
         $newConversionProfile->setPartnerId($toPartner->getId());
         $newConversionProfile->save();
         KalturaLog::log("Copied [" . $conversionProfile->getId() . "], new id is [" . $newConversionProfile->getId() . "]");
         $copiedList[$conversionProfile->getId()] = $newConversionProfile->getId();
         $c = new Criteria();
         $c->add(flavorParamsConversionProfilePeer::CONVERSION_PROFILE_ID, $conversionProfile->getId());
         $fpcpList = flavorParamsConversionProfilePeer::doSelect($c);
         foreach ($fpcpList as $fpcp) {
             $flavorParamsId = $fpcp->getFlavorParamsId();
             $flavorParams = assetParamsPeer::retrieveByPK($flavorParamsId);
             if ($flavorParams && $flavorParams->getPartnerId() === 0) {
                 $newFpcp = $fpcp->copy();
                 $newFpcp->setConversionProfileId($newConversionProfile->getId());
                 $newFpcp->save();
             }
         }
     }
     $toPartner->save();
     // make sure conversion profile is set on the new partner in case it was missed/skiped in the conversionProfile2::copy method
     if (!$toPartner->getDefaultConversionProfileId()) {
         $fromPartnerDefaultProfile = $fromPartner->getDefaultConversionProfileId();
         if ($fromPartnerDefaultProfile && key_exists($fromPartnerDefaultProfile, $copiedList)) {
             $toPartner->setDefaultConversionProfileId($copiedList[$fromPartnerDefaultProfile]);
             $toPartner->save();
         }
     }
 }