@@ -7,6 +7,7 @@ class CortexApiDistributionEngine extends DistributionEngine implements
77 IDistributionEngineSubmit,
88 IDistributionEngineDelete
99{
10+ protected $ tempXmlPath ;
1011 const CORTEX_API_LOGIN = 'API/Authentication/v1.0/Login ' ;
1112 const CORTEX_API_SEND_METADATA = 'API/v2.2/DataTable/Documents.Video.General-Library-Video:Update ' ;
1213 const CORTEX_API_UPLOAD_NEW_MEDIA = 'API/UploadMedia/v3.0/UploadNewMedia ' ;
@@ -34,6 +35,21 @@ class CortexApiDistributionEngine extends DistributionEngine implements
3435 * @var string
3536 */
3637 private $ recordId ;
38+
39+ public function configure ()
40+ {
41+ if (KBatchBase::$ taskConfig ->params ->tempXmlPath )
42+ {
43+ $ this ->tempXmlPath = KBatchBase::$ taskConfig ->params ->tempXmlPath ;
44+ if (!kFile::isDir ($ this ->tempXmlPath ))
45+ kFile::mkdir ($ this ->tempXmlPath , 0777 , true );
46+ }
47+ else
48+ {
49+ KalturaLog::err ("params.tempXmlPath configuration not supplied " );
50+ $ this ->tempXmlPath = sys_get_temp_dir ();
51+ }
52+ }
3753 /**
3854 * @param KalturaDistributionSubmitJobData $data
3955 * @return bool
@@ -407,8 +423,45 @@ protected function uploadVideo(KalturaCortexApiDistributionJobProviderData $apiD
407423 {
408424 try
409425 {
410- $ SystemIdentifier = $ this ->mediaUpload ($ apiDistributionJobProviderData ->videoAssetFilePath );
426+ $ needDel = false ;
427+ $ videoFilePath = $ apiDistributionJobProviderData ->videoAssetFilePath ;
428+ if (!$ videoFilePath )
429+ {
430+ throw new KalturaException ('No video asset to distribute, the job will fail ' ,KalturaBatchJobAppErrors::BULK_ITEM_NOT_FOUND );
431+ }
432+
433+ if (!kFile::checkFileExists ($ videoFilePath ))
434+ {
435+ throw new KalturaDistributionException ('The file [ ' .$ videoFilePath .'] was not found (probably not synced yet), the job will retry ' );
436+ }
437+ list ($ isRemote , $ remoteUrl ) = kFile::resolveFilePath ($ videoFilePath );
438+ $ tempVideoFilePath = !$ isRemote ? null : kFile::getExternalFile ($ remoteUrl , null , basename ($ videoFilePath ));
439+
440+ if (FALSE === strstr ($ videoFilePath , ". " ))
441+ {
442+ $ videoFilePathNew = $ this ->tempXmlPath . "/ " . uniqid () . ".dme " ;
443+ if (!kFile::checkFileExists ($ videoFilePathNew ))
444+ {
445+ $ copyFrom = $ tempVideoFilePath ? $ tempVideoFilePath : $ videoFilePath ;
446+ kFile::copy ($ copyFrom ,$ videoFilePathNew );
447+ $ needDel = true ;
448+ }
449+ $ videoFilePath = $ videoFilePathNew ;
450+ }
451+ elseif ($ isRemote )
452+ {
453+ $ videoFilePath = $ tempVideoFilePath ;
454+ }
455+ $ SystemIdentifier = $ this ->mediaUpload ($ videoFilePath );
411456 KalturaLog::info ("Cortex: upload video succeeded, SystemIdentifier: $ SystemIdentifier " );
457+ if ($ needDel == true )
458+ {
459+ kFile::unlink ($ videoFilePath );
460+ }
461+ if ($ isRemote )
462+ {
463+ kFile::unlink ($ tempVideoFilePath );
464+ }
412465 $ this ->setCortexSystemId ($ SystemIdentifier );
413466 return true ;
414467 }
0 commit comments