/** * 1. Create a new ezcomNotification object * 2. Check if data are stored properly * */ public function testCreateObject() { $notification = ezcomNotification::create(); $notification->setAttribute('contentobject_id', 12); $notification->setAttribute('language_id', 2); $notification->setAttribute('status', 1); $notification->store(); $this->assertType('ezcomNotification', $notification); $this->assertEquals(12, $notification->attribute('contentobject_id')); $this->assertEquals(2, $notification->attribute('language_id')); $this->assertEquals(1, $notification->attribute('status')); }
/** * clean up subscription after updating comment * @see extension/ezcomments/classes/ezcomCommentManager#afterUpdatingComment($comment, $notified) */ public function afterUpdatingComment($comment, $notified, $time) { $user = eZUser::fetch($comment->attribute('user_id')); // if notified is true, add subscription, else cleanup the subscription on the user and content $contentID = $comment->attribute('contentobject_id'); $languageID = $comment->attribute('language_id'); $subscriptionType = 'ezcomcomment'; if (!is_null($notified)) { $subscriptionManager = ezcomSubscriptionManager::instance(); if ($notified === true) { //add subscription but not send activation try { $subscriptionManager->addSubscription($comment->attribute('email'), $user, $contentID, $languageID, $subscriptionType, $time, false); } catch (Exception $e) { eZDebug::writeError($e->getMessage(), __METHOD__); switch ($e->getCode()) { case ezcomSubscriptionManager::ERROR_SUBSCRIBER_DISABLED: return 'The subscriber is disabled.'; default: return false; } } } else { $subscriptionManager->deleteSubscription($comment->attribute('email'), $comment->attribute('contentobject_id'), $comment->attribute('language_id')); } } //3. update queue. If there is subscription, add one record into queue table // if there is subcription on this content, add one item into queue if (ezcomSubscription::exists($contentID, $languageID, $subscriptionType)) { $notification = ezcomNotification::create(); $notification->setAttribute('contentobject_id', $comment->attribute('contentobject_id')); $notification->setAttribute('language_id', $comment->attribute('language_id')); $notification->setAttribute('comment_id', $comment->attribute('id')); $notification->store(); eZDebugSetting::writeNotice('extension-ezcomments', 'There are subscriptions, added an update notification to the queue.', __METHOD__); } else { // todo: if there is no subscription on this content, consider to clean up the queue } return true; }