public function testSendEmailNotification()
 {
     $notification = new SystemNotification();
     $notification->Title = "Notify on event";
     $notification->Description = 'Notifies on an event occurring';
     $notification->NotificationText = 'This is a notfication to $Member.Email about $NotifyOnThis.Title';
     $notification->Identifier = 'NOTIFY_ON_EVENT';
     $notification->NotifyOnClass = 'NotifyOnThis';
     $notification->write();
     // okay, add it to our page
     $page = $this->objFromFixture('NotifyOnThis', 'not1');
     $ns = new NotificationService();
     Config::inst()->update('NotificationService', 'use_queues', false);
     Config::inst()->update('EmailNotificationSender', 'send_notifications_from', '*****@*****.**');
     Config::inst()->update('SystemNotification', 'default_template', false);
     $ns->setSenders(array('email' => 'EmailNotificationSender'));
     $ns->setChannels(array('email'));
     $ns->notify('NOTIFY_ON_EVENT', $page);
     // now check that there was an email sent
     $users = $page->getRecipients($notification->Identifier);
     $expectedTo = $users[0]->Email;
     $expectedFrom = '*****@*****.**';
     $expectedSubject = $notification->Title;
     $expectedBody = "This is a notfication to {$expectedTo} about {$page->Title}";
     $expectedBody = $notification->format(nl2br($expectedBody), $page);
     // TODO
     $this->assertEmailSent($expectedTo, $expectedFrom, $expectedSubject);
 }
コード例 #2
0
 public static function getByID($snID)
 {
     $db = Loader::db();
     $row = $db->GetRow('select * from SystemNotifications where snID = ?', array($snID));
     if (is_array($row) && $row['snID']) {
         $sn = new SystemNotification();
         $sn->setPropertiesFromArray($row);
         return $sn;
     }
 }
 /**
  * Send a notification directly to a single user
  *
  * @param SystemNotification $notification
  * @param string $email
  * @param array $data
  */
 public function sendToUser($notification, $context, $user, $data)
 {
     $subject = $notification->format($notification->Title, $context, $user, $data);
     if (Config::inst()->get('SystemNotification', 'html_notifications')) {
         $message = $notification->format($notification->NotificationContent(), $context, $user, $data);
     } else {
         $message = $notification->format(nl2br($notification->NotificationContent()), $context, $user, $data);
     }
     if ($template = $notification->getTemplate()) {
         $templateData = $notification->getTemplateData($context, $user, $data);
         $templateData->setField('Body', $message);
         try {
             $body = $templateData->renderWith($template);
         } catch (Exception $e) {
             $body = $message;
         }
     } else {
         $body = $message;
     }
     $from = $this->config()->get('send_notifications_from');
     $to = $user->Email;
     if (!$to && method_exists($user, 'getEmailAddress')) {
         $to = $user->getEmailAddress();
     }
     // log
     $message = "Sending {$subject} to {$to}";
     SS_Log::log($message, SS_Log::NOTICE);
     // send
     $email = new Email($from, $to, $subject);
     $email->setBody($body);
     $this->extend('onBeforeSendToUser', $email);
     $email->send();
 }
コード例 #4
0
ファイル: update.php プロジェクト: rii-J/concrete5-de
	public function getLatestAvailableVersionNumber() {
		if (defined('MULTI_SITE') && MULTI_SITE == 1) {
			$updates = Update::getLocalAvailableUpdates();
			$multiSiteVersion = 0;
			foreach($updates as $up) {
				if (version_compare($up->getUpdateVersion(), $multiSiteVersion, '>')) {
					$multiSiteVersion = $up->getUpdateVersion();
				}	
			}
			Config::save('APP_VERSION_LATEST', $multiSiteVersion);
			return $multiSiteVersion;
		}
		
		$d = Loader::helper('date');
		// first, we check session
		$queryWS = false;
		Cache::disableCache();
		$vNum = Config::get('APP_VERSION_LATEST', true);
		Cache::enableCache();
		if (is_object($vNum)) {
			$seconds = strtotime($vNum->timestamp);
			$version = $vNum->value;
			if (is_object($version)) {
				$versionNum = $version->version;
			} else {
				$versionNum = $version;
			}
			$diff = time() - $seconds;
			if ($diff > APP_VERSION_LATEST_THRESHOLD) {
				// we grab a new value from the service
				$queryWS = true;
			}
		} else {
			$queryWS = true;
		}
		
		if ($queryWS) {
			Loader::library('marketplace');
			$mi = Marketplace::getInstance();
			if ($mi->isConnected()) {
				Marketplace::checkPackageUpdates();
			}
			$update = Update::getLatestAvailableUpdate();
			$versionNum = $update->version;
			
			if ($versionNum) {
				Config::save('APP_VERSION_LATEST', $versionNum);
				if (version_compare($versionNum, APP_VERSION, '>')) {
					Loader::model('system_notification');
					SystemNotification::add(SystemNotification::SN_TYPE_CORE_UPDATE, t('A new version of concrete5 is now available.'), '', $update->notes, View::url('/dashboard/system/update'));
				}		
			} else {
				// we don't know so we're going to assume we're it
				Config::save('APP_VERSION_LATEST', APP_VERSION);
			}
		}
		
		return $versionNum;
	}
コード例 #5
0
	public function get($itemsToGet = 0, $offset = 0) {
		$r = parent::get($itemsToGet, $offset);
		$posts = array();
		foreach($r as $row) {
			$sn = SystemNotification::getByID($row['snID']);
			if (is_object($sn)) {
				$posts[] = $sn;
			}
		}
		return $posts;
	}
 /**
  * Send out a notification
  *
  * @param SystemNotification $notification
  *				The configured notification object
  * @param DataObject $context
  *				The context of the notification to send
  * @param array $extraData
  *				Any extra data to add into the notification text
  * @param string $channel
  *				A specific channel to send through. If not set, just sends to the default configured
  */
 public function sendNotification(SystemNotification $notification, DataObject $context, $extraData = array(), $channel = null)
 {
     // check to make sure that there are users to send it to. If not, we don't bother with it at all
     $recipients = $notification->getRecipients($context);
     if (!count($recipients)) {
         return;
     }
     // if we've got queues and a large number of recipients, lets send via a queued job instead
     if ($this->config()->get('use_queues') && count($recipients) > 5) {
         $extraData['SEND_CHANNEL'] = $channel;
         singleton('QueuedJobService')->queueJob(new SendNotificationJob($notification, $context, $extraData));
     } else {
         $channels = $channel ? array($channel) : $this->channels;
         foreach ($channels as $channel) {
             if ($sender = $this->getSender($channel)) {
                 $sender->sendNotification($notification, $context, $extraData);
             }
         }
     }
 }
コード例 #7
0
 /** 
  * Runs through all packages on the marketplace, sees if they're installed here, and updates the available version number for them
  */
 public static function checkPackageUpdates()
 {
     Loader::model('system_notification');
     $items = Marketplace::getAvailableMarketplaceItems(false);
     foreach ($items as $i) {
         $p = Package::getByHandle($i->getHandle());
         if (is_object($p)) {
             // we only add a notification if it's newer than the last one we know about
             if (version_compare($p->getPackageVersionUpdateAvailable(), $i->getVersion(), '<') && version_compare($p->getPackageVersion(), $i->getVersion(), '<')) {
                 SystemNotification::add(SystemNotification::SN_TYPE_ADDON_UPDATE, t('An updated version of %s is available.', $i->getName()), t('New Version: %s.', $i->getVersion()), '', View::url('/dashboard/extend/update'), $i->getRemoteURL());
             }
             $p->updateAvailableVersionNumber($i->getVersion());
         }
     }
 }
コード例 #8
0
 public function getNotification()
 {
     return SystemNotification::get()->byID($this->notificationID);
 }
コード例 #9
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
Loader::dashboardModuleController('help');
Loader::dashboardModuleController('news');
Loader::model('system_notification');
// latest version, including addon updates
Loader::library('update');
$lv = Update::getLatestAvailableVersionNumber();
$fp = Loader::helper("feed");
$feed = $fp->load(HelpDashboardModuleController::FEED);
$feed->set_timeout(3);
$posts = $feed->get_items(0, 5);
foreach ($posts as $p) {
    SystemNotification::addFromFeed($p, SystemNotification::SN_TYPE_CORE_MESSAGE_HELP);
}
$feed = $fp->load(NewsDashboardModuleController::FEED);
$feed->set_timeout(3);
$posts = $feed->get_items(0, 5);
foreach ($posts as $p) {
    SystemNotification::addFromFeed($p, SystemNotification::SN_TYPE_CORE_MESSAGE_NEWS);
}