* Update media space email notification templates to use bcc instead of to
 */
require_once __DIR__ . '/../../bootstrap.php';
$criteria = new Criteria();
$criteria->add(EventNotificationTemplatePeer::STATUS, EventNotificationTemplateStatus::DELETED, Criteria::NOT_EQUAL);
$criteria->add(EventNotificationTemplatePeer::SYSTEM_NAME, array('New_Item_Pending_Moderation', 'New_Item_Pending_Moderation_2', 'Entry_Was_Added_To_Channel'), Criteria::IN);
$criteria->addAscendingOrderByColumn(EventNotificationTemplatePeer::ID);
$criteria->setLimit(100);
$eventNotificationTemplates = EventNotificationTemplatePeer::doSelect($criteria);
$lastId = 0;
$count = 0;
while ($eventNotificationTemplates) {
    foreach ($eventNotificationTemplates as $eventNotificationTemplate) {
        /* @var $eventNotificationTemplate EmailNotificationTemplate */
        $lastId = $eventNotificationTemplate->getId();
        $categoryId = new kEvalStringField();
        $categoryId->setCode('$scope->getEvent()->getObject()->getCategoryId()');
        $categoryUserFilter = new categoryKuserFilter();
        if ($eventNotificationTemplate->getSystemName() == 'Entry_Was_Added_To_Channel') {
            $categoryUserFilter->set('_matchor_permission_names', 'CATEGORY_SUBSCRIBE');
        } else {
            $categoryUserFilter->set('_matchor_permission_names', 'CATEGORY_MODERATE');
        }
        $bcc = new kEmailNotificationCategoryRecipientProvider();
        $bcc->setCategoryId($categoryId);
        $bcc->setCategoryUserFilter($categoryUserFilter);
        $eventNotificationTemplate->setBcc($bcc);
        $eventNotificationTemplate->setTo(null);
        $eventNotificationTemplate->save();
        $count++;
    }
Exemple #2
0
function handleFile($filePath)
{
    $con = Propel::getConnection(PartnerPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    $fileName = basename($filePath);
    KalturaLog::info("Handling file [{$fileName}]");
    list($order, $objectType, $fileExtension) = explode('.', $fileName, 3);
    $objectConfigurations = parse_ini_file($filePath, true);
    $object = new $objectType();
    /* @var $object BaseObject */
    $peer = $object->getPeer();
    $peerClass = get_class($peer);
    $newObjectType = "Insert{$objectType}";
    if (!class_exists($newObjectType)) {
        eval('
			class Insert' . $objectType . ' extends ' . $objectType . '
			{
				public function setId($v)
				{
					if(!$this->getId())
						parent::setId($v);
					
					return $this;
				}
				
				protected function doSave(PropelPDO $con)
				{
					$affectedRows = 0; // initialize var to track total num of affected rows
					if (!$this->alreadyInSave) {
						$this->alreadyInSave = true;
			
						$this->objectSaved = false;
						if ($this->isModified()) {
							if ($this->isNew()) {
								$pk = BasePeer::doInsert($this->buildCriteria(), $con);
								$affectedRows += 1;
								$this->setId($pk);  //[IMV] update autoincrement primary key
								$this->setNew(false);
								$this->objectSaved = true;
							} else {
								$affectedObjects = ' . $peerClass . '::doUpdate($this, $con);
								if($affectedObjects)
									$this->objectSaved = true;
									
								$affectedRows += $affectedObjects;
							}
			
							$this->resetModified(); // [HL] After being saved an object is no longer \'modified\'
						}
			
						$this->alreadyInSave = false;
					}
					return $affectedRows;
				}
			}
		');
    }
    $map = $peer->getTableMap();
    $primaryKeys = $map->getPrimaryKeys();
    foreach ($objectConfigurations as $objectConfiguration) {
        $object = new $newObjectType();
        /* @var $object BaseObject */
        $pk = null;
        $pkField = null;
        // New logic allowing to use other parameters as uique identifers for updates
        $identifierParam = null;
        $identifierColumn = null;
        $setters = array();
        foreach ($objectConfiguration as $attributeName => $value) {
            if ($attributeName == 'id') {
                $pk = $value;
            } elseif ($attributeName == 'identifierParam') {
                ${$attributeName} = $value;
                continue;
            }
            if (preg_match('/eval\\((?P<evalString>.+)\\)/', $value, $matches)) {
                $evalString = $matches["evalString"];
                $evaluator = new kEvalStringField();
                $evaluator->setScope(new kScope());
                $evaluator->setCode($evalString);
                $value = $evaluator->getValue();
                KalturaLog::info("Evaluated property value: {$value}");
            }
            $setter = "set{$attributeName}";
            if (!is_callable(array($object, $setter))) {
                throw new Exception("Attribute [{$attributeName}] not defined on object type [{$objectType}]");
            }
            if (preg_match('/^@[^@]+$/', $value)) {
                $valueFilePath = realpath(dirname($filePath) . '/' . substr($value, 1));
                if (!$valueFilePath || !is_file($valueFilePath)) {
                    throw new Exception("Attribute [{$attributeName}] file path [{$value}] not found");
                }
                $value = file_get_contents($valueFilePath);
            }
            if (preg_match('/^#[^#]+$/', $value)) {
                $value = kPluginableEnumsManager::genericApiToCore(substr($value, 1));
            }
            $setters[$setter] = $value;
        }
        $pkCriteria = null;
        $existingObject = null;
        if (!is_null($pk)) {
            $pkCriteria = new Criteria();
            $pkCriteria->add(constant(get_class($peer) . '::ID'), $pk);
            $existingObject = $peer->doSelectOne($pkCriteria, $con);
        } elseif (!is_null($identifierParam)) {
            // If we have some other form of identifier on the object
            $identifierColumn = $peer::translateFieldName($identifierParam, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME);
            $c = new Criteria();
            $c->add($identifierColumn, $objectConfiguration[$identifierParam]);
            $existingObject = $peer->doSelectOne($c, $con);
        }
        if ($existingObject) {
            KalturaLog::info('existing objects will not be re-written');
            continue;
        }
        foreach ($setters as $setter => $value) {
            $object->{$setter}($value);
        }
        $object->save();
        if (!is_null($pkCriteria)) {
            BasePeer::doUpdate($object->buildPkeyCriteria(), $pkCriteria, $con);
        }
        kMemoryManager::clearMemory();
    }
}
function createEmailNotification()
{
    $eventConditions = array();
    $liveStatusField = new kEvalBooleanField();
    $liveStatusField->setCode('$scope->getEvent()->getObject() instanceof LiveEntry && !$scope->getEvent()->getObject()->hasMediaServer() && $scope->getEvent()->getObject()->isCustomDataModified(null, \'mediaServers\')');
    $liveStatusCondition = new kEventFieldCondition();
    $liveStatusCondition->setDescription('Live Status Modified');
    $liveStatusCondition->setField($liveStatusField);
    $eventConditions[] = $liveStatusCondition;
    $liveStatusCondition = new kMatchMetadataCondition();
    $liveStatusCondition->setDescription('Metadata monitor field is on');
    $liveStatusCondition->setXPath('Monitor');
    $liveStatusCondition->setProfileSystemName('LiveMonitor');
    $liveStatusCondition->setValues(array('on'));
    $eventConditions[] = $liveStatusCondition;
    $toEmailNotificationRecipients = array();
    $toEmailNotificationRecipient = new kEmailNotificationRecipient();
    $toEmailNotificationRecipient->setEmail(new kStringValue('*****@*****.**'));
    $toEmailNotificationRecipient->setName(new kStringValue('Kaltura Customer Care'));
    $toEmailNotificationRecipients[] = $toEmailNotificationRecipient;
    //	$toEmailNotificationEmail = new kEvalStringField();
    //	$toEmailNotificationEmail->setCode('$scope->getEvent()->getObject()->getkuser() ? $scope->getEvent()->getObject()->getkuser()->getEmail() : \'\'');
    //	$toEmailNotificationName = new kEvalStringField();
    //	$toEmailNotificationName->setCode('$scope->getEvent()->getObject()->getkuser() ? $scope->getEvent()->getObject()->getkuser()->getScreenName() : \'\'');
    //	$toEmailNotificationRecipient = new kEmailNotificationRecipient();
    //	$toEmailNotificationRecipient->setEmail($toEmailNotificationEmail);
    //	$toEmailNotificationRecipient->setName($toEmailNotificationName);
    //	$toEmailNotificationRecipients[] = $toEmailNotificationRecipient;
    $toEmail = new kEmailNotificationStaticRecipientProvider();
    $toEmail->setEmailRecipients($toEmailNotificationRecipients);
    $contentParameters = array();
    $eventNotificationValue = new kEvalStringField();
    $eventNotificationValue->setCode('kConf::get(\'partner_notification_email\')');
    $eventNotificationParameter = new kEventNotificationParameter();
    $eventNotificationParameter->setKey('from_email');
    $eventNotificationParameter->setDescription('kConf: Partner Notification E-Mail');
    $eventNotificationParameter->setValue($eventNotificationValue);
    $contentParameters[] = $eventNotificationParameter;
    $eventNotificationValue = new kEvalStringField();
    $eventNotificationValue->setCode('kConf::get(\'partner_notification_name\')');
    $eventNotificationParameter = new kEventNotificationParameter();
    $eventNotificationParameter->setKey('from_name');
    $eventNotificationParameter->setDescription('kConf: Partner Notification Name');
    $eventNotificationParameter->setValue($eventNotificationValue);
    $contentParameters[] = $eventNotificationParameter;
    $eventNotificationValue = new kEvalStringField();
    $eventNotificationValue->setCode('$scope->getEvent()->getObject()->getPartnerId()');
    $eventNotificationParameter = new kEventNotificationParameter();
    $eventNotificationParameter->setKey('partner_id');
    $eventNotificationParameter->setDescription('Partner ID');
    $eventNotificationParameter->setValue($eventNotificationValue);
    $contentParameters[] = $eventNotificationParameter;
    $eventNotificationValue = new kEvalStringField();
    $eventNotificationValue->setCode('$scope->getEvent()->getObject()->getId()');
    $eventNotificationParameter = new kEventNotificationParameter();
    $eventNotificationParameter->setKey('entry_id');
    $eventNotificationParameter->setDescription('Entry ID');
    $eventNotificationParameter->setValue($eventNotificationValue);
    $contentParameters[] = $eventNotificationParameter;
    $eventNotificationValue = new kEvalStringField();
    $eventNotificationValue->setCode('$scope->getEvent()->getObject()->getName()');
    $eventNotificationParameter = new kEventNotificationParameter();
    $eventNotificationParameter->setKey('entry_name');
    $eventNotificationParameter->setDescription('Entry Name');
    $eventNotificationParameter->setValue($eventNotificationValue);
    $contentParameters[] = $eventNotificationParameter;
    $emailNotification = new EmailNotificationTemplate();
    $emailNotification->setPartnerId(99);
    $emailNotification->setStatus(EventNotificationTemplateStatus::ACTIVE);
    $emailNotification->setName('Is Live Entry Still Alive');
    $emailNotification->setSystemName('EMAIL_LIVE_ENTRY_NOT_ALIVE');
    $emailNotification->setDescription('Email notification template to be sent when a 24/7 live-entry stopped broadcasting.');
    $emailNotification->setAutomaticDispatchEnabled(true);
    $emailNotification->setEventType(EventNotificationEventType::OBJECT_CHANGED);
    $emailNotification->setObjectType(EventNotificationEventObjectType::ENTRY);
    $emailNotification->setEventConditions($eventConditions);
    $emailNotification->setFormat(EmailNotificationFormat::HTML);
    $emailNotification->setSubject('[Kaltura] - Live-Entry [{partner_id}/{entry_id}] stopped broadcasting.');
    $emailNotification->setBody("Partner ID: {partner_id}<br/>\nEntry ID: {entry_id}<br/>\nEntry Name: {entry_name}<br/>\n");
    $emailNotification->setFromEmail('{from_email}');
    $emailNotification->setFromName('{from_name}');
    $emailNotification->setTo($toEmail);
    $emailNotification->setContentParameters($contentParameters);
    $emailNotification->setRequiredCopyTemplatePermissions(FEATURE_KALTURA_LIVE_MONITOR);
    $emailNotification->save();
}