Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions alpha/apps/kaltura/lib/batch2/kJobsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2064,8 +2064,42 @@ private static function shouldBlockFileConversion($fileSync)
return $shouldBlock;
}

/**
* Check if an active entry export CSV job already exists for the partner
* @param int $partnerId
* @return bool true if active job exists, false otherwise
*/
public static function hasActiveEntryExportJob($partnerId)
{
$c = new Criteria();
$c->add(BatchJobPeer::PARTNER_ID, $partnerId);
$c->add(BatchJobPeer::JOB_TYPE, BatchJobType::EXPORT_CSV);
$c->add(BatchJobPeer::JOB_SUB_TYPE, ExportObjectType::ENTRY);
$c->add(BatchJobPeer::STATUS, BatchJobPeer::getUnClosedStatusList(), Criteria::IN);
$c->add(BatchJobPeer::DC, kDataCenterMgr::getCurrentDc());

$existingJob = BatchJobPeer::doSelectOne($c);

if ($existingJob)
{
KalturaLog::info("Active entry export job [" . $existingJob->getId() . "] already exists for partner [$partnerId]");
return true;
}

return false;
}

public static function addExportCsvJob(kExportCsvJobData $jobData, $partnerId, $exportObjectType)
{
// Check for duplicate entry export jobs only
if ($exportObjectType == ExportObjectType::ENTRY)
{
if (self::hasActiveEntryExportJob($partnerId))
{
throw new kCoreException("Entry export job already in progress", kCoreException::EXPORT_JOB_IN_PROGRESS);
}
}

$batchJob = new BatchJob();
$batchJob->setPartnerId($partnerId);
$shouldExportCsvToSharedStorage = kConf::get('should_export_csv_to_shared_storage','runtime_config', null);
Expand Down
4 changes: 3 additions & 1 deletion alpha/apps/kaltura/lib/exceptions/kCoreException.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public function getData()
const CANNOT_REMOVE_ENTRY_FROM_CATEGORY = 'CANNOT_REMOVE_ENTRY_FROM_CATEGORY';

const USER_APP_ROLE_NOT_ALLOWED_FOR_GROUP = 'USER_APP_ROLE_NOT_ALLOWED_FOR_GROUP';

const USER_ROLE_NOT_FOUND = 'USER_ROLE_NOT_FOUND';

const EXPORT_JOB_IN_PROGRESS = 'EXPORT_JOB_IN_PROGRESS';
}
7 changes: 5 additions & 2 deletions api_v3/lib/KalturaErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,9 @@ class KalturaErrors extends APIErrors
const INVALID_SHORT_LINK = "INVALID_SHORT_LINK;ID;Invalid short link [@ID@]";
const EXPIRED_SHORT_LINK = "EXPIRED_SHORT_LINK;ID;Expired short link [@ID@]";
const SHORT_LINK_UNIQUE_ID_ALREADY_EXISTS = "SHORT_LINK_UNIQUE_ID_ALREADY_EXISTS;UNIQUE_ID;Short link unique id [@UNIQUE_ID@] already exists";
const INVALID_SHORT_LINK_DOMAIN = "INVALID_SHORT_LINK_DOMAIN;ID;Domain of short link [@ID@] is not allowed";
const INVALID_LINK_PREFIX = "INVALID_LINK_PREFIX;;The provided url must be https";

/*
* Export CSV service
*/
const ENTRY_EXPORT_CSV_IN_PROGRESS = "ENTRY_EXPORT_CSV_IN_PROGRESS;;An entry export job is already in progress. Please wait for it to complete before starting a new export.";
}
13 changes: 12 additions & 1 deletion api_v3/services/ExportCsvService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,18 @@ protected function exportMappedObjectToCsv($exportObjectType, $jobData, $filter,
$jobData->setOptions($dbOptions);
}

kJobsManager::addExportCsvJob($jobData, $this->getPartnerId(), $exportObjectType);
try
{
kJobsManager::addExportCsvJob($jobData, $this->getPartnerId(), $exportObjectType);
}
catch (kCoreException $e)
{
if ($e->getCode() == kCoreException::EXPORT_JOB_IN_PROGRESS)
{
throw new KalturaAPIException(KalturaErrors::ENTRY_EXPORT_CSV_IN_PROGRESS);
}
throw $e;
}

return $kuser->getEmail();
}
Expand Down
Loading