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'));
 }
Exemple #2
0
     // missing form data
     $tpl->setVariable('error_message', ezpI18n::tr('ezcomments/comment/add/form', 'There is a problem with your comment form '));
     $tpl->setVariable('validation_messages', $formTool->messages());
     $Result['content'] = $tpl->fetch('design:comment/add.tpl');
     return $Result;
 }
 //TODO: from 63, most of the code can be implemented in a class see another TODO in edit.php
 // Build ezcomcomment object
 $comment = ezcomComment::create();
 $formTool->fillObject($comment);
 $comment->setAttribute('contentobject_id', $contentObjectId);
 $languageId = eZContentLanguage::idByLocale($languageCode);
 $comment->setAttribute('language_id', $languageId);
 $sessionKey = $http->getSessionKey();
 $comment->setAttribute('session_key', $sessionKey);
 $util = ezcomUtility::instance();
 $ip = $util->getUserIP();
 $comment->setAttribute('ip', $ip);
 $user = eZUser::currentUser();
 $comment->setAttribute('user_id', $user->attribute('contentobject_id'));
 $currentTime = time();
 $comment->setAttribute('created', $currentTime);
 $comment->setAttribute('modified', $currentTime);
 // toggle notification state on change in state
 // only when notification is enabled, the notification can be changed
 // when email is enabled or email is disabled in setting but user logged in, change notification
 $notification = $formTool->fieldValue('notificationField');
 $email = $comment->attribute('email');
 $changeNotification = false;
 if ($notification === true) {
     // email is enabled in setting
 /**
  * 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__);
     }
 }