/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { require_once dirname(__FILE__) . '/../../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('public', 'prod', true); sfContext::createInstance($configuration); $email = $arguments['email_address']; $password = $arguments['password']; $newUser = PcUserPeer::registerNewUser($email, $password, 'en', 'en', '+01:00,1', 0, false, false); if ($newUser) { $newUser->setAwaitingActivation(0)->save(); $supporter = new PcSupporter(); $supporter->setUserId($newUser->getId())->setExpiryDate(2100000000)->save(); $this->log("The user has been created successfully in the pc_user table. \n You may need to set up the correct timezone in the account settings."); $this->log("The new user can reset their password following the link 'forgotten password' on the Login page."); } else { $this->log("An error occurred - probably the user already exists."); } }
/** * It handles the case in which a user that already used a free trial, * try to get another free trial (that is not allowed) * * It also set the pc_user.has_requested_free_trial field * * @param PcUser $user * @param PcSubscriptionType $subscriptionType * @param bool $isGift (=false) * @param bool $isAutomatic (=false) * @param string $paypalTransactionId (='') * @return bool - false if a user who requested a free trial tries to get it again, true otherwise */ public static function createOrExtendSupporterAccount(PcUser $user, PcSubscriptionType $subscriptionType, $isGift = false, $isAutomatic = false, $paypalTransactionId = '') { if ($subscriptionType->getId() == PcSubscriptionTypePeer::FREE_TRIAL) { if ($user->getHasRequestedFreeTrial()) { return false; } else { $user->setHasRequestedFreeTrial(1)->save(); } } // 3 situations can happen: // 1) the user is not an supporter -> we add the record // 2) the user is still a supporter -> we extend the subscription from the last day of the current subscription // 3) the user used to be a supporter (the record is still in the table) but the subscription has expired -> we // start a new subscription from today $startDate = null; $today = date("Y-m-d"); $c = new Criteria(); $c->add(PcSupporterPeer::USER_ID, $user->getId()); $supporterAccount = PcSupporterPeer::doSelectOne($c); if (!$supporterAccount) { $supporterAccount = new PcSupporter(); $supporterAccount->setUserId($user->getId()); $startDate = $today; } else { $supporterAccountExpiryDate = $supporterAccount->getExpiryDate(); if ($today > $supporterAccountExpiryDate) { $startDate = $today; } else { $startDate = $supporterAccountExpiryDate; } } $newExpiryDateTimestamp = $supporterAccount->getNewExpiryDateAfterSubscription($subscriptionType, $startDate); $supporterAccount->setExpiryDate(date("Y-m-d", $newExpiryDateTimestamp))->save(); // recording the subscription $subscription = new PcSubscription(); $subscription->setUserId($user->getId())->setSubscriptionTypeId($subscriptionType->getId())->setWasGift($isGift)->setWasAutomatic($isAutomatic)->setPaypalTransactionId($paypalTransactionId)->save(); // sending email $email = $user->getEmail(); $from = sfConfig::get('app_emailAddress_contact'); $subject = sfConfig::get('app_subscriptionSuccess_emailSubject'); $body = sfConfig::get('app_subscriptionSuccess_emailBody'); $replyTo = sfConfig::get('app_emailAddress_director'); PcUtils::sendEmail($email, $subject, $body, $from, $replyTo); // creating task in the Inbox $user->addToInbox(__('ACCOUNT_SUBSCRIPTION_INBOX_MESSAGE') . ' ' . $supporterAccount->getExpiryDate('j F Y') . '.'); return true; }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param PcSupporter $value A PcSupporter object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(PcSupporter $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getUserId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Sets a single PcSupporter object as related to this object by a one-to-one relationship. * * @param PcSupporter $l PcSupporter * @return PcUser The current object (for fluent API support) * @throws PropelException */ public function setPcSupporter(PcSupporter $v) { $this->singlePcSupporter = $v; // Make sure that that the passed-in PcSupporter isn't already associated with this object if ($v->getPcUser() === null) { $v->setPcUser($this); } return $this; }