示例#1
0
 public function execute_fix_wpw_date_expires()
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $this->output("looking for wikiplace records to fix...\n");
     $cond = 'wpw_date_expires > DATE_ADD(wpw_report_updated,INTERVAL 1 MONTH)';
     $wikiplaces = WpWikiplace::search($cond, true);
     foreach ($wikiplaces as $wikiplace) {
         $subscription = WpSubscription::newFromId($wikiplace->getSubscriptionId());
         $should_ends = WpWikiplace::calculateNextDateExpiresFromSubscription($subscription);
         if ($subscription->isActive() && $subscription->getTmrStatus() == 'OK' && $wikiplace->getDateExpires() != $should_ends) {
             $this->output("wpw_id=" . $wikiplace->getId() . "\tupdated=" . $wikiplace->getReportUpdated() . "\texpires=" . $wikiplace->getDateExpires() . "\n");
             $this->output(" > wps\t\tstarts=" . $subscription->getStart() . "\tends=" . $subscription->getEnd() . "\n");
             $this->output(" > should expire {$should_ends}\n");
             if (!$this->isTest()) {
                 $this->output(" > fixing...\n");
                 $success = $dbw->update('wp_wikiplace', array('wpw_date_expires' => $should_ends), array('wpw_id' => $wikiplace->getId()));
                 if (!$success) {
                     $this->error("Error while updating wikiplace id=" . $wikiplace->getId(), true);
                 }
                 $this->output(" > fixed :)\n");
             }
             $this->output("\n");
         }
     }
     $this->output("end\n");
     $dbw->commit();
 }
 public function execute()
 {
     $when = WpSubscription::now();
     $this->output("[" . WpSubscription::now() . ": Criteria end_date = {$when}]\n");
     $this->output("[" . WpSubscription::now() . ": Searching subscriptions to renew...]\n");
     $subs = WpSubscription::factoryAllOutdatedToRenew($when);
     $this->output("[" . WpSubscription::now() . ": " . count($subs) . " subscription(s) to renew]\n");
     foreach ($subs as $sub) {
         $result = $sub->renew();
         if ($result === true) {
             // renewal OK
             $tmr_status = $sub->getTmrStatus();
             $this->output("wps_id[{$sub->getId()}], renewal OK, wps_wpp_id[{$sub->getPlanId()}], " . ($sub->isActive() ? 'ACTIVE' : 'UNACTIVE') . ", tmr_status = {$tmr_status}\n");
             // renewal OK ==> tmr_status is OK or PE
             if ($tmr_status == 'OK') {
                 $sub->sendOnPlanRenewalOK();
             } else {
                 $sub->sendOnPlanRenewalPE();
             }
         } else {
             // there was a problem
             $this->output("wps_id[{$sub->getId()}], ERROR = {$result}\n");
         }
     }
     $this->output("[" . WpSubscription::now() . ": Deactivating all remaining outdated subscriptions...]\n");
     if (($nb = WpSubscription::deactivateAllOutdated($when)) === false) {
         $this->output("ERROR\n");
     } else {
         $this->output("OK, {$nb} subscription(s) deactivated\n");
     }
     $this->output("[" . WpSubscription::now() . ": END]\n");
 }
 public function execute($par)
 {
     $this->setHeaders();
     // sets robotPolicy = "noindex,nofollow" + set page title
     $user = $this->getUser();
     $output = $this->getOutput();
     $request = $this->getRequest();
     // Check rights and block if necessary
     if (!$this->userCanExecute($user)) {
         // If anon, redirect to login
         if ($user->isAnon()) {
             $output->redirect($this->getTitleFor('UserLogin')->getLocalURL(array('returnto' => $this->getFullTitle())), '401');
             return;
         }
         // Else display an error page.
         $this->displayRestrictionError();
         return;
     }
     if (isset($par) && $par != '') {
         $explosion = explode(':', $par);
         if (count($explosion) == 1) {
             $this->action = $explosion[0];
             $this->category_id = $this->getRequest()->getText('category', null);
         } else {
             if (count($explosion) == 2) {
                 $this->action = $explosion[0];
                 $this->category_id = $explosion[1];
             }
         }
     } else {
         $this->action = $this->getRequest()->getText('action', null);
         $this->category_id = $this->getRequest()->getText('category', null);
     }
     if ($user->isAllowed(WP_ADMIN_RIGHT)) {
         $this->userIsAdmin = true;
         $this->userInvitationsCategories = WpInvitationCategory::factoryAllAvailable(true);
         // with admin categories
     } else {
         $this->userIsAdmin = false;
         $this->userActiveSubscription = WpSubscription::newActiveByUserId($user->getId());
         $this->userInvitationsCategories = WpInvitationCategory::factoryAllAvailable(false);
         // without admin categories
         $this->setUsageThisMonth();
         $this->setUsageLeftThisMonth();
     }
     $this->msgType = $request->getText('msgtype', null);
     $msgKey = $request->getText('msgkey', null);
     if ($msgKey != null) {
         $msg = wfMessage($msgKey);
         if ($msg->exists()) {
             $this->msg = $msg;
         }
     }
     $this->display();
 }
示例#4
0
 public function execute()
 {
     $lifespan = intval($this->getOption('lifespan', 60));
     if ($lifespan < 1) {
         $lifespan = 60;
     }
     $this->output("[" . WpSubscription::now() . ": Updating usages, considering {$lifespan} minutes lifespan...]\n");
     // updates all users'wikiplaces having lifespan expired
     $ok = WpWikiplace::updateOutdatedUsages(null, $lifespan);
     if ($ok === false) {
         $this->output("ERROR: {$ok}\n");
     } else {
         // $this->output("OK: $ok record(s) updated\n");
     }
     // $this->output( "[".WpSubscription::now().": Archiving and resetting monthly usages...]\n" );
     $ok = WpWikiplace::archiveAndResetExpiredUsages();
     if ($ok === false) {
         $this->output("ERROR: {$ok}\n");
     } else {
         // $this->output("OK: $ok record(s) archived and reset\n");
     }
     $this->output("[" . WpSubscription::now() . ": END]\n");
 }
示例#5
0
 /**
  *
  * @param WpSubscription $subscription
  * @return string MySQL DATETIME string format 
  */
 public static function calculateNextDateExpiresFromSubscription($subscription)
 {
     // contains the needed day/hour/minute/second
     $end = date_create_from_format('Y-m-d H:i:s', $subscription->getEnd(), new DateTimeZone('GMT'));
     $now = new DateTime('now', new DateTimeZone('GMT'));
     $expire = date_create_from_format('Y-m-d H:i:s', $now->format('Y-m-') . $end->format('d H:i:s'), new DateTimeZone('GMT'));
     if ($expire < $now) {
         $expire->modify('+1 month');
     }
     return $expire->format('Y-m-d H:i:s');
 }
示例#6
0
 /**
  * Search for a subscription attached to this transaction, and if found, update it.
  * @param array $tmr
  * @return boolean False (=stop hook) only if the transaction is for a subscription.
  */
 public static function onTransactionUpdated($tmr)
 {
     $sub = WpSubscription::newFromTransactionId($tmr['tmr_id']);
     if ($sub === null) {
         return true;
         // we are not concerned, so don't stop processing
     }
     $sub->onTransactionUpdated($tmr);
     return false;
     // the transaction update has been processed, so no other hook should take care of it
 }
 protected function displayList()
 {
     $user = $this->getUser();
     $output = $this->getOutput();
     /**
      *  @Todo BAD, does 2 db query for same results! And uses TP for just 1 line!
      */
     $tp = new WpSubscriptionsTablePager();
     $tp->setSelectConds(array('wps_buyer_user_id' => $this->getUser()->getId()));
     $subs = WpSubscription::newByUserId($user->getId());
     if (!isset($subs)) {
         if ($this->msgKey != null) {
             $tp->setHeader(wfMessage('wp-subscriptionslist-noactive-header')->parse());
         } else {
             $this->action = self::ACTION_NEW;
             $this->display();
             return;
         }
     } elseif ($subs->getTmrStatus() == 'PE') {
         $tp->setHeader(wfMessage('wp-subscriptionslist-pending-header')->parse());
     } elseif (!$subs->isActive()) {
         $tp->setHeader(wfMessage('wp-subscriptionslist-noactive-header')->parse());
     } else {
         $tp->setHeader(wfMessage('wp-subscriptionslist-header')->parse());
         $tp->setFooter(wfMessage('wp-subscriptionslist-footer')->parse());
     }
     $output->addHTML($tp->getWholeHtml());
 }
 /**
  *
  * @return WpInvitationCategory Array of WpInvitationCategory (indexes are categories identifiers)
  */
 public static function factoryAllAvailable($inldudeAdmin = false)
 {
     $dbr = wfGetDB(DB_SLAVE);
     $now = $dbr->addQuotes(WpSubscription::now());
     $conds = array('wpic_start_date <= ' . $now, 'wpic_end_date >= ' . $now);
     if (!$inldudeAdmin) {
         $conds[] = 'wpic_monthly_limit > 0';
     }
     $results = $dbr->select(array('wp_invitation_category', 'wp_wpi_wpp', 'wp_plan'), '*', $conds, __METHOD__, array('ORDER BY' => 'wpic_id'), array('wp_wpi_wpp' => array('LEFT JOIN', 'wpic_id = wpip_wpic_id'), 'wp_plan' => array('LEFT JOIN', 'wpip_wpp_id = wpp_id')));
     return self::factoryFromResults($results);
 }
示例#9
0
 public function displayCreateSubpage()
 {
     $user = $this->getUser();
     $wikiplaces = null;
     if ($this->name != null) {
         $wikiplace = $this->checkWikiPlace($this->name, true);
         if (is_null($wikiplace)) {
             return;
         }
         $wikiplaces = array($wikiplace);
         if (($reason = WpSubscription::userCanCreateNewPage($user, $wikiplace)) !== true) {
             $this->action = self::ACTION_CONSULT_WIKIPLACE;
             $this->msgKey = $reason;
             $this->msgType = 'error';
             $this->display();
             return;
         }
     }
     $wikiplaceSelect = $this->populateWikiPlaceSelect(array('type' => 'select', 'label-message' => 'wp-parent-wikiplace-field', 'section' => 'createpage-section', 'help-message' => 'wp-createpage-wikiplace-help', 'validation-callback' => array($this, 'validateMemberWikiplaceID'), 'options' => array()), $wikiplaces, $this->name);
     if (count($wikiplaceSelect['options']) == 0) {
         $this->action = self::ACTION_LIST_WIKIPLACES;
         $this->msgKey = 'wp-create-wp-first';
         $this->msgType = 'error';
         $this->display();
         return;
     }
     $formDescriptor = array('WpId' => $wikiplaceSelect, 'SpName' => array('type' => 'text', 'label-message' => 'wp-name-field', 'section' => 'createpage-section', 'help-message' => 'wp-createpage-name-help', 'validation-callback' => array($this, 'validateNewSubpageName')), 'Template' => array('label-message' => 'wp-template-field', 'section' => 'createpage-section', 'help-message' => 'wp-createpage-template-help', 'class' => 'WpSubpageTemplate'), 'License' => array('label-message' => 'wp-license-field', 'section' => 'createpage-section', 'help-message' => 'wp-createpage-license-help', 'class' => 'Licenses'), 'CreateTalk' => array('class' => 'HTMLCheckField', 'label-message' => 'wp-createtalk-field', 'section' => 'createpage-section', 'help-message' => 'wp-createpage-createtalk-help', 'default' => true));
     $htmlForm = new HTMLFormS($formDescriptor);
     $htmlForm->addHeaderText(wfMessage('wp-createpage-header')->parse());
     $htmlForm->setMessagePrefix('wp');
     $htmlForm->setTitle($this->getTitleForCurrentRequest());
     $htmlForm->setSubmitCallback(array($this, 'processCreateSubpage'));
     $htmlForm->setSubmitText(wfMessage('wp-create')->text());
     if ($htmlForm->show()) {
         $this->getOutput()->addHTML(wfMessage('wp-create-sp-success', $this->homepageString, $this->subpageString)->parse());
     }
 }
示例#10
0
 /**
  *
  * @param WpInvitationCategory $invitationCategory
  * @param User $fromUser
  * 
  * @param string $code
  * @param string $toEmail
  * @param int $counter
  * @return WpInvitation 
  */
 public static function create($invitationCategory, $fromUser, $code, $toEmail = null, $counter = 1)
 {
     $invitationCategoryId = $invitationCategory->getId();
     $code = strtolower($code);
     $dbw = wfGetDB(DB_MASTER);
     $created = WpSubscription::now();
     $dbw->begin();
     $fromUserId = $fromUser->getId();
     // With PostgreSQL, a value is returned, but null returned for MySQL because of autoincrement system
     $id = $dbw->nextSequenceValue('wp_invitation_wpi_id_seq');
     $success = $dbw->insert('wp_invitation', array('wpi_id' => $id, 'wpi_code' => $code, 'wpi_to_email' => $toEmail, 'wpi_from_user_id' => $fromUserId, 'wpi_date_created' => $created, 'wpi_counter' => $counter, 'wpi_wpic_id' => $invitationCategoryId));
     // Setting id from auto incremented id in DB
     $id = $dbw->insertId();
     $dbw->commit();
     if (!$success) {
         return null;
     }
     return new self($id, $code, $toEmail, $fromUserId, $created, null, $counter, $invitationCategoryId);
 }
示例#11
0
 /**
  * Returns offers, that can be talen as renewal, and will be still accessible at $when, with at least theses quotas
  * @param int $nb_wikiplaces Optional, default = 0
  * @param int $nb_wikiplace_pages  Optional, default = 0
  * @param int $diskspace in MB  Optional, default = 0
  * @param string $when Optional, to ensure that the plan is available at this date, default = now
  * @return array array of WpPlans 
  * @todo also add plan available using an invitation
  */
 public static function factoryAvailableForRenewal($nb_wikiplaces = 0, $nb_wikiplace_pages = 0, $diskspace = 0, $when = null)
 {
     if ($when == null) {
         $when = WpSubscription::now();
     }
     $dbr = wfGetDB(DB_SLAVE);
     $when = $dbr->addQuotes($when);
     $conds = $dbr->makeList(array("wpp_renew_wpp_id" => 0, "wpp_start_date <= {$when}", "wpp_end_date > {$when}", "wpp_invitation_only" => 0, "wpp_nb_wikiplaces >= {$nb_wikiplaces}", "wpp_nb_wikiplace_pages >= {$nb_wikiplace_pages}", "wpp_diskspace >= {$diskspace}"), LIST_AND);
     $result = $dbr->select('wp_plan', '*', $conds, __METHOD__);
     $offers = array();
     foreach ($result as $row) {
         $offers[] = self::constructFromDatabaseRow($row);
     }
     $dbr->freeResult($result);
     return $offers;
 }
示例#12
0
 public function execute()
 {
     $deadline = intval($this->getOption('deadline', 0));
     if ($deadline < 0) {
         $deadline = 0;
     }
     $when = WpSubscription::now(0, 0, 0, $deadline);
     $this->output("[" . WpSubscription::now() . ": Searching subscriptions to renew before {$when} which has not been notified ...]\n");
     $subs = WpSubscription::factoryActiveEndSoonToNotify($when);
     $this->output("[" . WpSubscription::now() . ": " . count($subs) . " subscription(s) to check...]\n");
     foreach ($subs as $sub) {
         $next_plan_id = $sub->getRenewalPlanId();
         $msg = "wps_id[{$sub->getId()}], ";
         if ($next_plan_id == WPP_ID_NORENEW) {
             $msg .= 'do not renew';
             $sub->sendOnNoRenewalSoon();
             $sub->setRenewalPlanNotified();
         } else {
             $msg .= "renew_wpp_id[{$next_plan_id}]: ";
             // a plan is defined has renewal, check if it's a good choice...
             $renewal_date = $sub->getEnd();
             $next_plan = $sub->getRenewalPlan();
             $user_id = $sub->getBuyerUserId();
             if ($next_plan == null) {
                 // should not occur, but ensure database is not corrupted, correct if needed
                 // change to the current plan suggested renewal one
                 $curr_plan = $sub->getPlan();
                 $new_next_plan;
                 if ($curr_plan == null) {
                     // should not occur, but ... just in case
                     $new_next_plan = WpPlan::newFromId(WP_FALLBACK_PLAN_ID);
                 } else {
                     $new_next_plan = $curr_plan->getRenewalPlan($renewal_date);
                 }
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "doesn't exist, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-plan-not-available-renewal', $new_next_plan);
             } elseif (!$next_plan->hasSufficientQuotas(WpWikiplace::countWikiplacesOwnedByUser($user_id), WpPage::countPagesOwnedByUser($user_id), WpPage::countDiskspaceUsageByUser($user_id))) {
                 // change to the current plan suggested renewal one
                 $curr_plan = $sub->getPlan();
                 $new_next_plan = $curr_plan->getRenewalPlan($renewal_date);
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "unsufficient quotas, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-insufficient-quota', $next_plan);
             } elseif (!$next_plan->isAvailableForRenewal($renewal_date)) {
                 // ensure the next plan will still be available
                 // change to the planned renwal plan suggested renewal one
                 $new_next_plan = $next_plan->getRenewalPlan($renewal_date);
                 $new_next_plan_id = $new_next_plan->getId();
                 // update and flag as problem reported, as we will send an email to user
                 $sub->setRenewalPlanId($new_next_plan_id, true);
                 $msg .= "will not be available, changed to = {$new_next_plan_id}";
                 $sub->sendOnRenewalSoonWarning('wp-plan-not-available-renewal', $next_plan);
             } else {
                 // it seems to be ok :)
                 $msg .= 'renewal will be ok';
                 $sub->sendOnRenewalSoonValid();
                 $sub->setRenewalPlanNotified();
             }
         }
         $this->output("{$msg}\n");
     }
     $this->output("[" . WpSubscription::now() . ": END]\n");
 }
 private function subscribeFor($plan_id = null, $user_name = null, $confirm = false)
 {
     $output = $this->getOutput();
     $output->addWikiText("=== Subscribe For ===");
     $this->prettyOutput($output, array('plan' => $plan_id, 'user' => $user_name));
     $output->addWikiText("----");
     if (empty($plan_id) || !is_numeric($plan_id)) {
         $output->addWikiText("=== Specify a plan id in integer format. ===");
         return;
     }
     $plan = WpPlan::newFromId($plan_id);
     if (is_null($plan)) {
         $output->addWikiText("=== No plan with that identifier was found. ===");
         return;
     }
     $output->addWikiText("=== Plan ===");
     $price = $plan->getPrice();
     $this->prettyOutput($output, array('id' => $plan->getId(), 'name' => $plan->getName(), 'period' => $plan->getPeriod() . ' month(s)', 'by invitation only' => $plan->isInvitationRequired() ? 'yes' : 'no', 'price' => $price['amount'] . ' ' . $price['currency']));
     $output->addWikiText("----");
     if (empty($user_name)) {
         $output->addWikiText("=== Specify a user name. ===");
         return;
     }
     $user = User::newFromName($user_name);
     if (!$user || $user->getId() == 0) {
         $output->addWikiText("=== ERROR The user doesn't exist ! ===");
         return;
     }
     $output->addWikiText("=== User to subscribe for ===");
     $this->prettyOutput($output, array('id' => $user->getId(), 'name' => $user->getName(), 'email' => $user->getEmail(), 'email confirmed' => $user->isEmailConfirmed() ? 'yes' : 'no', 'timestamp of account creation' => $user->getRegistration()));
     if (!$user->isEmailConfirmed()) {
         $output->addWikiText("==== WARNING Email is not confirmed ! ====");
     }
     $last_subscription = WpSubscription::newByUserId($user->getId());
     if (is_null($last_subscription)) {
         $output->addWikiText("=== The user doesn't have any subscription. ===");
     } else {
         $output->addWikiText("==== Last subscription ====");
         $this->prettyOutput($output, array('id' => $last_subscription->getId(), 'starts' => $last_subscription->getStart(), 'ends' => $last_subscription->getEnd(), 'active' => $last_subscription->isActive() ? "yes" : "no", 'transaction status' => $last_subscription->getTmrStatus()));
         if ($last_subscription->isActive()) {
             $output->addWikiText("==== ERROR Last subscription is still active ! ====");
             return;
         }
         $lastPlan = $last_subscription->getPlan();
         if (is_null($lastPlan)) {
             $output->addWikiText("=== ERROR The subscribed plan doesn't exist ! ===");
             return;
         }
         $output->addWikiText("==== Subscribed plan ====");
         $price = $lastPlan->getPrice();
         $this->prettyOutput($output, array('id' => $lastPlan->getId(), 'name' => $lastPlan->getName(), 'period' => $lastPlan->getPeriod() . ' month(s)', 'by invitation only' => $lastPlan->isInvitationRequired() ? 'yes' : 'no', 'price' => $price['amount'] . ' ' . $price['currency']));
     }
     $check = WpSubscription::canSubscribe($user);
     if (is_string($check)) {
         $output->addWikiText("=== ERROR The user cannot take a subscription ! ===");
         $output->addWikiText($check);
         return;
     } else {
         $output->addWikiText("=== The user can take a subscription. ===");
     }
     $output->addWikiText("----");
     if ($confirm !== true) {
         $output->addWikiText("=== To confirm ===");
         $output->addHTML($this->getLink(self::ACTION_SUBSCRIBER_FOR, array('plan' => $plan_id, 'user' => $user_name), true));
     } else {
         $subscription = WpSubscription::subscribe($user, $plan);
         if (is_null($subscription)) {
             $output->addWikiText("=== An error occured ! ===");
         } else {
             $output->addWikiText("== Done ! ==");
             $output->addWikiText("==== New subscription ====");
             $this->prettyOutput($output, array('id' => $subscription->getId(), 'buyer user id' => $subscription->getBuyerUserId(), 'starts' => $subscription->getStart(), 'ends' => $subscription->getEnd(), 'active' => $subscription->isActive() ? "yes" : "no", 'transaction status' => $subscription->getTmrStatus()));
         }
     }
 }
示例#14
0
 private function displayOffers()
 {
     # block_join
     $html = Xml::openElement('div', array('class' => 'block block_join'));
     if (is_null(WpSubscription::newActiveByUserId($this->getUser()->getId()))) {
         $blockjoin = array('sz-blockjoin0', 'sz-blockjoin1', 'sz-blockjoin2');
     } else {
         $blockjoin = array('sz-blockjoin0b', 'sz-blockjoin1', 'sz-blockjoin2');
     }
     foreach ($blockjoin as $box) {
         $html .= Xml::openElement('a', array('class' => 'fade', 'href' => wfMessage($box . '-href')->text()));
         $html .= Xml::element('span', array(), wfMessage($box)->text());
         $html .= Html::rawElement('small', array(), wfMessage($box . '-catch')->parse());
         $html .= Xml::closeElement('a');
     }
     # /block_join
     $html .= Xml::closeElement('div');
     return $html;
 }