Skip to content
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

Add option to delay notifications when entry added to channel if entr… #13087

Open
wants to merge 2 commits into
base: Ursa-21.8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions alpha/apps/kaltura/lib/batch2/kFlowHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,16 @@ public static function addDeliveryTagToEntry(entry $entry)
$entry->save();
}
}

public static function handleDelayedNotification(entry $entry)
{
$delayedLockedJob = BatchJobLockPeer::retrieveByEntryIdAndStatus($entry->getEntryId(), BatchJob::BATCHJOB_STATUS_DELAYED);
if ($delayedLockedJob)
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
{
$delayedJob = BatchJobPeer::retrieveByEntryIdAndStatus($entry->getEntryId(), BatchJob::BATCHJOB_STATUS_DELAYED);
kJobsManager::updateBatchJob($delayedJob, BatchJob::BATCHJOB_STATUS_PENDING);
}
}

/**
* @param entry $entry
Expand Down
1 change: 1 addition & 0 deletions alpha/apps/kaltura/lib/batch2/kFlowManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ public function objectChanged(BaseObject $object, array $modifiedColumns)
&& $object->getStatus() == entryStatus::READY)
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
{
kFlowHelper::addDeliveryTagToEntry($object);
kFlowHelper::handleDelayedNotification($object);
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
}

if ($object instanceof entry
Expand Down
1 change: 1 addition & 0 deletions alpha/lib/model/BatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BatchJob extends BaseBatchJob implements ISyncableFile
const BATCHJOB_STATUS_FINISHED_PARTIALLY = 12;
const BATCHJOB_STATUS_SUSPEND = 13;
const BATCHJOB_STATUS_SUSPEND_ALMOST_DONE = 14;
const BATCHJOB_STATUS_DELAYED = 15;

const FILE_SYNC_BATCHJOB_SUB_TYPE_BULKUPLOAD = 1;
const FILE_SYNC_BATCHJOB_SUB_TYPE_CONFIG = 3;
Expand Down
15 changes: 12 additions & 3 deletions alpha/lib/model/BatchJobLockPeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class BatchJobLockPeer extends BaseBatchJobLockPeer {
);

const COUNT = 'COUNT(batch_job_lock.ID)';


/**
* This function returns a list of all job statuses that still require scheduling
* and therefore a lock object should appear for them in the lock table.
Expand All @@ -35,7 +35,8 @@ public static function getSchedulingRequiredStatusList()
BatchJob::BATCHJOB_STATUS_RETRY,
BatchJob::BATCHJOB_STATUS_PROCESSING,
BatchJob::BATCHJOB_STATUS_PROCESSED,
BatchJob::BATCHJOB_STATUS_MOVEFILE
BatchJob::BATCHJOB_STATUS_MOVEFILE,
BatchJob::BATCHJOB_STATUS_DELAYED
);
}

Expand Down Expand Up @@ -243,4 +244,12 @@ public static function retrieveByEntryId($entryId, array $jobTypes = null, array

return self::doSelect($c);
}

public static function retrieveByEntryIdAndStatus($obj_id, $status)
{
$c = new Criteria();
$c->add ( self::ENTRY_ID , $obj_id );
$c->add ( self::STATUS , $status );
return self::doSelectOne( $c );
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
}
} // BatchJobLockPeer
9 changes: 9 additions & 0 deletions alpha/lib/model/BatchJobPeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static function getUnClosedStatusList()
BatchJob::BATCHJOB_STATUS_PROCESSED,
BatchJob::BATCHJOB_STATUS_MOVEFILE,
BatchJob::BATCHJOB_STATUS_RETRY,
BatchJob::BATCHJOB_STATUS_DELAYED
);
}

Expand Down Expand Up @@ -79,6 +80,14 @@ public static function retrieveByEntryId($obj_id)
$c->add ( self::ENTRY_ID , $obj_id );
return self::doSelect( $c );
}

public static function retrieveByEntryIdAndStatus($obj_id, $status)
{
$c = new Criteria();
$c->add ( self::ENTRY_ID , $obj_id );
$c->add ( self::STATUS , $status );
return self::doSelectOne( $c );
}

public static function doAvgTimeDiff($jobType, $t1, $t2, PDO $con = null)
{
Expand Down
12 changes: 12 additions & 0 deletions deployment/permissions/object.KalturaEventNotificationTemplate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ permissionItem8.parameter = manualDispatchEnabled
permissionItem8.action = insert
permissionItem8.partnerId = -2
permissionItem8.permissions = eventNotification.SYSTEM_ADMIN_EVENT_NOTIFICATION_INSERT, PARTNER_-2_GROUP_*_PERMISSION

permissionItem9.object = KalturaEventNotificationTemplate
permissionItem9.parameter = eventDelayedConditions
permissionItem9.action = insert
permissionItem9.partnerId = -2
permissionItem9.permissions = eventNotification.SYSTEM_ADMIN_EVENT_NOTIFICATION_INSERT, PARTNER_-2_GROUP_*_PERMISSION

permissionItem10.object = KalturaEventNotificationTemplate
permissionItem10.parameter = eventDelayedConditions
permissionItem10.action = update
permissionItem10.partnerId = -2
permissionItem10.permissions = eventNotification.SYSTEM_ADMIN_EVENT_NOTIFICATION_MODIFY, PARTNER_-2_GROUP_*_PERMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @package deployment
* @subpackage scorpius.roles_and_permissions
*/

$script = realpath(dirname(__FILE__) . '/../../../../') . '/alpha/scripts/utils/permissions/addPermissionsAndItems.php';
$config = realpath(dirname(__FILE__)) . '/../../../permissions/object.KalturaEventNotificationTemplate.ini';
passthru("php $script $config");
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @package plugins.eventNotification
* @subpackage api.enum
* @see EventNotificationTemplateStatus
*/
class KalturaEventNotificationDelayedConditions extends KalturaEnum implements EventNotificationDelayedConditions
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ class KalturaEventNotificationTemplate extends KalturaObject implements IFiltera
* @var KalturaEventNotificationParameterArray
*/
public $userParameters;

/**
* Event batch job will be delayed until specific condition criteria is met
*
* @var KalturaEventNotificationDelayedConditions
* @requiresPermission update
*/
public $eventDelayedConditions;

/**
* mapping between the field on this object (on the left) and the setter/getter on the entry object (on the right)
Expand All @@ -134,6 +142,7 @@ class KalturaEventNotificationTemplate extends KalturaObject implements IFiltera
'eventConditions',
'contentParameters',
'userParameters',
'eventDelayedConditions'
);

/* (non-PHPdoc)
Expand Down Expand Up @@ -173,7 +182,7 @@ public function toObject($dbObject = null, $propertiesToSkip = array())
{
if(is_null($dbObject))
throw new kCoreException("Event notification template type [" . $this->type . "] not found", kCoreException::OBJECT_TYPE_NOT_FOUND, $this->type);

return parent::toObject($dbObject, $propertiesToSkip);
}

Expand Down Expand Up @@ -219,4 +228,4 @@ protected function validate (EventNotificationTemplate $sourceObject = null)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,29 @@ protected function addEventNotificationDispatchJob($eventNotificationType, kEven
$batchJob = kJobsManager::addJob($batchJob, $jobData, $jobType, $eventNotificationType);
$jobData->setJobId($batchJob->getId());
$batchJob->setData($jobData);


if ($this->getEventDelayedConditions() && $entryId && $this->areDelayedEventConditionsMet($entryId))
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
danbar0kal marked this conversation as resolved.
Show resolved Hide resolved
{
return kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_DELAYED);
}

return kJobsManager::updateBatchJob($batchJob, BatchJob::BATCHJOB_STATUS_PENDING);
}

public function areDelayedEventConditionsMet($objectId)
{
$delayedEventConditions = $this->getEventDelayedConditions();
if ($delayedEventConditions)
{
switch ($delayedEventConditions)
{
case EventNotificationDelayedConditions::PENDING_ENTRY_READY:
{
$entry = BaseentryPeer::retrieveByPK($objectId);
return $entry->getStatus() !== entryStatus::READY;
}
}
}
return false;
}
}
11 changes: 11 additions & 0 deletions plugins/event_notification/lib/model/EventNotificationTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class EventNotificationTemplate extends BaseEventNotificationTemplate i
const CUSTOM_DATA_MANUAL_DISPATCH_ENABLED = 'manualDispatchEnabled';
const CUSTOM_DATA_AUTOMATIC_DISPATCH_ENABLED = 'automaticDispatchEnabled';
const CUSTOM_DATA_URL_ENCODE = 'urlEncode';
const EVENT_DELAYED_CONDITIONS = 'eventDelayedConditions';

/**
* Dispatch the event notification
Expand Down Expand Up @@ -58,6 +59,16 @@ public function getCacheInvalidationKeys()
{
return array("eventNotificationTemplate:id=".strtolower($this->getId()), "eventNotificationTemplate:partnerId=".strtolower($this->getPartnerId()));
}

public function setEventDelayedConditions($v)
{
return $this->putInCustomData(self::EVENT_DELAYED_CONDITIONS, $v);
}

public function getEventDelayedConditions()
{
return $this->getFromCustomData(self::EVENT_DELAYED_CONDITIONS, null, null);
}

public function getContentParametersKeyValueArray()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* @package plugins.eventNotification
* @subpackage model.enum
*/
interface EventNotificationDelayedConditions extends BaseEnum
{
const NONE = 0;
const PENDING_ENTRY_READY = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public function populateFromObject($object, $add_underscore = true)
*/
protected function addTypeElements(Kaltura_Client_EventNotification_Type_EventNotificationTemplate $eventNotificationTemplate)
{
$this->addElement('select', 'event_delayed_conditions', array(
'label' => 'Delay Notification Condition:',
'filters' => array('StringTrim'),
'required' => true,
'multiOptions' => array(
Kaltura_Client_EventNotification_Enum_EventNotificationDelayedConditions::NONE => 'Do not delay',
Kaltura_Client_EventNotification_Enum_EventNotificationDelayedConditions::PENDING_ENTRY_READY => 'Until entry is ready',
),
));

$format = new Kaltura_Form_Element_EnumSelect('format', array(
'enum' => 'Kaltura_Client_EmailNotification_Enum_EmailNotificationFormat',
'label' => 'Format:',
Expand Down Expand Up @@ -159,4 +169,4 @@ protected function populateHeaderField($object , $headerName)
));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ protected function addTypeElements(Kaltura_Client_EventNotification_Type_EventNo
));
$this->addElements(array($element));

$this->addElement('select', 'event_delayed_conditions', array(
'label' => 'Delay Notification Condition:',
'filters' => array('StringTrim'),
'required' => true,
'multiOptions' => array(
Kaltura_Client_EventNotification_Enum_EventNotificationDelayedConditions::NONE => 'None',
Kaltura_Client_EventNotification_Enum_EventNotificationDelayedConditions::PENDING_ENTRY_READY => 'When entry is ready',
),
));

$this->addElement('select', 'secureHashingAlgo', array(
'label' => 'Secure Hashing Algorithm:',
'filters' => array('StringTrim'),
Expand Down Expand Up @@ -159,4 +169,4 @@ protected function addTypeElements(Kaltura_Client_EventNotification_Type_EventNo
'decorators' => array('FormElements', 'Fieldset', array('HtmlTag', array('tag' => 'div', 'style' => 'display: none', 'id' => 'frmFreeText'))),
));
}
}
}
6 changes: 6 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Ursa-21.8.0
## Add option to delay notifications ##
* Issue Type: Task
* Issue ID: PLAT-25045
### Deployment script ###
php deployment/updates/scripts/add_permissions/2025_01_19_eventNotification_update_eventDelayedConditions_permission.php
# Ursa-21.4.0
## Kava - redirect external client tags to dedicated druid url ##
- Issue Type: Story
Expand Down