/** * @param BatchJob $batchJob * @param $data * @param int $type * @param int $subType * @return BatchJob */ public static function addJob(BatchJob $batchJob, kJobData $data, $type, $subType = null) { $batchJob->setJobType($type); $batchJob->setJobSubType($subType); $batchJob->setData($data); if (!$batchJob->getParentJobId() && $batchJob->getEntryId()) { $currentJob = kBatchManager::getCurrentUpdatingJob(); if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) { $batchJob->setParentJobId($currentJob->getId()); $batchJob->setBulkJobId($currentJob->getBulkJobId()); $batchJob->setRootJobId($currentJob->getRootJobId()); } else { $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId()); // some jobs could be on deleted entry if ($entry) { $batchJob->setRootJobId($entry->getBulkUploadId()); $batchJob->setBulkJobId($entry->getBulkUploadId()); } } } $lockInfo = new kLockInfoData($batchJob); $lockInfo->setEstimatedEffort($data->calculateEstimatedEffort($batchJob)); $lockInfo->setPriority($data->calculatePriority($batchJob)); $lockInfo->setUrgency($data->calculateUrgency($batchJob)); $batchJob->setLockInfo($lockInfo); if (is_null($batchJob->getStatus())) { $batchJob = self::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING); } else { $batchJob = self::updateBatchJob($batchJob, $batchJob->getStatus()); } return $batchJob; }
/** * @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()) { $currentJob = kBatchManager::getCurrentUpdatingJob(); if ($currentJob && $currentJob->getEntryId() == $batchJob->getEntryId()) { $batchJob->setParentJobId($currentJob->getId()); $batchJob->setBulkJobId($currentJob->getBulkJobId()); $batchJob->setRootJobId($currentJob->getRootJobId()); } else { $entry = entryPeer::retrieveByPKNoFilter($batchJob->getEntryId()); // some jobs could be on deleted entry if ($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; }