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;
 }
<?php

/**
 * File containing php script for cleaning up the expired non-activated subscription
 *
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
 * @license For full copyright and license information view LICENSE file distributed with this source code.
 *
 */
/**
 * clean up the subscription expired
 */
if (!$isQuiet) {
    $cli->output("Start cleaning up the subscription...");
}
$ezcommentsINI = eZINI::instance('ezcomments.ini');
$expiryDays = $ezcommentsINI->variable('NotificationSettings', 'DaysToCleanupSubscription');
$time = -1;
if ($expiryDays != '-1') {
    $time = 60 * 60 * 24 * (double) $expiryDays;
}
$result = ezcomSubscriptionManager::cleanupExpiredSubscription($time);
if (!is_null($result)) {
    if (!$isQuiet) {
        $cli->output(count($result) . " subscription have been cleaned up!");
    }
} else {
    if (!$isQuiet) {
        $cli->output("No subscription has been cleaned up!");
    }
}
 /**
  * Add an subscription. If the subscriber is disabled, throw an exception
  * If there is no subscriber, add one.
  * If there is no subscription for the content, add one
  * @param $email: user's email
  * @return void
  */
 public function addSubscription($email, $user, $contentID, $languageID, $subscriptionType, $currentTime, $activate = true)
 {
     //1. insert into subscriber
     $ezcommentsINI = eZINI::instance('ezcomments.ini');
     $subscriber = ezcomSubscriber::fetchByEmail($email);
     //if there is no data in subscriber for same email, save it
     if (is_null($subscriber)) {
         $subscriber = ezcomSubscriber::create();
         $subscriber->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscriber->setAttribute('email', $email);
         if ($user->isAnonymous()) {
             $util = ezcomUtility::instance();
             $hashString = $util->generateSusbcriberHashString($subscriber);
             $subscriber->setAttribute('hash_string', $hashString);
         }
         $subscriber->store();
         eZDebugSetting::writeNotice('extension-ezcomments', 'Subscriber does not exist, added one', __METHOD__);
         $subscriber = ezcomSubscriber::fetchByEmail($email);
     } else {
         if ($subscriber->attribute('enabled') == false) {
             throw new Exception('Subscription can not be added because the subscriber is disabled.', self::ERROR_SUBSCRIBER_DISABLED);
         }
     }
     //3 insert into subscription table
     // if there is no data in ezcomment_subscription with given contentobject_id and subscriber_id
     $hasSubscription = ezcomSubscription::exists($contentID, $languageID, $subscriptionType, $email);
     if ($hasSubscription === false) {
         $subscription = ezcomSubscription::create();
         $subscription->setAttribute('user_id', $user->attribute('contentobject_id'));
         $subscription->setAttribute('subscriber_id', $subscriber->attribute('id'));
         $subscription->setAttribute('subscription_type', $subscriptionType);
         $subscription->setAttribute('content_id', $contentID);
         $subscription->setAttribute('language_id', $languageID);
         $subscription->setAttribute('subscription_time', $currentTime);
         $defaultActivated = $ezcommentsINI->variable('CommentSettings', 'SubscriptionActivated');
         if ($user->isAnonymous() && $defaultActivated !== 'true' && $activate === true) {
             $subscription->setAttribute('enabled', 0);
             $utility = ezcomUtility::instance();
             $subscription->setAttribute('hash_string', $utility->generateSubscriptionHashString($subscription));
             $subscription->store();
             $result = ezcomSubscriptionManager::sendActivationEmail(eZContentObject::fetch($contentID), $subscriber, $subscription);
             if (!$result) {
                 eZDebug::writeError("Error sending mail to '{$email}'", __METHOD__);
             }
         } else {
             $subscription->setAttribute('enabled', 1);
             $subscription->store();
         }
         eZDebugSetting::writeNotice('extension-ezcomments', 'No existing subscription for this content and user, added one', __METHOD__);
     }
 }
Example #5
0
<?php

/**
 * File containing logic of activate view
 *
 * @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/gnu_gpl GNU General Public License v2.0
 *
 */
$tpl = eZTemplate::factory();
$module = $Params['Module'];
if ($module->isCurrentAction('Redirect')) {
    $http = eZHTTPTool::instance();
    $redirectURI = $http->variable('RedirectURI');
    $module->redirectTo($redirectURI);
} else {
    $hashString = trim($Params['HashString']);
    $subscriptionManager = new ezcomSubscriptionManager($tpl, $Params, $module);
    $subscriptionManager->activateSubscription($hashString);
    $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezcomments/comment/activate', 'Activate subscription')));
    $Result['content'] = $tpl->fetch('design:comment/activate.tpl');
    return $Result;
}