public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $limit = $this->getP("page_size", 20);
     $limit = min($limit, 100);
     $page = $this->getP("page", 1);
     $offset = ($page - 1) * $limit;
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::PARTNER_ID, $partner_id);
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $c->addDescendingOrderByColumn(BatchJobPeer::ID);
     $count = BatchJobPeer::doCount($c);
     $c->setLimit($limit);
     $c->setOffset($offset);
     $jobs = BatchJobPeer::doSelect($c);
     $obj = array();
     foreach ($jobs as $job) {
         $jobData = $job->getData();
         if (!$jobData instanceof kBulkUploadJobData) {
             continue;
         }
         $bulkResults = BulkUploadResultPeer::retrieveWithEntryByBulkUploadId($job->getId());
         $obj[] = array("uploadedBy" => $jobData->getUploadedBy(), "uploadedOn" => $job->getCreatedAt(null), "numOfEntries" => count($bulkResults), "status" => $job->getStatus(), "error" => $job->getStatus() == BatchJob::BATCHJOB_STATUS_FAILED ? $job->getMessage() : '', "logFileUrl" => requestUtils::getCdnHost() . "/index.php/extwidget/bulkuploadfile/id/{$job->getId()}/pid/{$job->getPartnerId()}/type/log", "csvFileUrl" => requestUtils::getCdnHost() . "/index.php/extwidget/bulkuploadfile/id/{$job->getId()}/pid/{$job->getPartnerId()}/type/csv");
     }
     $this->addMsg("count", $count);
     $this->addMsg("page_size", $limit);
     $this->addMsg("page", $page);
     $this->addMsg("bulk_uploads", $obj);
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     // TODO -  verify permissions for viewing lists
     $detailed = $this->getP("detailed", false);
     $limit = $this->getP("page_size", 10);
     $page = $this->getP("page", 1);
     //$order_by = int( $this->getP ( "order_by" , -1 ) );
     $offset = ($page - 1) * $limit;
     $c = new Criteria();
     $download_types = array(BatchJobType::FLATTEN, BatchJobType::DOWNLOAD);
     $c->add(BatchJobPeer::JOB_TYPE, $download_types, Criteria::IN);
     // filter
     $filter = new BatchJobFilter(true);
     $fields_set = $filter->fillObjectFromRequest($this->getInputParams(), "filter_", null);
     $filter->attachToCriteria($c);
     //if ($order_by != -1) kshowPeer::setOrder( $c , $order_by );
     $count = BatchJobPeer::doCount($c);
     $offset = ($page - 1) * $limit;
     $c->setLimit($limit);
     if ($offset > 0) {
         $c->setOffset($offset);
     }
     $list = BatchJobPeer::doSelect($c);
     $level = objectWrapperBase::DETAIL_LEVEL_REGULAR;
     $this->addMsg("count", $count);
     $this->addMsg("page_size", $limit);
     $this->addMsg("page", $page);
     $wrapper = objectWrapperBase::getWrapperClass($list, $level);
     $this->addMsg("downloads", $wrapper);
 }
示例#3
0
 /**
  * Return the notifications for a specific entry id and type
  * 
  * @action getClientNotification
  * @param string $entryId
  * @param KalturaNotificationType $type
  * @return KalturaClientNotification
  */
 function getClientNotificationAction($entryId, $type)
 {
     // in case of a multirequest, a mediaService.addFromUploadedFile may fail and therefore the resulting entry id will be empty
     // in such a case return immidiately without looking for the notification
     if ($entryId == '') {
         throw new KalturaAPIException(KalturaErrors::NOTIFICATION_FOR_ENTRY_NOT_FOUND, $entryId);
     }
     $notifications = BatchJobPeer::retrieveByEntryIdAndType($entryId, BatchJobType::NOTIFICATION, $type);
     // FIXME: throw error if not found
     if (count($notifications) == 0) {
         throw new KalturaAPIException(KalturaErrors::NOTIFICATION_FOR_ENTRY_NOT_FOUND, $entryId);
     }
     $notification = $notifications[0];
     $partnerId = $this->getPartnerId();
     $nofication_config_str = null;
     list($nofity, $nofication_config_str) = myPartnerUtils::shouldNotify($partnerId);
     if (!$nofity) {
         return new KalturaClientNotification();
     }
     $nofication_config = myNotificationsConfig::getInstance($nofication_config_str);
     $nofity_send_type = $nofication_config->shouldNotify($type);
     if ($nofity_send_type != myNotificationMgr::NOTIFICATION_MGR_SEND_SYNCH && $nofity_send_type != myNotificationMgr::NOTIFICATION_MGR_SEND_BOTH) {
         return new KalturaClientNotification();
     }
     $partner = PartnerPeer::retrieveByPK($partnerId);
     list($url, $signatureKey) = myNotificationMgr::getPartnerNotificationInfo($partner);
     list($params, $rawSignature) = myNotificationMgr::prepareNotificationData($url, $signatureKey, $notification, null);
     $serializedParams = http_build_query($params, "", "&");
     $result = new KalturaClientNotification();
     $result->url = $url;
     $result->data = $serializedParams;
     return $result;
 }
示例#4
0
 protected function copyModifiedColumns(BatchJobLog $batchJobLog, BatchJob $batchJob, array $modifiedColumns)
 {
     $shouldSkipInTranslation = array(BatchJobPeer::LOCK_INFO, BatchJobPeer::HISTORY, BatchJobPeer::BATCH_JOB_LOCK_ID, BatchJobPeer::EXECUTION_STATUS);
     foreach ($modifiedColumns as $modifiedColumn) {
         $fieldPosLog = -1;
         try {
             if (in_array($modifiedColumn, $shouldSkipInTranslation)) {
                 if ($modifiedColumn == BatchJobPeer::EXECUTION_STATUS) {
                     $batchJobLog->setAbort($batchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED);
                 }
                 continue;
             }
             $fieldName = BatchJobPeer::translateFieldName($modifiedColumn, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME);
             $fieldPosJob = BatchJobPeer::translateFieldName($modifiedColumn, BasePeer::TYPE_COLNAME, BasePeer::TYPE_NUM);
             $fieldPosLog = BatchJobLogPeer::translateFieldName($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM);
         } catch (PropelException $e) {
             KalturaLog::err("Could not set value for BatchJobLog field {$fieldName}, exception thrown: " . $e->getMessage());
         }
         if ($fieldPosLog != -1) {
             $batchJobLog->setByPosition($fieldPosLog, $batchJob->getByPosition($fieldPosJob));
         }
         if ($modifiedColumn == BatchJobPeer::DATA) {
             //set param_1 for the $batchJobLog
             $batchJobData = $batchJob->getData();
             /* @var $batchJobData kBulkUploadJobData */
             $batchJobLog->setParam1($batchJobData->getBulkUploadObjectType());
         }
     }
     return $batchJobLog;
 }
示例#5
0
 public function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     EmailIngestionProfilePeer::clearInstancePool();
     entryPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     flavorAssetPeer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     flavorParamsOutputPeer::clearInstancePool();
     flavorParamsPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     notificationPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     // TODO clear default filters
     // TODO call all memory cleaner plugins
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
示例#6
0
 /**
  * @action notify
  * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY
  * @param int $id integration job id
  */
 public function notifyAction($id)
 {
     $coreType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION);
     $batchJob = BatchJobPeer::retrieveByPK($id);
     $invalidJobId = false;
     $invalidKs = false;
     if (!self::validateKs($batchJob)) {
         $invalidKs = true;
         KalturaLog::err("ks not valid for notifying job [{$id}]");
     } elseif (!$batchJob) {
         $invalidJobId = true;
         KalturaLog::err("Job [{$id}] not found");
     } elseif ($batchJob->getJobType() != $coreType) {
         $invalidJobId = true;
         KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . $coreType . "]");
     } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) {
         $invalidJobId = true;
         KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]");
     } elseif ($batchJob->getPartnerId() != kCurrentContext::getCurrentPartnerId()) {
         $invalidKs = true;
         KalturaLog::err("Job [{$id}] of wrong partner [" . $batchJob->getPartnerId() . "] expected [" . kCurrentContext::getCurrentPartnerId() . "]");
     }
     if ($invalidJobId) {
         throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id);
     }
     if ($invalidKs) {
         throw new KalturaAPIException(KalturaIntegrationErrors::INTEGRATION_NOTIFY_FAILED);
     }
     kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED);
 }
 public function getLockedJobs()
 {
     $c = new Criteria();
     $c->add(BatchJobPeer::BATCH_INDEX, null, Criteria::ISNOTNULL);
     $c->add(BatchJobPeer::SCHEDULER_ID, $this->scheduler_configured_id);
     $c->add(BatchJobPeer::WORKER_ID, $this->configured_id);
     return BatchJobPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
 }
示例#8
0
 public function getFieldNameFromPeer($field_name)
 {
     if ($this->queryFromBatchJob) {
         return BatchJobPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     } else {
         return BatchJobLockPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME);
     }
 }
 public function execute()
 {
     $jobId = $this->getRequestParameter("id");
     $partnerId = $this->getRequestParameter("pid");
     $type = $this->getRequestParameter("type");
     $c = new Criteria();
     $c->addAnd(BatchJobPeer::ID, $jobId);
     $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId);
     $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::BULKUPLOAD);
     $batchJob = BatchJobPeer::doSelectOne($c);
     if (!$batchJob) {
         die("File not found");
     }
     header("Content-Type: text/plain; charset=UTF-8");
     if ($type == "log") {
         $bulkUploadResults = BulkUploadResultPeer::retrieveByBulkUploadId($jobId);
         if (!count($bulkUploadResults)) {
             $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADLOG);
             if (kFileSyncUtils::file_exists($syncKey, true)) {
                 $content = kFileSyncUtils::file_get_contents($syncKey, true);
                 echo $content;
                 die;
             }
             die("Log file is not ready");
         }
         $STDOUT = fopen('php://output', 'w');
         $data = $batchJob->getData();
         foreach ($bulkUploadResults as $bulkUploadResult) {
             $values = array($bulkUploadResult->getTitle(), $bulkUploadResult->getDescription(), $bulkUploadResult->getTags(), $bulkUploadResult->getUrl(), $bulkUploadResult->getContentType());
             if ($data instanceof kBulkUploadJobData && $data->getCsvVersion() > kBulkUploadJobData::BULK_UPLOAD_CSV_VERSION_V1) {
                 $values[] = $bulkUploadResult->getConversionProfileId();
                 $values[] = $bulkUploadResult->getAccessControlProfileId();
                 $values[] = $bulkUploadResult->getCategory();
                 $values[] = $bulkUploadResult->getScheduleStartDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getScheduleEndDate('Y-m-d\\TH:i:s');
                 $values[] = $bulkUploadResult->getThumbnailUrl();
                 $values[] = $bulkUploadResult->getPartnerData();
             }
             $values[] = $bulkUploadResult->getEntryId();
             $values[] = $bulkUploadResult->getEntryStatus();
             $values[] = $bulkUploadResult->getErrorDescription();
             fputcsv($STDOUT, $values);
         }
         fclose($STDOUT);
     } else {
         $syncKey = $batchJob->getSyncKey(BatchJob::FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOADCSV);
         if (kFileSyncUtils::file_exists($syncKey, true)) {
             $content = kFileSyncUtils::file_get_contents($syncKey, true);
             echo $content;
             die;
         } else {
             die("File not found");
         }
     }
     die;
     //  no template needed
 }
 /**
  * batch updateExclusiveFileSyncImportJob action updates a BatchJob of type FILESYNC_IMPORT that was claimed using the getExclusiveFileSyncImportJobs
  * 
  * @action updateExclusiveFileSyncImportJob
  * @param int $id The id of the job to free
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism  
  * @param KalturaBatchJob $job
  * @return KalturaBatchJob 
  */
 function updateExclusiveFileSyncImportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job)
 {
     $dbBatchJob = BatchJobPeer::retrieveByPK($id);
     // verifies that the job is of the right type
     if ($dbBatchJob->getJobType() != KalturaBatchJobType::FILESYNC_IMPORT) {
         throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job));
     }
     $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob));
     $batchJob = new KalturaBatchJob();
     // start from blank
     return $batchJob->fromObject($dbBatchJob);
 }
示例#11
0
 /**
  * Will investigate a single entry
  */
 public function execute()
 {
     $this->forceSystemAuthentication();
     $batchjob_id = @$_REQUEST["batchjob_id"];
     $entry_id = @$_REQUEST["entry_id"];
     $job = BatchJobPeer::retrieveByPK($batchjob_id);
     if ($job) {
         $job->setStatus(BatchJob::BATCHJOB_STATUS_PENDING);
         $job->save();
     }
     $this->redirect("/system/investigate?entry_id={$entry_id}");
 }
示例#12
0
 /**
  * batch updateExclusiveVirusScanJob action updates a BatchJob of type VIRUS_SCAN that was claimed using the getExclusiveVirusScanJobs
  * 
  * @action updateExclusiveVirusScanJob
  * @param int $id The id of the job to free
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism  
  * @param KalturaBatchJob $job
  * @return KalturaBatchJob 
  */
 function updateExclusiveVirusScanJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job)
 {
     $dbBatchJob = BatchJobPeer::retrieveByPK($id);
     // verifies that the job is of the right type
     $jobType = VirusScanPlugin::getBatchJobTypeCoreValue(VirusScanBatchJobType::VIRUS_SCAN);
     if ($dbBatchJob->getJobType() != $jobType) {
         throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job));
     }
     $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob));
     $batchJob = new KalturaBatchJob();
     // start from blank
     return $batchJob->fromObject($dbBatchJob);
 }
示例#13
0
 /**
  * 
  * @param int $objectType
  * @param string $objectId
  * @return ISyncableFile
  */
 public static function retrieveObject($objectType, $objectId)
 {
     $object = null;
     switch ($objectType) {
         case FileSyncObjectType::ENTRY:
             entryPeer::setUseCriteriaFilter(false);
             $object = entryPeer::retrieveByPK($objectId);
             entryPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::UICONF:
             uiConfPeer::setUseCriteriaFilter(false);
             $object = uiConfPeer::retrieveByPK($objectId);
             uiConfPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::BATCHJOB:
             BatchJobPeer::setUseCriteriaFilter(false);
             $object = BatchJobPeer::retrieveByPK($objectId);
             BatchJobPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::FLAVOR_ASSET:
             assetPeer::setUseCriteriaFilter(false);
             $object = assetPeer::retrieveById($objectId);
             assetPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::SYNDICATION_FEED:
             syndicationFeedPeer::setUseCriteriaFilter(false);
             $object = syndicationFeedPeer::retrieveByPK($objectId);
             syndicationFeedPeer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::CONVERSION_PROFILE:
             conversionProfile2Peer::setUseCriteriaFilter(false);
             $object = conversionProfile2Peer::retrieveByPK($objectId);
             conversionProfile2Peer::setUseCriteriaFilter(true);
             break;
         case FileSyncObjectType::FILE_ASSET:
             conversionProfile2Peer::setUseCriteriaFilter(false);
             $object = FileAssetPeer::retrieveByPK($objectId);
             conversionProfile2Peer::setUseCriteriaFilter(true);
             break;
     }
     if ($object == null) {
         $object = KalturaPluginManager::loadObject('ISyncableFile', $objectType, array('objectId' => $objectId));
     }
     if ($object == null) {
         $error = __METHOD__ . " Cannot find object type [" . $objectType . "] with object_id [" . $objectId . "]";
         KalturaLog::err($error);
         throw new kFileSyncException($error);
     }
     return $object;
 }
 /**
  * @param boolean  $bypassSerialization enables PS2 support
  */
 public function setData($v, $bypassSerialization = false)
 {
     if ($bypassSerialization) {
         return parent::setData($v);
     }
     $this->setDuplicationKey(BatchJobPeer::createDuplicationKey($this->getJobType(), $v));
     if (!is_null($v)) {
         $sereializedValue = serialize($v);
         if (strlen((string) $sereializedValue) > BatchJob::MAX_SERIALIZED_JOB_DATA_SIZE) {
             $v = new kJobCompressedData($sereializedValue);
             $sereializedValue = serialize($v);
         }
         parent::setData($sereializedValue);
     } else {
         parent::setData(null);
     }
 }
 public function getEntryId(FileSync $fileSync)
 {
     if ($fileSync->getObjectType() == FileSyncObjectType::ENTRY) {
         return $fileSync->getObjectId();
     }
     if ($fileSync->getObjectType() == FileSyncObjectType::BATCHJOB) {
         $job = BatchJobPeer::retrieveByPK($fileSync->getObjectId());
         if ($job) {
             return $job->getEntryId();
         }
     }
     if ($fileSync->getObjectType() == FileSyncObjectType::FLAVOR_ASSET) {
         $flavor = flavorAssetPeer::retrieveById($fileSync->getObjectId());
         if ($flavor) {
             return $flavor->getEntryId();
         }
     }
     return null;
 }
 protected function copyModifiedColumns(BatchJobLog $batchJobLog, BatchJob $batchJob, array $modifiedColumns)
 {
     foreach ($modifiedColumns as $modifiedColumn) {
         try {
             $fieldName = BatchJobPeer::translateFieldName($modifiedColumn, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME);
             $fieldPosJob = BatchJobPeer::translateFieldName($modifiedColumn, BasePeer::TYPE_COLNAME, BasePeer::TYPE_NUM);
             $fieldPosLog = BatchJobLogPeer::translateFieldName($fieldName, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM);
         } catch (PropelException $e) {
             KalturaLog::err("Could not set value for BatchJobLog field {$fieldName}, exception thrown: " . $e->getMessage());
         }
         $batchJobLog->setByPosition($fieldPosLog, $batchJob->getByPosition($fieldPosJob));
         if ($modifiedColumn == BatchJobPeer::DATA) {
             //set param_1 for the $batchJobLog
             $batchJobData = $batchJob->getData();
             /* @var $batchJobData kBulkUploadJobData */
             $batchJobLog->setParam1($batchJobData->getBulkUploadObjectType());
         }
     }
     return $batchJobLog;
 }
示例#17
0
 /**
  * @action notify
  * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY
  * @param int $id integration job id
  */
 public function notifyAction($id)
 {
     $coreType = IntegrationPlugin::getBatchJobTypeCoreValue(IntegrationBatchJobType::INTEGRATION);
     $batchJob = BatchJobPeer::retrieveByPK($id);
     $invalid = false;
     if (!$batchJob) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] not found");
     } elseif ($batchJob->getJobType() != $coreType) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . $coreType . "]");
     } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]");
     }
     if ($invalid) {
         throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id);
     }
     kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED);
 }
示例#18
0
 /**
  * @action notify
  * @disableTags TAG_WIDGET_SESSION,TAG_ENTITLEMENT_ENTRY,TAG_ENTITLEMENT_CATEGORY
  * @param int $id distribution job id
  */
 public function notifyAction($id)
 {
     $submitCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_SUBMIT);
     $updateCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_UPDATE);
     $deleteCoreType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_DELETE);
     $validJobTypes = array($submitCoreType, $updateCoreType, $deleteCoreType);
     $batchJob = BatchJobPeer::retrieveByPK($id);
     $invalid = false;
     if (!$batchJob) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] not found");
     } elseif (!in_array($batchJob->getJobType(), $validJobTypes)) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] wrong type [" . $batchJob->getJobType() . "] expected [" . implode(', ', $validJobTypes) . "]");
     } elseif ($batchJob->getJobSubType() != UnicornDistributionProvider::get()->getType()) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] wrong sub-type [" . $batchJob->getJobSubType() . "] expected [" . UnicornDistributionProvider::get()->getType() . "]");
     } elseif ($batchJob->getStatus() != KalturaBatchJobStatus::ALMOST_DONE) {
         $invalid = true;
         KalturaLog::err("Job [{$id}] wrong status [" . $batchJob->getStatus() . "] expected [" . KalturaBatchJobStatus::ALMOST_DONE . "]");
     }
     if ($invalid) {
         throw new KalturaAPIException(KalturaErrors::INVALID_BATCHJOB_ID, $id);
     }
     kJobsManager::updateBatchJob($batchJob, KalturaBatchJobStatus::FINISHED);
     $data = $batchJob->getData();
     /* @var $data kDistributionJobData */
     $providerData = $data->getProviderData();
     /* @var $providerData kUnicornDistributionJobProviderData */
     $entryDistribution = EntryDistributionPeer::retrieveByPK($data->getEntryDistributionId());
     if ($entryDistribution) {
         $entryDistribution->putInCustomData(kUnicornDistributionJobProviderData::CUSTOM_DATA_FLAVOR_ASSET_OLD_VERSION, $providerData->getFlavorAssetVersion());
         $entryDistribution->save();
     }
     if ($batchJob->getJobType() == $submitCoreType) {
         $this->attachRemoteAssetResource($batchJob->getEntry(), $batchJob->getData());
     }
     if ($batchJob->getJobType() == $deleteCoreType) {
         $this->detachRemoteAssetResource($batchJob->getEntry(), $batchJob->getData());
     }
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $job_type = $this->getPM("job_type");
     $processor_name = $this->getPM("processor_name");
     $processor_timeout = $this->getPM("processor_timeout");
     $over_quota_partners = $this->getPM("over_quota_partners");
     $defered_partners = $this->getPM("defered_partners");
     $con = Propel::getConnection();
     // fetch one pending row of a given job_type
     // where the over_quota_partner requests are dropped
     // and defered_partners request are of less priority
     $query = "SELECT " . BatchJobPeer::ID . " FROM " . BatchJobPeer::TABLE_NAME . " WHERE " . BatchJobPeer::STATUS . "=" . BatchJob::BATCHJOB_STATUS_PENDING . " AND " . BatchJobPeer::JOB_TYPE . "=" . $job_type . " " . (count($over_quota_partners) ? " AND " . BatchJobPeer::PARTNER_ID . " NOT IN ({$over_quota_partners}) " : "") . " ORDER BY " . (count($defered_partners) ? BatchJobPeer::PARTNER_ID . " IN ({$defered_partners}), " : "") . BatchJobPeer::CREATED_AT . " LIMIT 1";
     $statement = $con->prepareStatement($query);
     $resultset = $statement->executeQuery();
     $batch_job = null;
     while ($resultset->next()) {
         $batch_job = BatchJobPeer::retrieveByPK($resultset->getInt('ID'));
     }
     $batch_job = BatchJobPeer::doSelectOne($c);
     if ($batch_job) {
         // force update to work on the currently selected row and ensure it is still in pending status
         $c->add(BatchJobPeer::ID, $batch_job->getId());
         $c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_PENDING);
         $update = new Criteria();
         $update->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_QUEUED);
         $update->add(BatchJobPeer::PROCESSOR_NAME, $processor_name);
         $update->add(BatchJobPeer::PROCESSOR_EXPIRATION, time() + $processor_timeout);
         $affectedRows = BasePeer::doUpdate($c, $update, $con);
         if ($affectedRows != 1) {
             $batch_job = null;
         }
     }
     if (!$batch_job) {
         //xx$this->addError ( APIErrors::INVALID_ENTRY_ID, $this->getObjectPrefix() , $entry_id );
     } else {
         $wrapper = objectWrapperBase::getWrapperClass($batch_job, objectWrapperBase::DETAIL_LEVEL_REGULAR);
         // TODO - remove this code when cache works properly when saving objects (in their save method)
         $wrapper->removeFromCache("batch_job", $batch_job->getId());
         $this->addMsg("batchjob", $wrapper);
     }
 }
示例#20
0
 /**
  * Will list out all kind of perspectives of entries
  */
 public function execute()
 {
     $this->forceSystemAuthentication();
     $conversion_count = $this->getRequestParameter("conv_count", 10);
     if ($conversion_count > 40) {
         $conversion_count = 40;
     }
     $c = new Criteria();
     $c->addDescendingOrderByColumn(conversionPeer::ID);
     $c->setLimit($conversion_count);
     $this->conversions = conversionPeer::doSelect($c);
     $this->conversion_count = $conversion_count;
     /*		
     	$conv = new conversion();
     	$conv->setId(6);
     	$conv->setinFileName ( "Dasd");
     	$conv->setStatus ( 1 );
     	$conv->setCreatedAt ( 1234545 );
     	$convs = array ( $conv );
     	$this->conversions = $convs;
     */
     $import_count = $this->getRequestParameter("impo_count", 10);
     if ($import_count > 40) {
         $import_count = 40;
     }
     $c = new Criteria();
     $c->addDescendingOrderByColumn(BatchJobPeer::ID);
     $c->setLimit($import_count);
     $this->imports = BatchJobPeer::doSelect($c);
     $this->import_count = $import_count;
     /*	
     $batch= new BatchJob();
     $batch->setId ( 4 );
     $batch->setData ( 'a:3:{s:7:"entryId";i:11077;s:9:"sourceUrl";s:84:"http://youtube.com/get_video?video_id=KDko2MFvY-s&t=OEgsToPDskKuVircfOJDjTh4FENGwQ0g";s:8:"destFile";s:36:"/web//content/imports/data/11077.flv";}' );
     $imports = array( $batch );
     
     $this->imports = $imports;
     */
 }
示例#21
0
 public static function shouldCreateLockObject(BatchJob $batchJob, $isNew, PropelPDO $con = null)
 {
     if ($isNew) {
         if (in_array($batchJob->getStatus(), self::getSchedulingRequiredStatusList())) {
             return true;
         }
         return false;
     }
     $oldStatus = $batchJob->getColumnsOldValue(BatchJobPeer::STATUS);
     $oldValueInClosed = is_null($oldStatus) ? false : in_array($oldStatus, BatchJobPeer::getClosedStatusList());
     $newValue = $batchJob->getStatus();
     $newValueInOpen = in_array($newValue, BatchJobPeer::getUnClosedStatusList());
     // if the object is not a new object, a batch_job_lock object should exist.
     // an exception is when we move from a closed state to a open open.
     // f.i. retry request of an entry that was in closed status and we now restarted it.
     if (!($oldValueInClosed && $newValueInOpen)) {
         return false;
     }
     $lockEntry = BatchJobLockPeer::retrieveByPK($batchJob->getId());
     if ($lockEntry === null) {
         return true;
     }
     return false;
 }
 public function executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser)
 {
     $prefix = $this->getObjectPrefix();
     $batchjob_id = $this->getPM("{$prefix}_id");
     $batchjob = BatchJobPeer::retrieveByPK($batchjob_id);
     if (!$batchjob) {
         $this->addError(APIErrors::INVALID_BATCHJOB_ID, $batchjob_id);
         return;
     }
     // get the new properties for the batchjob from the request
     $batchjob_update_data = new BatchJob();
     $obj_wrapper = objectWrapperBase::getWrapperClass($batchjob_update_data, 0);
     $fields_modified = baseObjectUtils::fillObjectFromMap($this->getInputParams(), $batchjob_update_data, "{$prefix}_", $obj_wrapper->getUpdateableFields());
     if (count($fields_modified) > 0) {
         if ($batchjob_update_data) {
             baseObjectUtils::fillObjectFromObject($obj_wrapper->getUpdateableFields(), $batchjob_update_data, $batchjob, baseObjectUtils::CLONE_POLICY_PREFER_NEW, null, BasePeer::TYPE_PHPNAME);
         }
         $batchjob->save();
     }
     $wrapper = objectWrapperBase::getWrapperClass($batchjob, objectWrapperBase::DETAIL_LEVEL_REGULAR);
     $wrapper->removeFromCache("batchjob", $batchjob->getId());
     $this->addMsg("{$prefix}", $wrapper);
     $this->addDebug("modified_fields", $fields_modified);
 }
示例#23
0
文件: entry.php 项目: AdiTal/server
 public function getBatchJobs()
 {
     return BatchJobPeer::retrieveByEntryId($this->getId());
 }
 /**
  * batch updateExclusiveDistributionFetchReportJob action updates a BatchJob of type DISTRIBUTION_FETCH_REPORT that was claimed using the getExclusiveDistributionFetchReportJobs
  * 
  * @action updateExclusiveDistributionFetchReportJob
  * @param int $id The id of the job to free
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism  
  * @param KalturaBatchJob $job
  * @return KalturaBatchJob 
  */
 function updateExclusiveDistributionFetchReportJobAction($id, KalturaExclusiveLockKey $lockKey, KalturaBatchJob $job)
 {
     $dbBatchJob = BatchJobPeer::retrieveByPK($id);
     // verifies that the job is of the right type
     $jobType = ContentDistributionPlugin::getBatchJobTypeCoreValue(ContentDistributionBatchJobType::DISTRIBUTION_FETCH_REPORT);
     if ($dbBatchJob->getJobType() != $jobType) {
         throw new KalturaAPIException(APIErrors::UPDATE_EXCLUSIVE_JOB_WRONG_TYPE, $id, serialize($lockKey), serialize($job));
     }
     $dbBatchJob = kBatchManager::updateExclusiveBatchJob($id, $lockKey->toObject(), $job->toObject($dbBatchJob));
     $batchJob = new KalturaBatchJob();
     // start from blank
     return $batchJob->fromObject($dbBatchJob);
 }
示例#25
0
 function calculateUrgency(BatchJob $batchJob)
 {
     $flavorParamsId = $this->getFlavorParamsOutput()->getFlavorParamsId();
     $isBulkupload = $batchJob->getBulkJobId() !== null;
     $readiness = null;
     if ($this->priority == 0) {
         self::calculatePriority($batchJob);
     }
     if ($this->priority == self::MIGRATION_FLAVOR_PRIORITY) {
         return BatchJobUrgencyType::MIGRATION_URGENCY;
     }
     // If you have no conversion profile, there is no poinr in this calculation
     if (is_null($this->conversionProfileId)) {
         return BatchJobUrgencyType::DEFAULT_URGENCY;
     }
     if ($batchJob->getObjectId() && $batchJob->getObjectType()) {
         $batchJobs = BatchJobPeer::retrieveByJobTypeAndObject($batchJob->getObjectId(), $batchJob->getObjectType(), $batchJob->getJobType(), $batchJob->getJobSubType());
         if (count($batchJobs)) {
             return $batchJobs[0]->getLockInfo()->getUrgency() + 1;
         }
     }
     // a conversion job will be considered as required in one of the following cases:
     // 1. The flavor is required
     // 2. There are no required flavors and this is the flavor is optional with the minimal bitrate
     // 3. all flavors are set as READY_BEHAVIOR_NO_IMPACT.
     $allFlavorParamsIds = array();
     $hasRequired = false;
     $allNoImpact = true;
     // Go over all flavors and decide on cases 1-3
     $fpcps = flavorParamsConversionProfilePeer::retrieveByConversionProfile($this->conversionProfileId);
     foreach ($fpcps as $fpcp) {
         $allFlavorParamsIds[] = $fpcp->getFlavorParamsId();
         if ($fpcp->getFlavorParamsId() == $flavorParamsId) {
             // Case 1
             $readiness = $fpcp->getReadyBehavior();
         }
         if ($fpcp->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
             // Case 2
             $hasRequired = true;
         }
         if ($fpcp->getReadyBehavior() != flavorParamsConversionProfile::READY_BEHAVIOR_NO_IMPACT) {
             // Case 3
             $allNoImpact = false;
         }
     }
     // Case 2
     if (!$hasRequired && $readiness == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL) {
         $flvParamsMinBitrate = assetParamsPeer::retrieveMinimalBitrate($allFlavorParamsIds);
         if (!is_null($flvParamsMinBitrate) && $flvParamsMinBitrate->getId() == $flavorParamsId) {
             $readiness = flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED;
         }
     }
     // Case 3
     if ($allNoImpact) {
         $readiness = flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED;
     }
     // Decide on the urgency by the readiness and the upload method
     if ($readiness == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
         return $isBulkupload ? BatchJobUrgencyType::REQUIRED_BULK_UPLOAD : BatchJobUrgencyType::REQUIRED_REGULAR_UPLOAD;
     } else {
         if ($readiness == flavorParamsConversionProfile::READY_BEHAVIOR_OPTIONAL) {
             return $isBulkupload ? BatchJobUrgencyType::OPTIONAL_BULK_UPLOAD : BatchJobUrgencyType::OPTIONAL_REGULAR_UPLOAD;
         } else {
             return BatchJobUrgencyType::DEFAULT_URGENCY;
         }
     }
 }
示例#26
0
 /**
  * batch getFullStatus action returns the status of all schedulers and queues
  * 
  * @action getFullStatus
  * @return KalturaFullStatusResponse
  */
 function getFullStatusAction()
 {
     $response = new KalturaFullStatusResponse();
     // gets queues length
     //		$c = new Criteria();
     //		$c->add(BatchJobPeer::STATUS, array(KalturaBatchJobStatus::PENDING, KalturaBatchJobStatus::RETRY), Criteria::IN);
     //		$c->addGroupByColumn(BatchJobPeer::JOB_TYPE);
     //		$c->addSelectColumn('AVG(DATEDIFF(NOW(),' . BatchJobPeer::CREATED_AT . '))');
     $queueList = BatchJobPeer::doQueueStatus(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
     $response->queuesStatus = KalturaBatchQueuesStatusArray::fromBatchQueuesStatusArray($queueList);
     $response->schedulers = KalturaSchedulerArray::statusFromSchedulerArray(SchedulerPeer::doSelect(new Criteria(), myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2)));
     return $response;
 }
示例#27
0
 /**
  * Get the associated BatchJob object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     BatchJob The associated BatchJob object.
  * @throws     PropelException
  */
 public function getBatchJob(PropelPDO $con = null)
 {
     if ($this->aBatchJob === null && $this->batch_job_id !== null) {
         $this->aBatchJob = BatchJobPeer::retrieveByPk($this->batch_job_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aBatchJob->addBatchJobLockSuspends($this);
         		 */
     }
     return $this->aBatchJob;
 }
示例#28
0
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = BatchJobPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setJobType($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setJobSubType($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setData($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setFileSize($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setDuplicationKey($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setStatus($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setAbort($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setCheckAgainTimeout($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setProgress($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setMessage($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setDescription($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setUpdatesCount($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setCreatedAt($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setCreatedBy($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setUpdatedAt($arr[$keys[15]]);
     }
     if (array_key_exists($keys[16], $arr)) {
         $this->setUpdatedBy($arr[$keys[16]]);
     }
     if (array_key_exists($keys[17], $arr)) {
         $this->setDeletedAt($arr[$keys[17]]);
     }
     if (array_key_exists($keys[18], $arr)) {
         $this->setPriority($arr[$keys[18]]);
     }
     if (array_key_exists($keys[19], $arr)) {
         $this->setWorkGroupId($arr[$keys[19]]);
     }
     if (array_key_exists($keys[20], $arr)) {
         $this->setQueueTime($arr[$keys[20]]);
     }
     if (array_key_exists($keys[21], $arr)) {
         $this->setFinishTime($arr[$keys[21]]);
     }
     if (array_key_exists($keys[22], $arr)) {
         $this->setEntryId($arr[$keys[22]]);
     }
     if (array_key_exists($keys[23], $arr)) {
         $this->setPartnerId($arr[$keys[23]]);
     }
     if (array_key_exists($keys[24], $arr)) {
         $this->setSubpId($arr[$keys[24]]);
     }
     if (array_key_exists($keys[25], $arr)) {
         $this->setSchedulerId($arr[$keys[25]]);
     }
     if (array_key_exists($keys[26], $arr)) {
         $this->setWorkerId($arr[$keys[26]]);
     }
     if (array_key_exists($keys[27], $arr)) {
         $this->setBatchIndex($arr[$keys[27]]);
     }
     if (array_key_exists($keys[28], $arr)) {
         $this->setLastSchedulerId($arr[$keys[28]]);
     }
     if (array_key_exists($keys[29], $arr)) {
         $this->setLastWorkerId($arr[$keys[29]]);
     }
     if (array_key_exists($keys[30], $arr)) {
         $this->setLastWorkerRemote($arr[$keys[30]]);
     }
     if (array_key_exists($keys[31], $arr)) {
         $this->setProcessorExpiration($arr[$keys[31]]);
     }
     if (array_key_exists($keys[32], $arr)) {
         $this->setExecutionAttempts($arr[$keys[32]]);
     }
     if (array_key_exists($keys[33], $arr)) {
         $this->setLockVersion($arr[$keys[33]]);
     }
     if (array_key_exists($keys[34], $arr)) {
         $this->setTwinJobId($arr[$keys[34]]);
     }
     if (array_key_exists($keys[35], $arr)) {
         $this->setBulkJobId($arr[$keys[35]]);
     }
     if (array_key_exists($keys[36], $arr)) {
         $this->setRootJobId($arr[$keys[36]]);
     }
     if (array_key_exists($keys[37], $arr)) {
         $this->setParentJobId($arr[$keys[37]]);
     }
     if (array_key_exists($keys[38], $arr)) {
         $this->setDc($arr[$keys[38]]);
     }
     if (array_key_exists($keys[39], $arr)) {
         $this->setErrType($arr[$keys[39]]);
     }
     if (array_key_exists($keys[40], $arr)) {
         $this->setErrNumber($arr[$keys[40]]);
     }
     if (array_key_exists($keys[41], $arr)) {
         $this->setOnStressDivertTo($arr[$keys[41]]);
     }
 }
示例#29
0
 public function getDirectChildJobs()
 {
     $c = new Criteria();
     $c->add(BatchJobPeer::PARENT_JOB_ID, $this->id);
     return BatchJobPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2));
 }
示例#30
0
$flavorParamsArr = null;
if (!is_null($flavorParamsIds) && strlen(trim($flavorParamsIds))) {
    $flavorParamsArr = explode(',', $flavorParamsIds);
}
$moreEntries = true;
$maxConcurrentJobs = 20;
$totalExported = 0;
$lastCreatedAt = null;
$processedIds = array();
$nonFinalBatchStatuses = array(BatchJob::BATCHJOB_STATUS_PENDING, BatchJob::BATCHJOB_STATUS_QUEUED, BatchJob::BATCHJOB_STATUS_PROCESSING, BatchJob::BATCHJOB_STATUS_PROCESSED, BatchJob::BATCHJOB_STATUS_MOVEFILE);
while ($moreEntries) {
    $c = new Criteria();
    $c->addAnd(BatchJobPeer::PARTNER_ID, $partnerId);
    $c->addAnd(BatchJobPeer::JOB_TYPE, BatchJobType::STORAGE_EXPORT);
    $c->addAnd(BatchJobPeer::STATUS, $nonFinalBatchStatuses, Criteria::IN);
    $batchCount = BatchJobPeer::doCount($c, false, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL3));
    if ($batchCount >= $maxConcurrentJobs) {
        sleep(30);
        continue;
    }
    $curLimit = $maxConcurrentJobs - $batchCount;
    $currentExported = 0;
    $c = new Criteria();
    $c->add(entryPeer::PARTNER_ID, $partnerId);
    if ($lastCreatedAt) {
        $c->addAnd(entryPeer::CREATED_AT, $lastCreatedAt, Criteria::LESS_EQUAL);
    }
    $c->addDescendingOrderByColumn(entryPeer::CREATED_AT);
    $c->setLimit($curLimit);
    $entries = entryPeer::doSelect($c, myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL3));
    foreach ($entries as $entry) {