Esempio n. 1
0
 /**
  * Return the notifications for a specific entry id and type
  * 
  * @action getClientNotification
  * @param string $entryId
  * @param KalturaNotificationType $type
  * @return KalturaClientNotification
  */
 function getClientNotificationAction($entryId, $type)
 {
     // in case of a multirequest, a mediaService.addFromUploadedFile may fail and therefore the resulting entry id will be empty
     // in such a case return immidiately without looking for the notification
     if ($entryId == '') {
         throw new KalturaAPIException(KalturaErrors::NOTIFICATION_FOR_ENTRY_NOT_FOUND, $entryId);
     }
     $notifications = BatchJobPeer::retrieveByEntryIdAndType($entryId, BatchJobType::NOTIFICATION, $type);
     // FIXME: throw error if not found
     if (count($notifications) == 0) {
         throw new KalturaAPIException(KalturaErrors::NOTIFICATION_FOR_ENTRY_NOT_FOUND, $entryId);
     }
     $notification = $notifications[0];
     $partnerId = $this->getPartnerId();
     $nofication_config_str = null;
     list($nofity, $nofication_config_str) = myPartnerUtils::shouldNotify($partnerId);
     if (!$nofity) {
         return new KalturaClientNotification();
     }
     $nofication_config = myNotificationsConfig::getInstance($nofication_config_str);
     $nofity_send_type = $nofication_config->shouldNotify($type);
     if ($nofity_send_type != myNotificationMgr::NOTIFICATION_MGR_SEND_SYNCH && $nofity_send_type != myNotificationMgr::NOTIFICATION_MGR_SEND_BOTH) {
         return new KalturaClientNotification();
     }
     $partner = PartnerPeer::retrieveByPK($partnerId);
     list($url, $signatureKey) = myNotificationMgr::getPartnerNotificationInfo($partner);
     list($params, $rawSignature) = myNotificationMgr::prepareNotificationData($url, $signatureKey, $notification, null);
     $serializedParams = http_build_query($params, "", "&");
     $result = new KalturaClientNotification();
     $result->url = $url;
     $result->data = $serializedParams;
     return $result;
 }
 /**
  * $notification_type -
  * $puser_id - the puser_id of the kuser that caused the modification
  * $object_data - can be either an object or an object id (if the object no longer exists
  * $partner_id - if exists, use this (usually in case of $object_data is an id), if not - use the partner_id from the object
  * $entry_id is optional
  */
 public static function createNotification($notification_type, $object_data, $partner_id = null, $puser_id = null, $prefix = null, $extra_notification_data = null, $entry_id = null)
 {
     if (!$entry_id && $object_data instanceof entry) {
         $entry_id = $object_data->getId();
     }
     if (!$partner_id) {
         if ($object_data instanceof BaseObject) {
             $partner_id = $object_data->getPartnerId();
         } else {
             KalturaLog::log("Cannot create notification [{$notification_type}] [{$object_data}] [{$partner_id}]");
             return false;
         }
     }
     //		echo "[$partner_id]";
     $nofication_config_str = null;
     list($nofity, $nofication_config_str) = myPartnerUtils::shouldNotify($partner_id);
     if (!$nofity) {
         return false;
     }
     $nofication_config = myNotificationsConfig::getInstance($nofication_config_str);
     $nofity_send_type = $nofication_config->shouldNotify($notification_type);
     //echo "nofication_config_str: $nofication_config_str<br>notification_type:$notification_type<br>";
     if ($nofity_send_type == self::NOTIFICATION_MGR_NO_SEND) {
         return false;
     }
     //echo "nofity_send_type: $nofity_send_type<br>";
     // now check what type of notification to use - none / synch / a-synch
     //		Remarked by Tan-Tan, Nov 5 2009 to support the new batches
     //
     //		$not = new notification();
     //		$not->setType( $notification_type );
     //		if (  $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH)
     //		{
     //
     //			// the notification should be in status pending so it will be sent in the
     //			$not->setStatus( BatchJob::BATCHJOB_STATUS_PENDING );
     //		}
     //		elseif (  $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH  )
     //		{
     //			$not->setStatus( BatchJob::BATCHJOB_STATUS_FINISHED );
     //		}
     //
     //		// return the notification to the caller
     //		$retrun_notification = ( $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH );
     //
     ////echo "retrun_notification: $retrun_notification<br>";
     //
     //		$not->setPartnerId( $partner_id );
     //		$not->setPuserId( $puser_id );
     //		$not->setDc ( kDataCenterMgr::getCurrentDcId() );
     //		if ( $object_data instanceof BaseObject )
     //		{
     //			$not->setObjectId($object_data->getId() );
     //			$not->setData( self::createNotificationData ( $notification_type , $object_data, $extra_notification_data  ) );
     //
     //			if ( $object_data instanceof entry )
     //			{
     //				if (defined("KALTURA_API_V3"))
     //					$puser_id = $object_data->getKuser()->getPuserId();
     //				else
     //					$puser_id = PuserKuserPeer::getByKuserId( $object_data->getKuserId() , 1 );
     //
     //				$not->setPuserId( $puser_id );
     //
     //			}
     //		}
     //		else
     //		{
     //			// in this case all we have is the object data which is the id
     //			// this is probably the case of some delete and we mifght not have the object in hand but only the id
     //			$not->setObjectId( $object_data );
     //		}
     //		$not->save();
     //		Added by Tan-Tan, Nov 2009 to support the new batches
     //		if (  $nofity_send_type == self::NOTIFICATION_MGR_SEND_ASYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH)
     //		{
     //
     //			// the notification should be in status pending so it will be sent in the
     //			$job->setStatus( BatchJob::BATCHJOB_STATUS_PENDING );
     //		}
     //		else
     $dontSend = false;
     if ($nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH) {
         $dontSend = true;
     }
     // return the notification to the caller
     $retrun_notification = $nofity_send_type == self::NOTIFICATION_MGR_SEND_SYNCH || $nofity_send_type == self::NOTIFICATION_MGR_SEND_BOTH;
     $objectId = null;
     $notificationData = null;
     if ($object_data instanceof BaseObject) {
         $objectId = $object_data->getId();
         $notificationData = self::createNotificationData($notification_type, $object_data, $extra_notification_data);
         if ($object_data instanceof entry) {
             if (kCurrentContext::isApiV3Context()) {
                 $kuser = $object_data->getKuser();
                 if ($kuser) {
                     $puser_id = $kuser->getPuserId();
                 } else {
                     $puser_id = null;
                     KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not find kuser [' . $object_data->getKuserId() . '] from object [' . $object_data->getId() . ']');
                 }
             } else {
                 $puser_id = PuserKuserPeer::getByKuserId($object_data->getKuserId(), 1);
                 // in flatten (or maybe other old batches), KALTURA_API_V3 is not defined, but entry user could have
                 // been created through api v3, in that case there will not be a record in puser_kuser table
                 if (is_null($puser_id)) {
                     $puser_id = $object_data->getPuserId();
                     // if entry was created on PS2 and from some reason puserId is still missing
                     if (is_null($puser_id)) {
                         $kuser = kuserPeer::retrieveByPK($object_data->getKuserId());
                         if ($kuser) {
                             $puser_id = $kuser->getPuserId();
                         }
                     }
                 }
                 if (is_null($puser_id)) {
                     KalturaLog::log(__CLASS__ . '::' . __METHOD__ . ' [line: ' . __LINE__ . '] could not get puser_id out of api_v3 context puserId from entry:[' . $object_data->getPuserId() . '] kuser ID:[' . $object_data->getKuserId() . '] entry:[' . $object_data->getId() . ']');
                 }
             }
         }
     } else {
         // in this case all we have is the object data which is the id
         // this is probably the case of some delete and we mifght not have the object in hand but only the id
         $objectId = $object_data;
     }
     $job = kJobsManager::addNotificationJob(null, $entry_id, $partner_id, $notification_type, $nofity_send_type, $puser_id, $objectId, $notificationData);
     if ($retrun_notification) {
         // return the notification id, notification object , url & the serialized data
         $partner = PartnerPeer::retrieveByPK($partner_id);
         list($url, $signature_key) = self::getPartnerNotificationInfo($partner);
         list($params, $raw_signature) = self::prepareNotificationData($url, $signature_key, $job, $prefix);
         $serialized_params = http_build_query($params, "", "&");
         return array($job->getId(), $job, $url, $params, $serialized_params);
     } else {
         return $job->getId();
     }
 }