-
Notifications
You must be signed in to change notification settings - Fork 184
fix(SUP-50789): Fix Sync Method Used Credit #13889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Venus-22.17.0
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,30 +150,52 @@ 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(); | ||
| $stmt = EntryVendorTaskPeer::doSelectStmt($c); | ||
| $row = $stmt->fetch(PDO::FETCH_NUM); | ||
| $syncStartDate = $this->getSyncCreditStartDate(); | ||
|
|
||
| $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); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this $this->addAdditionalCriteria($c); was deleted? |
||
| $queueTasks = EntryVendorTaskPeer::doSelect($queueC); | ||
|
|
||
| $totalPrice = $row[0]; | ||
| if($totalPrice) | ||
| foreach ($queueTasks as $task) | ||
| { | ||
| $totalUsedCredit += $totalPrice; | ||
| if (!$task->getIsPayPerUse()) | ||
| { | ||
| $totalPrice += $task->getPrice(); | ||
| } | ||
| } | ||
|
|
||
| $this->setSyncedCredit($totalUsedCredit); | ||
| $this->setLastSyncTime($now); | ||
| /* 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) | ||
| { | ||
| $totalUsedCredit += $totalPrice; | ||
| } | ||
| return $totalUsedCredit; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why deleted these 2 lines? |
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to add Default value to the setIsPayPerUse
else
{
$object_to_fill->setIsPayPerUse(false); // Default value
}
@MosheMaorKaltura WDYT?