public function testActivateSubscription()
 {
     $subscriber = ezcomSubscriber::create();
     $subscriber->setAttribute('email', '*****@*****.**');
     $subscriber->setAttribute('user_id', 10);
     $subscriber->store();
     $subscription = ezcomSubscription::create();
     $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
     $subscription->setAttribute('subscriber_type', 'ezcomcomment');
     $subscription->setAttribute('enabled', 0);
     $subscription->setAttribute('content_id', '10_2');
     $hashString = ezcomUtility::instance()->generateSubscriptionHashString($subscription);
     $subscription->setAttribute('hash_string', $hashString);
     $subscription->store();
     $id = $subscription->attribute('id');
     $tpl = eZTemplate::factory();
     $subscriptionManager = ezcomSubscriptionManager::instance($tpl, null, null, 'ezcomSubscriptionManager');
     $subscriptionManager->activateSubscription($hashString);
     $subscriptionActivated = ezcomSubscription::fetch($id);
     $this->assertEquals(1, $subscriptionActivated->attribute('enabled'));
 }
 /**
  * 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;
 }