Beispiel #1
0
 /**
  * The type and the sub-type are constant in the batch job, therefore they must be proveided
  * when a new batch job is generated.
  * @return BatchJob
  */
 public function createChild($type, $subType = null, $same_root = true, $dc = null)
 {
     $child = new BatchJob();
     $child->setJobType($type);
     if ($subType !== null) {
         $child->setJobSubType($subType);
     }
     $child->setParentJobId($this->id);
     $child->setPartnerId($this->partner_id);
     $child->setEntryId($this->entry_id);
     $child->setBulkJobId($this->bulk_job_id);
     // the condition is required in the special case of file_sync import jobs which are created on one dc but run from the other
     $child->setDc($dc === null ? $this->dc : $dc);
     if ($same_root && $this->root_job_id) {
         $child->setRootJobId($this->root_job_id);
     } else {
         $child->setRootJobId($this->id);
     }
     return $child;
 }
 /**
  * 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)
 {
     $job = new BatchJob();
     $job->setPartnerId($partner->getId());
     $job->setJobType(BatchJobType::BULKUPLOAD);
     $job->setJobSubType($bulkUploadType);
     $job->save();
     $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) {
         throw new APIException(APIErrors::BULK_UPLOAD_CREATE_CSV_FILE_SYNC_ERROR);
     }
     $filePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     if (is_null($jobData)) {
         throw new APIException(APIErrors::BULK_UPLOAD_BULK_UPLOAD_TYPE_NOT_VALID, $bulkUploadType);
     }
     if (!$jobData->getBulkUploadObjectType()) {
         $jobData->setBulkUploadObjectType(BulkUploadObjectType::ENTRY);
     }
     $jobData->setFilePath($filePath);
     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());
         }
     }
     return kJobsManager::addJob($job, $jobData, BatchJobType::BULKUPLOAD, kPluginableEnumsManager::apiToCore("BulkUploadType", $bulkUploadType));
 }
Beispiel #3
0
 public static function addExportLiveReportJob($reportType, KalturaLiveReportExportParams $params)
 {
     KalturaLog::debug("adding Export Live Report job");
     // Calculate time offset from server time to UTC
     $dateTimeZoneServer = new DateTimeZone(kConf::get('date_default_timezone'));
     $dateTimeZoneUTC = new DateTimeZone("UTC");
     $dateTimeUTC = new DateTime("now", $dateTimeZoneUTC);
     $timeOffsetSeconds = -1 * $dateTimeZoneServer->getOffset($dateTimeUTC);
     // Create job data
     $jobData = new kLiveReportExportJobData();
     $jobData->entryIds = $params->entryIds;
     $jobData->recipientEmail = $params->recpientEmail;
     $jobData->timeZoneOffset = $timeOffsetSeconds - $params->timeZoneOffset * 60;
     // Convert minutes to seconds
     $jobData->timeReference = time();
     $jobData->applicationUrlTemplate = $params->applicationUrlTemplate;
     $job = new BatchJob();
     $job->setPartnerId(kCurrentContext::getCurrentPartnerId());
     $job->setJobType(BatchJobType::LIVE_REPORT_EXPORT);
     $job->setJobSubType($reportType);
     $job->setData($jobData);
     return self::addJob($job, $jobData, BatchJobType::LIVE_REPORT_EXPORT, $reportType);
 }
Beispiel #4
0
 /**
  * @param BatchJob $batchJob
  * @param $data
  * @param int $type
  * @param int $subType
  * @return BatchJob
  */
 public static function addJob(BatchJob $batchJob, $data, $type, $subType = null)
 {
     $batchJob->setJobType($type);
     $batchJob->setJobSubType($subType);
     $batchJob->setData($data);
     if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) {
         $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId());
         // some jobs could be on deleted entry
         $batchJob->setRootJobId($entry->getBulkUploadId());
         $batchJob->setBulkJobId($entry->getBulkUploadId());
     }
     // validate partner id
     $partnerId = $batchJob->getPartnerId();
     //		if(!$partnerId)
     //			throw new APIException(APIErrors::PARTNER_NOT_SET);
     // validate that partner exists
     $partner = PartnerPeer::retrieveByPK($partnerId);
     if (!$partner) {
         KalturaLog::err("Invalid partner id [{$partnerId}]");
         throw new APIException(APIErrors::INVALID_PARTNER_ID, $partnerId);
     }
     // set the priority and work group
     $batchJob->setPriority($partner->getPriority($batchJob->getBulkJobId()));
     $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
     // look for identical jobs
     $twinJobs = BatchJobPeer::retrieveDuplicated($type, $data);
     $twinJob = null;
     if (count($twinJobs)) {
         foreach ($twinJobs as $currentTwinJob) {
             if ($currentTwinJob->getId() != $batchJob->getId()) {
                 $twinJob = reset($twinJobs);
             }
         }
     }
     if (!is_null($twinJob)) {
         $batchJob->setTwinJobId($twinJob->getId());
         if (!kConf::get("batch_ignore_duplication")) {
             $batchJob = self::updateBatchJob($batchJob, $twinJob->getStatus(), $twinJob);
         } else {
             $batchJob->save();
         }
     }
     return $batchJob;
 }