protected function doDispatch(KalturaBatchJob $job, KalturaIntegrationJobData &$data, KalturaVoicebaseJobProviderData $providerData)
 {
     $entryId = $providerData->entryId;
     $flavorAssetId = $providerData->flavorAssetId;
     $spokenLanguage = $providerData->spokenLanguage;
     $formatsString = $providerData->captionAssetFormats;
     $formatsArray = explode(',', $formatsString);
     $shouldReplaceRemoteMedia = $providerData->replaceMediaContent;
     $fileLocation = $providerData->fileLocation;
     $callBackUrl = $data->callbackNotificationUrl;
     KalturaLog::debug('callback is - ' . $callBackUrl);
     $this->clientHelper = VoicebasePlugin::getClientHelper($providerData->apiKey, $providerData->apiPassword);
     $flavorUrl = KBatchBase::$kClient->flavorAsset->getUrl($flavorAssetId);
     $externalEntryExists = $this->clientHelper->checkExistingExternalContent($entryId);
     if (!$externalEntryExists) {
         $uploadSuccess = $this->clientHelper->uploadMedia($flavorUrl, $entryId, $callBackUrl, $spokenLanguage, $fileLocation);
         if (!$uploadSuccess) {
             throw new Exception("upload failed");
         }
     } elseif ($shouldReplaceRemoteMedia == true) {
         $this->clientHelper->deleteRemoteFile($entryId);
         $uploadSuccess = $this->clientHelper->uploadMedia($flavorUrl, $entryId, $callBackUrl, $spokenLanguage, $fileLocation);
         if (!$uploadSuccess) {
             throw new Exception("upload failed");
         }
     } elseif ($fileLocation) {
         $this->clientHelper->updateRemoteTranscript($entryId, $fileLocation, $callBackUrl);
     } else {
         return true;
     }
     return false;
 }
 public function updatedJob(BatchJob $dbBatchJob)
 {
     $data = $dbBatchJob->getData();
     $providerData = $data->getProviderData();
     $entryId = $providerData->getEntryId();
     $partnerId = $dbBatchJob->getPartnerId();
     $spokenLanguage = $providerData->getSpokenLanguage();
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_DONT_PROCESS) {
         $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true);
         if (!$transcript) {
             $transcript = new TranscriptAsset();
             $transcript->setType(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT));
             $transcript->setEntryId($entryId);
             $transcript->setPartnerId($partnerId);
             $transcript->setLanguage($spokenLanguage);
             $transcript->setContainerFormat(AttachmentType::TEXT);
             $transcript->setAccuracy(self::DEFAULT_ACCURACY);
         }
         $transcript->setStatus(AttachmentAsset::ASSET_STATUS_QUEUED);
         $transcript->save();
         return true;
     }
     $formatsString = $providerData->getCaptionAssetFormats();
     if ($dbBatchJob->getStatus() == BatchJob::BATCHJOB_STATUS_FINISHED) {
         $clientHelper = VoicebasePlugin::getClientHelper($providerData->getApiKey(), $providerData->getApiPassword());
         $externalEntryExists = $clientHelper->checkExistingExternalContent($entryId);
         if (!$externalEntryExists) {
             KalturaLog::err('remote content does not exist');
             return true;
         }
         $formatsArray = explode(',', $formatsString);
         $formatsArray[] = "TXT";
         $contentsArray = $clientHelper->getRemoteTranscripts($entryId, $formatsArray);
         KalturaLog::debug('contents are - ' . print_r($contentsArray, true));
         $transcript = $this->getAssetsByLanguage($entryId, array(TranscriptPlugin::getAssetTypeCoreValue(TranscriptAssetType::TRANSCRIPT)), $spokenLanguage, true);
         $captions = $this->getAssetsByLanguage($entryId, array(CaptionPlugin::getAssetTypeCoreValue(CaptionAssetType::CAPTION)), $spokenLanguage);
         $this->setObjectContent($transcript, $contentsArray["TXT"], null, true);
         unset($contentsArray["TXT"]);
         foreach ($contentsArray as $format => $content) {
             $captionFormatConst = constant("KalturaCaptionType::" . $format);
             if (isset($captions[$captionFormatConst])) {
                 $caption = $captions[$captionFormatConst];
             } else {
                 $caption = new CaptionAsset();
                 $caption->setEntryId($entryId);
                 $caption->setPartnerId($partnerId);
                 $caption->setLanguage($spokenLanguage);
                 $caption->setContainerFormat($captionFormatConst);
                 $caption->setAccuracy(self::DEFAULT_ACCURACY);
                 $caption->setStatus(CaptionAsset::ASSET_STATUS_QUEUED);
                 $caption->save();
             }
             $this->setObjectContent($caption, $content, $format);
         }
     }
     return true;
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $object = parent::toObject($object_to_fill, $props_to_skip);
     $entryId = $object->getEntryId();
     $entry = entryPeer::retrieveByPK($entryId);
     $partnerId = $entry->getPartnerId();
     $transcriptId = $object->getInputTranscriptId();
     $voicebaseOptionsObj = VoicebasePlugin::getPartnerVoicebaseOptions($partnerId);
     $object->setApiKey($voicebaseOptionsObj->apiKey);
     $object->setApiPassword($voicebaseOptionsObj->apiPassword);
     if (!$object->getFlavorAssetId()) {
         $sourceAsset = assetPeer::retrieveOriginalReadyByEntryId($entryId);
         if (!$sourceAsset) {
             throw new KalturaAPIException(KalturaVoicebaseErrors::NO_FLAVOR_ASSET_FOUND, $entryId);
         }
         $object->setFlavorAssetId($sourceAsset->getId());
     }
     $voicebaseParamsMap = kConf::get('voicebase', 'integration');
     if (!$object->getSpokenLanguage()) {
         $object->setSpokenLanguage($voicebaseParamsMap['default_language']);
     }
     $formatsString = $object->getCaptionAssetFormats();
     if ($formatsString) {
         $formatsArray = explode(',', $formatsString);
         $excludedFormats = $voicebaseParamsMap['exclude_formats'];
         $sanitizedFormatsArray = array();
         foreach ($formatsArray as $format) {
             $format = preg_replace("/[^A-Z_]/", "", $format);
             if (!constant("KalturaCaptionType::" . $format) || in_array($format, $excludedFormats)) {
                 throw new KalturaAPIException(KalturaVoicebaseErrors::INVALID_TYPES, $formatsString);
             }
             $sanitizedFormatsArray[] = $format;
         }
         $sanitizedFormats = implode(",", $sanitizedFormatsArray);
         $object->setCaptionAssetFormats($sanitizedFormats);
     } else {
         $defaultFormats = implode(",", $voicebaseParamsMap['default_formats']);
         $object->setCaptionAssetFormats($defaultFormats);
     }
     if ($transcriptId) {
         $transcript = assetPeer::retrieveById($transcriptId);
         $key = $transcript->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         $fileSync = FileSyncPeer::retrieveByFileSyncKey($key, true);
         $object->setFileLocation($fileSync->getFullPath());
     }
     return $object;
 }
<?php

require_once __DIR__ . '/../bootstrap.php';
if ($argc < 3) {
    die("Usage: php addVoicebaseParamsToPartner [partner id] [apiKey] [apiPassword]" . PHP_EOL);
}
$partnerId = $argv[1];
$apiKey = $argv[2];
$apiPassword = $argv[3];
$options = new VoicebaseOptions($apiKey, $apiPassword);
VoicebasePlugin::setPartnerVoicebaseOptions($partnerId, $options);
 public static function validatePermissions($partnerId)
 {
     return PermissionPeer::isAllowedPlugin(VoicebasePlugin::getPluginName(), $partnerId);
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $object = parent::toObject($object_to_fill, $props_to_skip);
     $entryId = $object->getEntryId();
     $entry = entryPeer::retrieveByPK($entryId);
     $partnerId = $entry->getPartnerId();
     $transcriptId = $object->getInputTranscriptId();
     $voicebaseOptionsObj = VoicebasePlugin::getPartnerVoicebaseOptions($partnerId);
     $object->setApiKey($voicebaseOptionsObj->apiKey);
     $object->setApiPassword($voicebaseOptionsObj->apiPassword);
     if ($transcriptId) {
         $transcript = assetPeer::retrieveById($transcriptId);
         $key = $transcript->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
         $fileSync = FileSyncPeer::retrieveByFileSyncKey($key, true);
         $object->setFileLocation($fileSync->getFullPath());
     }
     return $object;
 }