From b2f07fd08ad802a6194634cc3a8a916f465a51bd Mon Sep 17 00:00:00 2001 From: Moshe Maor Date: Wed, 4 Feb 2026 14:02:08 +0200 Subject: [PATCH 1/2] Revert "fix(SUP-50789): Fix Sync Method Used Credit" (#13779) --- .../KalturaEntryVendorTask.php | 17 +----- plugins/reach/lib/model/EntryVendorTask.php | 11 ---- .../reach/lib/model/data/kVendorCredit.php | 53 +++++-------------- 3 files changed, 14 insertions(+), 67 deletions(-) diff --git a/plugins/reach/lib/api/data/entryVendorTaks/KalturaEntryVendorTask.php b/plugins/reach/lib/api/data/entryVendorTaks/KalturaEntryVendorTask.php index 9a7fdd5865f..ddf21763249 100644 --- a/plugins/reach/lib/api/data/entryVendorTaks/KalturaEntryVendorTask.php +++ b/plugins/reach/lib/api/data/entryVendorTaks/KalturaEntryVendorTask.php @@ -223,13 +223,6 @@ class KalturaEntryVendorTask extends KalturaObject implements IRelatedFilterable */ public $externalTaskId; - /** - * Indicates if the task is pay-per-use based on the catalog item - * @var bool - * @readonly - */ - public $isPayPerUse; - private static $map_between_objects = array ( 'id', @@ -263,8 +256,7 @@ class KalturaEntryVendorTask extends KalturaObject implements IRelatedFilterable 'serviceType', 'serviceFeature', 'turnAroundTime', - 'externalTaskId', - 'isPayPerUse' + 'externalTaskId' ); /* (non-PHPdoc) @@ -287,13 +279,6 @@ public function toInsertableObject($object_to_fill = null, $props_to_skip = arra $object_to_fill = parent::toInsertableObject($object_to_fill, $props_to_skip); - // Set isPayPerUse flag based on catalog item - $dbVendorCatalogItem = VendorCatalogItemPeer::retrieveByPK($object_to_fill->getCatalogItemId()); - if ($dbVendorCatalogItem) - { - $object_to_fill->setIsPayPerUse($dbVendorCatalogItem->getPayPerUse()); - } - $jobData = $this->taskJobData; if ($this->isScheduled() && !$jobData->scheduledEventId) { diff --git a/plugins/reach/lib/model/EntryVendorTask.php b/plugins/reach/lib/model/EntryVendorTask.php index f76db9532fe..9f216fb321d 100644 --- a/plugins/reach/lib/model/EntryVendorTask.php +++ b/plugins/reach/lib/model/EntryVendorTask.php @@ -37,7 +37,6 @@ class EntryVendorTask extends BaseEntryVendorTask implements IRelatedObject, IIn const CUSTOM_DATA_SERVICE_FEATURE = 'serviceFeature'; const CUSTOM_DATA_TURN_AROUND_TIME = 'turnAroundTime'; const CUSTOM_DATA_EXTERNAL_TASK_ID = 'externalTaskId'; - const CUSTOM_DATA_IS_PAY_PER_USE = 'isPayPerUse'; const SEVEN_DAYS = 604800; const BUSINESS_DAY_FRIDAY = 5; //Monday is 1 const BUSINESS_DAY_NEXT_MONDAY = 8; @@ -157,11 +156,6 @@ public function setExternalTaskId($v) $this->putInCustomData(self::CUSTOM_DATA_EXTERNAL_TASK_ID, $v); } - public function setIsPayPerUse($v) - { - $this->putInCustomData(self::CUSTOM_DATA_IS_PAY_PER_USE, $v); - } - //getters @@ -285,11 +279,6 @@ public function getExternalTaskId() return $this->getFromCustomData(self::CUSTOM_DATA_EXTERNAL_TASK_ID); } - public function getIsPayPerUse() - { - return $this->getFromCustomData(self::CUSTOM_DATA_IS_PAY_PER_USE, null, false); - } - public function isScheduled() { return $this->getTaskJobData() instanceof kScheduledVendorTaskData; diff --git a/plugins/reach/lib/model/data/kVendorCredit.php b/plugins/reach/lib/model/data/kVendorCredit.php index cb94f59fd35..29a39f9a6c2 100644 --- a/plugins/reach/lib/model/data/kVendorCredit.php +++ b/plugins/reach/lib/model/data/kVendorCredit.php @@ -150,49 +150,23 @@ public function isSynced() public function syncCredit($reachProfileId, $partnerId) { + $c = new Criteria(); + $c->add(EntryVendorTaskPeer::REACH_PROFILE_ID, $reachProfileId , Criteria::EQUAL); + $c->add(EntryVendorTaskPeer::STATUS, array(EntryVendorTaskStatus::PENDING, EntryVendorTaskStatus::PROCESSING, EntryVendorTaskStatus::READY), Criteria::IN); + $c->add(EntryVendorTaskPeer::QUEUE_TIME, $this->getSyncCreditStartDate(), Criteria::GREATER_EQUAL); + $c->add(EntryVendorTaskPeer::PRICE, 0, Criteria::NOT_EQUAL); + $c->add(EntryVendorTaskPeer::PARTNER_ID, $partnerId); + $c->addSelectColumn('SUM('. EntryVendorTaskPeer::PRICE .')'); + $this->addAdditionalCriteria($c); + $now = time(); - $syncStartDate = $this->getSyncCreditStartDate(); + $stmt = EntryVendorTaskPeer::doSelectStmt($c); + $row = $stmt->fetch(PDO::FETCH_NUM); $totalUsedCredit = $this->getSyncedCredit(); - $totalPrice = 0; - - /* Query 1: Queue-based (non PPU) */ - $queueC = new Criteria(); - $queueC->add(EntryVendorTaskPeer::REACH_PROFILE_ID, $reachProfileId); - $queueC->add(EntryVendorTaskPeer::PARTNER_ID, $partnerId); - $queueC->add(EntryVendorTaskPeer::PRICE, 0, Criteria::NOT_EQUAL); - $queueC->add(EntryVendorTaskPeer::STATUS, [EntryVendorTaskStatus::PENDING, EntryVendorTaskStatus::PROCESSING, EntryVendorTaskStatus::READY], Criteria::IN); - $queueC->add(EntryVendorTaskPeer::QUEUE_TIME, $syncStartDate, Criteria::GREATER_EQUAL); - - $queueTasks = EntryVendorTaskPeer::doSelect($queueC); - - foreach ($queueTasks as $task) - { - if (!$task->getIsPayPerUse()) - { - $totalPrice += $task->getPrice(); - } - } - /* Query 2: Finish-based (PPU) */ - $finishC = new Criteria(); - $finishC->add(EntryVendorTaskPeer::REACH_PROFILE_ID, $reachProfileId); - $finishC->add(EntryVendorTaskPeer::PARTNER_ID, $partnerId); - $finishC->add(EntryVendorTaskPeer::PRICE, 0, Criteria::NOT_EQUAL); - $finishC->add(EntryVendorTaskPeer::STATUS, EntryVendorTaskStatus::READY); - $finishC->add(EntryVendorTaskPeer::FINISH_TIME, $syncStartDate, Criteria::GREATER_EQUAL); - - $finishedTasks = EntryVendorTaskPeer::doSelect($finishC); - - foreach ($finishedTasks as $task) - { - if ($task->getIsPayPerUse()) - { - $totalPrice += $task->getPrice(); - } - } - - if ($totalPrice) + $totalPrice = $row[0]; + if($totalPrice) { $totalUsedCredit += $totalPrice; } @@ -203,7 +177,6 @@ public function syncCredit($reachProfileId, $partnerId) return $totalUsedCredit; } - /*** * @param $includeOverages should return current credit including overageCredit info or not (Default is true) * @return int From 274685507d49913cd6f69fd2673e189f82fc9880 Mon Sep 17 00:00:00 2001 From: MaimanaGhnem <110167041+MaimanaGhnem@users.noreply.github.com> Date: Tue, 10 Feb 2026 10:09:11 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"Revert=20"SUP-49975:=20Prevent=20?= =?UTF-8?q?DFF=20purge=20and=20recreate=20when=20file=20is=20alread?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c914bd3b38634dadac8c78a55205cb97c9f66c4e. --- .../services/DropFolderFileService.php | 4 +++- .../batch/KZoomDropFolderEngine.php | 17 +++++++++++++++ .../zoom/lib/model/kZoomEventHanlder.php | 21 +++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/plugins/drop_folder/services/DropFolderFileService.php b/plugins/drop_folder/services/DropFolderFileService.php index 430a53b3cc6..50e66e08c20 100644 --- a/plugins/drop_folder/services/DropFolderFileService.php +++ b/plugins/drop_folder/services/DropFolderFileService.php @@ -235,7 +235,9 @@ private function newFileAddedOrDetected(KalturaDropFolderFile $dropFolderFile, $ $dbDropFolderFile = $existingDropFolderFile; break; case DropFolderFileStatus::DETECTED: - KalturaLog::info('Exisiting file status is DETECTED, updating status to ['.$fileStatus.']'); + case DropFolderFileStatus::PROCESSING: + $statusName = $existingDropFolderFile->getStatus() == DropFolderFileStatus::DETECTED ? 'DETECTED' : 'PROCESSING'; + KalturaLog::info("Exisiting file status is $statusName, updating status to [$fileStatus]"); $existingDropFolderFile = $dropFolderFile->toUpdatableObject($existingDropFolderFile); if($existingDropFolderFile->getStatus() != $fileStatus) $existingDropFolderFile->setStatus($fileStatus); diff --git a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php index a444bbcc46b..52023bbd0d2 100644 --- a/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php +++ b/plugins/vendor/zoom/ZoomDropFolderPlugin/batch/KZoomDropFolderEngine.php @@ -280,6 +280,11 @@ protected function handleMeetingFiles($meetingFiles, &$fileInStatusProcessingExi { $parentEntry = $this->createEntry($meetingFile[self::UUID], $this->dropFolder->zoomVendorIntegration->enableZoomTranscription, $recordingFile[self::RECORDING_START], $userId); + if (!$parentEntry) + { + KalturaLog::debug("Another system (ZOOM EVENT) is creating the parent entry, skipping drop folder file creation"); + continue; // Skip this recording file + } $this->addDropFolderFile($meetingFile, $recordingFile, $parentEntry->id, true); } } @@ -318,6 +323,18 @@ protected function getEntryByReferenceId($referenceId) protected function createEntry($uuid, $enableTranscriptionViaZoom, $recordingStartTime, $userId) { + if (empty($recordingStartTime)) + { + throw new kCoreException("Recording start time is null or empty for UUID: {$uuid}"); + } + $lockKey = $uuid . '_' . $recordingStartTime; + $resourceReservation = new kResourceReservation(kZoomRecordingProcessor::ZOOM_LOCK_TTL, true); + if(!$resourceReservation->reserve($lockKey)) + { + KalturaLog::debug("Entry creation for {$lockKey} is being processed by another system"); + return null; // Let the other system (Event) handle it + } + $newEntry = new KalturaMediaEntry(); $newEntry->sourceType = KalturaSourceType::URL; $newEntry->mediaType = KalturaMediaType::VIDEO; diff --git a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php index 9ce9358f656..06ca4241cdb 100644 --- a/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php +++ b/plugins/vendor/zoom/lib/model/kZoomEventHanlder.php @@ -321,6 +321,11 @@ protected static function createZoomDropFolderFile(kZoomEvent $event, $dropFolde { $parentEntry = self::createEntry($recording->uuid, $partnerId, $zoomVendorIntegration->getEnableZoomTranscription(), $recordingFile->recordingStart, $conversionProfileId); + if (!$parentEntry) + { + KalturaLog::debug("Another system (Watcher) is creating the parent entry, skipping drop folder file creation"); + continue; // Skip this recording file + } $zoomDropFolderFile->setIsParentEntry(true); } } @@ -437,6 +442,18 @@ protected static function getEntryByReferenceId($referenceId, $partnerId) protected static function createEntry($uuid, $partnerId, $enableTranscriptionViaZoom, $recordingStartTime, $conversionProfileId) { + if (empty($recordingStartTime)) + { + throw new kCoreException("Recording start time is null or empty for UUID: {$uuid}"); + } + $lockKey = $uuid . '_' . $recordingStartTime; + $resourceReservation = new kResourceReservation(kZoomRecordingProcessor::ZOOM_LOCK_TTL, true); + if(!$resourceReservation->reserve($lockKey)) + { + KalturaLog::debug("Entry creation for {$lockKey} is being processed by another system"); + return null; // Let the other system (Watcher) handle it + } + $templateEntry = null; $conversionProfile = conversionProfile2Peer::retrieveByPK($conversionProfileId); $defaultEntryId = $conversionProfile->getDefaultEntryId(); @@ -444,7 +461,7 @@ protected static function createEntry($uuid, $partnerId, $enableTranscriptionVia { $templateEntry = entryPeer::retrieveByPKNoFilter($defaultEntryId, null, false); } - + $newEntry = new entry(); if($templateEntry) { @@ -485,4 +502,4 @@ protected static function retrieveByFolderIdAndStatusesNotInAndName($dropFolderI return $dropFolderFiles; } -} \ No newline at end of file +}