Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ class KalturaEntryVendorTask extends KalturaObject implements IRelatedFilterable
*/
public $externalObjectId;

/**
* 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',
Expand Down Expand Up @@ -264,7 +272,8 @@ class KalturaEntryVendorTask extends KalturaObject implements IRelatedFilterable
'serviceFeature',
'turnAroundTime',
'externalTaskId',
'externalObjectId'
'externalObjectId',
'isPayPerUse'
);

/* (non-PHPdoc)
Expand All @@ -287,6 +296,13 @@ 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());
}

Copy link
Copy Markdown
Collaborator

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?


$jobData = $this->taskJobData;
if ($this->isScheduled() && !$jobData->scheduledEventId)
{
Expand Down
11 changes: 11 additions & 0 deletions plugins/reach/lib/model/EntryVendorTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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 CUSTOM_DATA_EXTERNAL_OBJECT_ID = 'externalObjectId';
const SEVEN_DAYS = 604800;
const BUSINESS_DAY_FRIDAY = 5; //Monday is 1
Expand Down Expand Up @@ -162,6 +163,11 @@
$this->putInCustomData(self::CUSTOM_DATA_EXTERNAL_OBJECT_ID, $v);
}

public function setIsPayPerUse($v)
{
$this->putInCustomData(self::CUSTOM_DATA_IS_PAY_PER_USE, $v);
}


//getters

Expand Down Expand Up @@ -285,6 +291,11 @@
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 getExternalObjectId()
{
return $this->getFromCustomData(self::CUSTOM_DATA_EXTERNAL_OBJECT_ID);
Expand Down Expand Up @@ -554,23 +565,23 @@
$connectedEvent->save();
}

public function save(PropelPDO $con = null)
{
if (in_array(EntryVendorTaskPeer::STATUS, $this->modifiedColumns) &&
(in_array($this->status, array(EntryVendorTaskStatus::PROCESSING, EntryVendorTaskStatus::ABORTED))))
{
if (in_array($this->oldColumnsValues[EntryVendorTaskPeer::STATUS],
array(EntryVendorTaskStatus::PENDING, EntryVendorTaskStatus::PENDING_MODERATION, EntryVendorTaskStatus::PENDING_ENTRY_READY, EntryVendorTaskStatus::SCHEDULED)))
{
return parent::save($con);
}
else
{
throw new kCoreException("Entry vendor task item with id [$this->id] could not be updated to status [$this->status]", kCoreException::ENTRY_VENDOR_TASK_ITEM_COULD_NOT_BE_UPDATED);

}
}
parent::save($con);
}

Check warning on line 585 in plugins/reach/lib/model/EntryVendorTask.php

View check run for this annotation

OX Security / ox-security/scan

Inadequate Privacy Controls • PHP • Public Repo

Implement proper privacy controls including data minimization, access controls, encryption of sensitive data, and user consent mechanisms. Ensure compliance with privacy regulations like GDPR.

} // EntryVendorTask
54 changes: 38 additions & 16 deletions plugins/reach/lib/model/data/kVendorCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why deleted these 2 lines?
$this->setSyncedCredit($totalUsedCredit);
$this->setLastSyncTime($now);

}

Expand Down
Loading