Skip to content

Commit

Permalink
Tiding up
Browse files Browse the repository at this point in the history
  • Loading branch information
ZurPHP committed Mar 19, 2018
1 parent 9fae8da commit d2e7068
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
33 changes: 7 additions & 26 deletions plugins/scheduled_task/batch/ScheduledTaskBatchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,14 @@ public static function getEntriesIdWithSameCreateAtTime($entries, $createAtTime)
return $result;
}

/**
* @param KalturaMediaType $mediaType
* @return string
*/
public static function getMediaTypeString($mediaType)
{
switch ($mediaType)
{
case 1:
return "video";
break;
case 2:
return "image";
break;
case 5:
return "audio";
break;
case 201:
return "live steam flash";
break;
case 202:
return "live steam windows media";
break;
case 203:
return "live steam real media";
break;
case 204:
return "live steam quicktime";
break;
default:
return "unkown";
}
$relectionClass = new ReflectionClass ('KalturaMediaType');
$mapping = $relectionClass->getConstants();
return array_search($mediaType, $mapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ class KScheduledTaskDryRunner extends KJobHandlerWorker
*/
private $filter;

/**
* @var kalturaClient
*/
private $client;

/**
* @var scheduledTaskProfile
*/
private $scheduledTaskProfile;

/* (non-PHPdoc)
* @see KBatchBase::getType()
*/
Expand All @@ -59,7 +69,7 @@ private function initClient($jobData, $partnerId)
$ks = $this->createKs($client, $jobData);
$client->setKs($ks);
$this->impersonate($partnerId);
return $client;
$this->client = $client;
}

private function initRunFiles()
Expand Down Expand Up @@ -109,20 +119,22 @@ private function initRunData(KalturaBatchJob $job, KalturaScheduledTaskJobData $
$this->initRunFiles();
$profileId = $job->jobObjectId;
$this->maxResults = ($jobData->maxResults) ? $jobData->maxResults : 500;
$scheduledTaskProfile = $this->getScheduledTaskProfile($profileId);
$this->initClient($jobData,$scheduledTaskProfile->partnerId);
$this->scheduledTaskProfile = $this->getScheduledTaskProfile($profileId);
$this->initClient($jobData, $this->scheduledTaskProfile->partnerId);
$this->pager = new KalturaFilterPager();
$this->pager->pageSize = 500;
$this->pager->pageIndex = 1;
$this->filter = $scheduledTaskProfile->objectFilter;
$this->filter = $this->scheduledTaskProfile->objectFilter;
}

private function execDryRunInCSVMode($results, KalturaScheduledTaskJobData $jobData)
{
$jobData->fileFormat = KalturaDryRunFileType::CSV;
$resultsCount = 0;
while(true)
try
{
try
fputcsv($this->handle, $this->getCsvHeaders());
while (true)
{
$objects = $results->objects;
$count = count($objects);
Expand All @@ -135,25 +147,25 @@ private function execDryRunInCSVMode($results, KalturaScheduledTaskJobData $jobD
$csvEntryData = $this->getCsvData($entry);
fputcsv($this->handle, $csvEntryData, ",");
}
}
catch(Exception $ex)
{
$this->unimpersonate();
throw $ex;
}

if ($resultsCount >= $this->maxResults || $resultsCount < 500)
break;
if ($resultsCount >= $this->maxResults || $resultsCount < 500)
break;

$this->updateFitler($results->objects);
$results = ScheduledTaskBatchHelper::query($this->client, $this->scheduledTaskProfile, $this->pager, $this->filter);
$this->updateFitler($results->objects);
$results = ScheduledTaskBatchHelper::query($this->client, $this->scheduledTaskProfile, $this->pager, $this->filter);
}
}
catch(Exception $ex)
{
$this->unimpersonate();
throw $ex;
}

$jobData->totalCount = $resultsCount;
}

/**
* @param KalturaBaseEntry $entry
* @param KalturaMediaEntry $entry
* @return array
*/
private function getCsvData($entry)
Expand All @@ -163,8 +175,17 @@ private function getCsvData($entry)
return array($entry->id, $entry->name, $date, $mediaType);
}

/**
* @return array
*/
private function getCsvHeaders()
{
return array("id", "name", "last played at", "media type");
}

private function execDryRunInListResponseMode($results, KalturaScheduledTaskJobData $jobData)
{
$jobData->fileFormat = KalturaDryRunFileType::LIST_RESPONSE;
$resultsCount =0;
$response = new KalturaObjectListResponse();
$response->objects = array();
Expand All @@ -175,11 +196,11 @@ private function execDryRunInListResponseMode($results, KalturaScheduledTaskJobD
if (!$count)
break;

$response->objects = array_merge($response->objects, $results->objects);
$resultsCount += $count;
if ($resultsCount >= $this->maxResults || $resultsCount < 500)
break;

$response->objects = array_merge($response->objects, $results->objects);
$this->updateFitler($results->objects);
$results = ScheduledTaskBatchHelper::query($this->client, $this->scheduledTaskProfile, $this->pager, $this->filter);
}
Expand All @@ -200,10 +221,10 @@ private function execDryRunInListResponseMode($results, KalturaScheduledTaskJobD
private function execDryRun(KalturaBatchJob $job, KalturaScheduledTaskJobData $jobData)
{
$this->initRunData($job, $jobData);
$results = ScheduledTaskHelper::query($this->client, $this->scheduledTaskProfile, $this->pager, $this->filter);
if($results->totalCount > ScheduledTaskHelper::MAX_RESULTS_THRESHOLD)
$results = ScheduledTaskBatchHelper::query($this->client, $this->scheduledTaskProfile, $this->pager, $this->filter);
if($results->totalCount > ScheduledTaskBatchHelper::MAX_RESULTS_THRESHOLD)
{
$this->execDryRunInCSVMode($results);
$this->execDryRunInCSVMode($results, $jobData);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class KalturaScheduledTaskErrors extends KalturaErrors

const DRY_RUN_FAILED = "DRY_RUN_FAILED;;Dry run execution has failed";

const DRY_RUN_RESULT_IS_TOO_BIG = "DRY_RUN_RESULT_IS_TOO_BIG;;Dry run result is too big, use the following link:";
const DRY_RUN_RESULT_IS_TOO_BIG = "DRY_RUN_RESULT_IS_TOO_BIG;;Dry run result is too big, use the following link: ";
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,11 @@ public function serveDryRunResultsAction($requestId)
*/
private function getDryRunResultUrl($requestId)
{
$finalPath ='/api_v3/service/scheduledTaskProfileService/action/serveDryRunResults/requestId';

$finalPath ='/api_v3/service/scheduledtask_scheduledtaskprofile/action/serveDryRunResults/requestId/';
$finalPath .="$requestId";
$ksObj = $this->getKs();
$ksStr = ($ksObj) ? $ksObj->getOriginalString() : null;
$finalPath .= "/ks/".$ksStr;

$partnerId = $this->getPartnerId();
$downloadUrl = myPartnerUtils::getCdnHost($partnerId) . $finalPath;

Expand Down

0 comments on commit d2e7068

Please sign in to comment.