-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathKZoomDropFolderEngine.php
More file actions
604 lines (545 loc) · 22.9 KB
/
KZoomDropFolderEngine.php
File metadata and controls
604 lines (545 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<?php
/**
* @package plugins.ZoomDropFolder
*/
class KZoomDropFolderEngine extends KDropFolderFileTransferEngine
{
const DEFAULT_ZOOM_QUERY_TIMERANGE = 259200; // 3 days
const ONE_DAY = 86400;
const HOUR = 3600;
const ONE_MINUTE = 600;
const MAX_PAGE_SIZE = 300;
const MEETINGS = 'meetings';
const RECORDING_FILES = 'recording_files';
const UUID = 'uuid';
const ID = 'id';
const TOPIC = 'topic';
const START_TIME = 'start_time';
const ACCOUNT_ID = 'account_id';
const HOST_ID = 'host_id';
const TYPE = 'type';
const DOWNLOAD_URL = 'download_url';
const RECORDING_START = 'recording_start';
const FILE_SIZE = 'file_size';
const FILE_EXTENSION = 'file_extension';
const RECORDING_FILE_TYPE = 'file_type';
const RECORDING_TYPE = 'recording_type';
const NEXT_PAGE_TOKEN = 'next_page_token';
const ME = 'me';
const TRANSCRIPT = 'TRANSCRIPT';
const CC = 'CC';
const MP4 = 'MP4';
const M4A = 'M4A';
/**
* @var kZoomClient
*/
protected $zoomClient;
protected function getZoomParam($paramName, $default = 0)
{
$val = $default;
if(KBatchBase::$taskConfig->params->zoom && KBatchBase::$taskConfig->params->zoom->$paramName)
{
$val = KBatchBase::$taskConfig->params->zoom->$paramName;
}
return $val;
}
protected function isDayInThePast($startRunTime, $timestamp)
{
$today = kTimeZoneUtils::midnightTimezoneDateTime($startRunTime, 'Zulu');
$lastDayScanned = kTimeZoneUtils::midnightTimezoneDateTime($timestamp, 'Zulu');
$diff = $today->diff( $lastDayScanned );
$diffDays = (integer)$diff->format( "%R%a" ); // Extract days count in interval
return ($diffDays < 0);
}
protected function shouldAdvanceByDay($startRunTime, $fileInStatusProcessingExists)
{
/*
- "lastHandledMeetingTime" should be interpreted as "dayToScan".
- If we didn't scan today, but some day in the past, we might want to advance to the next day (might be today):
- If all files from the day in the past were handled, advance.
- Or if we're done waiting to some files to be completed.
*/
if( !$this->isDayInThePast($startRunTime, $this->dropFolder->lastHandledMeetingTime) )
{
return false;
}
$secondsFromMidnight = $startRunTime % self::ONE_DAY;
$meetingGracePeriod = $this->getZoomParam('meetingGracePeriod');
if($secondsFromMidnight <= $meetingGracePeriod)
{
KalturaLog::info("DropFolderId {$this->dropFolder->id}: A new day is here, but still waiting for new meetings to arrive");
return false;
}
if($fileInStatusProcessingExists)
{
$fileProcessingGracePeriod = $this->dropFolder->fileProcessingGracePeriod;
if($secondsFromMidnight <= $fileProcessingGracePeriod)
{
KalturaLog::info("DropFolderId {$this->dropFolder->id}: A new day is here, but found files in status Processing. Waiting for status completed");
return false;
}
KalturaLog::info("DropFolderId {$this->dropFolder->id}: ignoring files with status Processing");
}
KalturaLog::info("DropFolderId {$this->dropFolder->id}: Returning true");
return true;
}
public function watchFolder(KalturaDropFolder $dropFolder)
{
if($this->shouldDisableExpiredDropFolder($dropFolder))
{
$this->disableExpiredDropFolder($dropFolder);
}
$this->zoomClient = $this->initZoomClient($dropFolder);
$this->dropFolder = $dropFolder;
KalturaLog::info('Watching folder [' . $this->dropFolder->id . ']');
$startRunTime = time();
$meetingFiles = $this->getMeetingsFromZoom();
$fileInStatusProcessingExists = false;
if ($meetingFiles)
{
$this->handleMeetingFiles($meetingFiles, $fileInStatusProcessingExists);
}
else
{
KalturaLog::info('No files to handle at this time');
}
if($this->shouldAdvanceByDay($startRunTime, $fileInStatusProcessingExists))
{
KalturaLog::info("Advancing DropFolderId {$this->dropFolder->id} in a day");
$this->updateDropFolderLastMeetingHandled($this->dropFolder->lastHandledMeetingTime + self::ONE_DAY);
}
$this->handleExistingDropFolderFiles(self::DEFAULT_ZOOM_QUERY_TIMERANGE);
}
protected function refreshZoomClientTokens()
{
KalturaLog::debug("Going to refresh Zoom tokens");
try
{
$this->dropFolder = $this->dropFolderService->get($this->dropFolder->id);
}
catch (Exception $e)
{
KalturaLog::err("Error handling drop folder Id [" . $this->dropFolder->id . "] - could not refresh access token " . $e->getMessage());
return false;
}
$this->zoomClient = $this->initZoomClient($this->dropFolder);
return true;
}
protected function initZoomClient(KalturaDropFolder $dropFolder)
{
$accountId = isset($dropFolder->accountId) ? $dropFolder->accountId : null;
$refreshToken = isset($dropFolder->refreshToken) ? $dropFolder->refreshToken : null;
$accessToken = isset($dropFolder->accessToken) ? $dropFolder->accessToken : null;
$accessExpiresIn = isset($dropFolder->accessExpiresIn) ? $dropFolder->accessExpiresIn : null;
$zoomAuthType = isset($dropFolder->zoomAuthType) ? $dropFolder->zoomAuthType : 0;
return new kZoomClient($dropFolder->baseURL, $accountId, $refreshToken, $accessToken, $accessExpiresIn, $zoomAuthType);
}
protected function getMeetingsFromZoom()
{
$dayToScan = kTimeZoneUtils::timezoneDate('Y-m-d', $this->dropFolder->lastHandledMeetingTime, 'Zulu');
$pageSize = self::MAX_PAGE_SIZE;
$maxMeetings = $this->getZoomParam('maxMeetings', 3000);
$maxPages = ceil($maxMeetings / $pageSize);
$pageIndex = 0;
$nextPageToken = '';
$meetingFilesList = array();
do
{
$resultZoomList = $this->zoomClient->listRecordings(self::ME, $dayToScan, $nextPageToken, $pageSize);
$meetingFiles = $this->getMeetings($resultZoomList);
if (!$meetingFiles)
{
break;
}
$meetingFilesList = array_merge($meetingFilesList, $meetingFiles);
$pageIndex++;
$nextPageToken = $resultZoomList && $resultZoomList[self::NEXT_PAGE_TOKEN] ?
$resultZoomList[self::NEXT_PAGE_TOKEN] : '';
} while ($nextPageToken !== '' && $pageIndex < $maxPages);
return $meetingFilesList;
}
protected function getMeetings($resultZoomList)
{
if (!isset($resultZoomList[self::MEETINGS]) || empty($resultZoomList[self::MEETINGS]))
{
KalturaLog::info('No physical files found for drop folder id ['.$this->dropFolder->id.']');
return array();
}
$meetings = $resultZoomList[self::MEETINGS];
KalturaLog::info('Found ['.count($meetings).'] files in the folder:');
foreach ($meetings as $meeting)
{
KalturaLog::info('Meeting UUID: '. $meeting[self::UUID]);
}
return $meetings;
}
protected function handleMeetingFiles($meetingFiles, &$fileInStatusProcessingExists)
{
$groupParticipationType = $this->dropFolder->zoomVendorIntegration->groupParticipationType;
$optInGroupNames = explode("\r\n", $this->dropFolder->zoomVendorIntegration->optInGroupNames);
$optOutGroupNames = explode("\r\n", $this->dropFolder->zoomVendorIntegration->optOutGroupNames);
foreach ($meetingFiles as $meetingFile)
{
if($this->getEntryByReferenceId(zoomProcessor::ZOOM_PREFIX . $meetingFile[self::UUID]))
{
KalturaLog::debug('found entry with old reference id - continue to the next meeting');
continue;
}
if(kZoomTokens::isTokenExpired($this->zoomClient->getAccessExpiresIn()) && !$this->refreshZoomClientTokens())
{
return;
}
$partnerId = $this->dropFolder->partnerId;
$userId = ZoomBatchUtils::getUserId($this->zoomClient, $partnerId, $meetingFile, $this->dropFolder->zoomVendorIntegration);
if ($groupParticipationType != KalturaZoomGroupParticipationType::NO_CLASSIFICATION)
{
if (!$userId)
{
KalturaLog::err('Could not find user');
continue;
}
if (ZoomBatchUtils::shouldExcludeUserRecordingIngest($userId, $groupParticipationType, $optInGroupNames, $optOutGroupNames, $partnerId))
{
KalturaLog::debug('The user [' . $meetingFile[self::HOST_ID] . '] is configured to not save recordings - Not processing');
continue;
}
}
KalturaLog::debug('meeting file is: ' . print_r($meetingFile, true));
$kZoomRecording = new kZoomRecording();
$kZoomRecording->parseType($meetingFile[self::TYPE]);
if($kZoomRecording->recordingType == KalturaRecordingType::WEBINAR && !$this->dropFolder->zoomVendorIntegration->enableWebinarUploads)
{
KalturaLog::debug('webinar uploads is disabled for vendor integration id: ' . $this->dropFolder->zoomVendorIntegration->id);
continue;
}
if($kZoomRecording->recordingType == KalturaRecordingType::MEETING && !$this->dropFolder->zoomVendorIntegration->enableMeetingUpload)
{
KalturaLog::debug('meeting uploads is disabled for vendor integration id: ' . $this->dropFolder->zoomVendorIntegration->id);
continue;
}
$recordingFilesOrdered = ZoomHelper::orderRecordingFiles($meetingFile[self::RECORDING_FILES],
self::RECORDING_START,
self::RECORDING_TYPE,
$fileInStatusProcessingExists);
KalturaLog::debug('recording files ordered are: ' . print_r($recordingFilesOrdered, true));
foreach ($recordingFilesOrdered as $recordingFilesPerTimeSlot)
{
$parentEntry = null;
$this->handleAudioFiles($recordingFilesPerTimeSlot);
foreach ($recordingFilesPerTimeSlot as $recordingFile)
{
$recordingFileName = $meetingFile[self::UUID] . '_' . $recordingFile[self::ID] . ZoomHelper::SUFFIX_ZOOM;
$dropFolderFilesMap = $this->loadDropFolderFiles($recordingFileName);
if (count($dropFolderFilesMap) === 0)
{
$isTranscript = in_array($recordingFile[self::RECORDING_FILE_TYPE], array(self::TRANSCRIPT, self::CC));
if ($isTranscript && isset($this->dropFolder->zoomVendorIntegration->enableZoomTranscription) &&
!$this->dropFolder->zoomVendorIntegration->enableZoomTranscription)
{
continue;
}
if (ZoomHelper::shouldHandleFileType($recordingFile[self::RECORDING_FILE_TYPE]))
{
if (!$parentEntry)
{
$parentEntry = $this->getEntryByReferenceId(zoomProcessor::ZOOM_PREFIX . $meetingFile[self::UUID] . $recordingFile[self::RECORDING_START]);
if ($parentEntry)
{
$this->addDropFolderFile($meetingFile, $recordingFile, $parentEntry->id, false);
}
else if (!$isTranscript)
{
$parentEntry = $this->createEntry($meetingFile[self::UUID],
$this->dropFolder->zoomVendorIntegration->enableZoomTranscription, $recordingFile[self::RECORDING_START], $userId);
$this->addDropFolderFile($meetingFile, $recordingFile, $parentEntry->id, true);
}
}
else
{
$this->addDropFolderFile($meetingFile, $recordingFile, $parentEntry->id, false);
}
}
}
}
}
}
}
protected function getEntryByReferenceId($referenceId)
{
$entryFilter = new KalturaBaseEntryFilter();
$entryFilter->referenceIdEqual = $referenceId;
$entryFilter->updatedAtGreaterThanOrEqual = time() - self::DEFAULT_ZOOM_QUERY_TIMERANGE;
$entryFilter->statusNotIn = KalturaEntryStatus::DELETED . ',' . KalturaEntryStatus::ERROR_CONVERTING . ',' .
KalturaEntryStatus::ERROR_IMPORTING;
$entryPager = new KalturaFilterPager();
$entryPager->pageSize = 1;
$entryPager->pageIndex = 1;
KBatchBase::impersonate($this->dropFolder->partnerId);
$entryList = KBatchBase::$kClient->baseEntry->listAction($entryFilter, $entryPager);
KBatchBase::unimpersonate();
if (is_array($entryList->objects) && isset($entryList->objects[0]) )
{
return $entryList->objects[0];
}
return null;
}
protected function createEntry($uuid, $enableTranscriptionViaZoom, $recordingStartTime, $userId)
{
$newEntry = new KalturaMediaEntry();
$newEntry->sourceType = KalturaSourceType::URL;
$newEntry->mediaType = KalturaMediaType::VIDEO;
$newEntry->referenceId = zoomProcessor::ZOOM_PREFIX . $uuid . $recordingStartTime;
$newEntry->blockAutoTranscript = $enableTranscriptionViaZoom;
$newEntry->conversionProfileId = $this->dropFolder->conversionProfileId;
if ($userId)
{
$newEntry->userId = $userId;
}
KBatchBase::impersonate($this->dropFolder->partnerId);
$entry = KBatchBase::$kClient->baseEntry->add($newEntry);
KBatchBase::unimpersonate();
return $entry;
}
protected function updateDropFolderLastMeetingHandled($lastHandledMeetingTime)
{
$updateDropFolder = new KalturaZoomDropFolder();
$updateDropFolder->lastHandledMeetingTime = $lastHandledMeetingTime;
$this->dropFolderPlugin->dropFolder->update($this->dropFolder->id, $updateDropFolder);
KalturaLog::debug('Last handled meetings time is: '. $lastHandledMeetingTime);
}
protected function handleAudioFiles(&$recordingFilesPerTimeSlot)
{
$foundMP4 = false;
$audioKeys = array();
foreach ($recordingFilesPerTimeSlot as $key => $recordingFile)
{
if ($recordingFile[self::RECORDING_FILE_TYPE] === self::MP4)
{
$foundMP4 = true;
}
if ($recordingFile[self::RECORDING_FILE_TYPE] === self::M4A)
{
$audioKeys[] = $key;
}
}
if ($foundMP4)
{
foreach ($audioKeys as $audioKey)
{
$audioRecordingFile = $recordingFilesPerTimeSlot[$audioKey];
KalturaLog::debug('Video and Audio files were found. audio file is ' . print_r($audioRecordingFile, true) . ' , unsetting Audio');
unset($recordingFilesPerTimeSlot[$audioKey]);
}
}
}
protected function addDropFolderFile($meetingFile, $recordingFile, $parentEntryId, $isParentEntry = false)
{
try
{
$kMeetingMetaData = self::allocateMeetingMetaData($meetingFile);
$kRecordingFile = self::allocateZoomRecordingFile($recordingFile);
$zoomDropFolderFile = $this->allocateZoomDropFolderFile($meetingFile, $recordingFile, $kMeetingMetaData, $kRecordingFile, $parentEntryId,
$isParentEntry);
KalturaLog::debug("Adding new ZoomDropFolderFile: " . print_r($zoomDropFolderFile, true));
$dropFolderFile = $this->dropFolderFileService->add($zoomDropFolderFile);
return $dropFolderFile;
}
catch(Exception $e)
{
KalturaLog::err('Cannot add new drop folder file with name ['.
$meetingFile[self::UUID] . '_' . $recordingFile[self::ID] . ZoomHelper::SUFFIX_ZOOM .'] - '.$e->getMessage());
return null;
}
}
protected static function allocateMeetingMetaData($meetingFile)
{
$kMeetingMetaData = new kalturaZoomMeetingMetadata();
$kMeetingMetaData->meetingId = $meetingFile[self::ID];
$kMeetingMetaData->uuid = $meetingFile[self::UUID];
$kMeetingMetaData->topic = $meetingFile[self::TOPIC];
$kMeetingMetaData->meetingStartTime = kTimeZoneUtils::strToZuluTime($meetingFile[self::START_TIME]);
$kMeetingMetaData->accountId = $meetingFile[self::ACCOUNT_ID];
$kMeetingMetaData->hostId = $meetingFile[self::HOST_ID];
$kZoomRecording = new kZoomRecording();
$kZoomRecording->parseType($meetingFile[self::TYPE]);
$kMeetingMetaData->type = $kZoomRecording->recordingType;
return $kMeetingMetaData;
}
protected static function allocateZoomRecordingFile($recordingFile)
{
$kRecordingFile = new KalturaZoomRecordingFile();
$kRecordingFile->id = $recordingFile[self::ID];
$kRecordingFile->downloadUrl = $recordingFile[self::DOWNLOAD_URL];
$kRecordingFile->fileExtension = $recordingFile[self::FILE_EXTENSION];
$kRecordingFile->recordingStart = kTimeZoneUtils::strToZuluTime($recordingFile[self::RECORDING_START]);
$kZoomRecordingFile = new kZoomRecordingFile();
$kZoomRecordingFile->parseFileType($recordingFile[self::RECORDING_FILE_TYPE]);
$kRecordingFile->fileType = $kZoomRecordingFile->recordingFileType;
return $kRecordingFile;
}
protected function allocateZoomDropFolderFile($meetingFile, $recordingFile, $kMeetingMetaData, $kRecordingFile, $parentEntryId, $isParentEntry)
{
$zoomDropFolderFile = new KalturaZoomDropFolderFile();
$zoomDropFolderFile->dropFolderId = $this->dropFolder->id;
$zoomDropFolderFile->fileName = $meetingFile[self::UUID] . '_' . $recordingFile[self::ID] . ZoomHelper::SUFFIX_ZOOM;
$zoomDropFolderFile->fileSize = $recordingFile[self::FILE_SIZE];
$zoomDropFolderFile->meetingMetadata = $kMeetingMetaData;
$zoomDropFolderFile->recordingFile = $kRecordingFile;
$zoomDropFolderFile->parentEntryId = $parentEntryId;
$zoomDropFolderFile->isParentEntry = $isParentEntry;
return $zoomDropFolderFile;
}
protected function handleExistingDropFolderFile (KalturaDropFolderFile $dropFolderFile)
{
if(kZoomTokens::isTokenExpired($this->zoomClient->getAccessExpiresIn()) && !$this->refreshZoomClientTokens())
{
return;
}
$fileSize = $this->zoomClient->getFileSize($dropFolderFile->meetingMetadata->uuid, $dropFolderFile->recordingFile->id);
if (!$fileSize)
{
KalturaLog::info('Current file size is empty');
return;
}
if($dropFolderFile->status == KalturaDropFolderFileStatus::UPLOADING)
{
$this->handleUploadingDropFolderFile($dropFolderFile, $fileSize, 0);
}
else
{
$deleteTime = $dropFolderFile->updatedAt + $this->dropFolder->autoFileDeleteDays*86400;
if(($dropFolderFile->status == KalturaDropFolderFileStatus::HANDLED && $this->dropFolder->fileDeletePolicy != KalturaDropFolderFileDeletePolicy::MANUAL_DELETE && time() > $deleteTime) ||
$dropFolderFile->status == KalturaDropFolderFileStatus::DELETED)
{
$this->purgeFile($dropFolderFile);
}
}
}
protected function purgeFile(KalturaDropFolderFile $dropFolderFile)
{
$fullPath = $dropFolderFile->fileName;
try
{
$this->zoomClient->deleteRecordingFile($dropFolderFile->meetingMetadata->uuid, $dropFolderFile->recordingFile->id);
}
catch (Exception $e)
{
KalturaLog::err("Error when deleting drop folder file - ".$e->getMessage());
$this->handleFileError($dropFolderFile->id, KalturaDropFolderFileStatus::ERROR_DELETING, KalturaDropFolderFileErrorCode::ERROR_DELETING_FILE,
DropFolderPlugin::ERROR_DELETING_FILE_MESSAGE. '['.$fullPath.']');
}
$this->handleFilePurged($dropFolderFile->id);
if($dropFolderFile->recordingFile->fileType == KalturaRecordingFileType::VIDEO)
{
$this->purgeAudioFiles($dropFolderFile->meetingMetadata->uuid);
}
}
protected function purgeAudioFiles($meetingId)
{
try
{
$meetingRecordings = $this->zoomClient->getMeetingRecordings($meetingId);
}
catch (Exception $e)
{
KalturaLog::err("Error when listing meeting files for meeting id [$meetingId]: " . $e->getMessage());
return;
}
if (!$meetingRecordings || !isset($meetingRecordings[kZoomRecording::RECORDING_FILES]))
{
return;
}
$recordingFiles = $meetingRecordings[kZoomRecording::RECORDING_FILES];
foreach ($recordingFiles as $recordingFile)
{
if ($recordingFile[self::RECORDING_FILE_TYPE] === self::M4A)
{
KalturaLog::debug('Deleting Audio File From Zoom, file ID: ' . $recordingFile[self::ID]);
try
{
$this->zoomClient->deleteRecordingFile($meetingId, $recordingFile[self::ID]);
}
catch (Exception $e)
{
KalturaLog::err("Error when deleting audio file ID: " . $recordingFile[self::ID] . " Error: " . $e->getMessage());
}
}
}
}
public function processFolder (KalturaBatchJob $job, KalturaDropFolderContentProcessorJobData $data)
{
KBatchBase::impersonate($job->partnerId);
$dropFolderFileId = $data->dropFolderFileIds;
/* @var KalturaZoomDropFolderFile $dropFolderFile*/
$dropFolderFile = $this->dropFolderFileService->get($dropFolderFileId);
/* @var KalturaZoomDropFolder $dropFolder */
$dropFolder = $this->dropFolderPlugin->dropFolder->get($data->dropFolderId);
if(!$dropFolder->zoomVendorIntegration)
{
throw new kExternalException(KalturaDropFolderErrorCode::MISSING_CONFIG, DropFolderPlugin::MISSING_CONFIG_MESSAGE);
}
//If the token will be expired during the processing (in $expiryExtraGraceTime seconds), sleep $expiryExtraGraceTime and refresh token
$expiryExtraGraceTime = 3;
if(kZoomTokens::isTokenExpired($dropFolder->accessExpiresIn, $expiryExtraGraceTime))
{
sleep($expiryExtraGraceTime);
$dropFolder = $this->dropFolderPlugin->dropFolder->get($data->dropFolderId);
}
$zoomBaseUrl = $dropFolder->baseURL;
$entry = KBatchBase::$kClient->baseEntry->get($dropFolderFile->parentEntryId);
switch ($data->contentMatchPolicy)
{
case KalturaDropFolderContentFileHandlerMatchPolicy::ADD_AS_NEW:
$isTranscript = in_array($dropFolderFile->recordingFile->fileType, array(KalturaRecordingFileType::TRANSCRIPT, KalturaRecordingFileType::CC));
if ($isTranscript)
{
$transcriptProcessor = new zoomTranscriptProcessor($zoomBaseUrl, $dropFolder);
$transcriptProcessor->handleRecordingTranscriptComplete($dropFolderFile, $entry);
$this->updateDropFolderFile($dropFolderFile->parentEntryId , $dropFolderFile);
}
else if (in_array($dropFolderFile->recordingFile->fileType, array(KalturaRecordingFileType::VIDEO, KalturaRecordingFileType::AUDIO,
KalturaRecordingFileType::CHAT)))
{
if ($dropFolderFile->meetingMetadata->type == KalturaRecordingType::WEBINAR)
{
$zoomRecordingProcessor = new zoomWebinarProcessor($zoomBaseUrl, $dropFolder);
}
else
{
$zoomRecordingProcessor = new zoomMeetingProcessor($zoomBaseUrl, $dropFolder);
}
$zoomRecordingProcessor->mainEntry = $entry;
$entry = $zoomRecordingProcessor->handleRecordingVideoComplete($dropFolderFile);
$this->updateDropFolderFile($entry->id , $dropFolderFile);
}
break;
default:
throw new kApplicativeException(KalturaDropFolderErrorCode::CONTENT_MATCH_POLICY_UNDEFINED, 'No content match policy is defined for drop folder');
}
KBatchBase::unimpersonate();
}
function updateDropFolderFile($entryId , $dropFolderFile)
{
$kZoomDropFolderFile = new KalturaZoomDropFolderFile();
$kZoomDropFolderFile->entryId = $entryId;
$this->dropFolderFileService->update($dropFolderFile->id, $kZoomDropFolderFile);
$this->dropFolderFileService->updateStatus($dropFolderFile->id, KalturaDropFolderFileStatus::HANDLED);
}
function shouldDisableExpiredDropFolder($dropFolder)
{
$accessExpiresIn = isset($dropFolder->accessExpiresIn) ? $dropFolder->accessExpiresIn : null;
if($accessExpiresIn && $accessExpiresIn <= time() - self::ONE_DAY*5)
{
return true;
}
return false;
}
function disableExpiredDropFolder($dropFolder)
{
$updateDropFolder = new KalturaDropFolder();
$updateDropFolder->status = DropFolderStatus::DISABLED;
$this->dropFolderPlugin->dropFolder->update($dropFolder->id, $updateDropFolder);
$expiredTimeInGmt = kTimeZoneUtils::timezoneDate('Y-m-d', $dropFolder->accessExpiresIn, 'GMT');
throw new Exception("Failed to refresh tokens, last successful refresh was on $expiredTimeInGmt GMT");
}
}