public function validateRenewPlanId($id, $allData)
 {
     if (!preg_match('/^[0-9]{1,10}$/', $id)) {
         return 'Error: Invalid Renewal Plan ID';
     }
     if ($id == WPP_ID_NORENEW) {
         return true;
         // "no next plan"
     }
     $plan = WpPlan::newFromId($id);
     if ($plan == null) {
         return 'Error: Invalid Plan ID';
     }
     $user_id = $this->getUser()->getId();
     $curr_sub = WpSubscription::newActiveByUserId($user_id);
     if ($curr_sub == null) {
         return 'Error: No Active Subscription';
     }
     if (!$plan->isAvailableForRenewal($curr_sub->getEnd())) {
         return 'Error: Plan Not Available For Renewal';
     }
     if (!$plan->hasSufficientQuotas(WpWikiplace::countWikiplacesOwnedByUser($user_id), WpPage::countPagesOwnedByUser($user_id), WpPage::countDiskspaceUsageByUser($user_id))) {
         return 'Error: Plan Quotas Unsufficients';
     }
     return true;
 }
 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 displayList()
 {
     $user = $this->getUser();
     if ($user->isAllowed(WP_ADMIN_RIGHT) && $this->name != null) {
         $user_id = User::newFromName($this->name)->getId();
         if ($user_id == 0) {
             $this->action = self::ACTION_NOACTION;
             $this->msgKey = 'wp-invalid-name';
             $this->msgType = 'error';
             $this->display();
             return;
         }
     } else {
         $user_id = $user->getId();
     }
     $output = $this->getOutput();
     $tp = new WpWikiplacesTablePager();
     $tp->setSelectConds(array('wpw_owner_user_id' => $user_id));
     $tp->setHeader(wfMessage('wp-list-header')->parse());
     $diskspace = wfFormatSizeMB(WpPage::countDiskspaceUsageByUser($user_id));
     $pages = wfFormatNumber(WpPage::countPagesOwnedByUser($user_id));
     $tp->setFooter(wfMessage('wp-list-footer', $diskspace, $pages)->parse());
     /** @TODO Add Total Hits, Total Bandwidth & Report Updated, ie. Make pretty getters and factories in WpWikiplace that can take the result/row from the pager as argument */
     $output->addHTML($tp->getWholeHtml());
 }
Example #4
0
 /**
  * Checks subscription is active, page creation quota is not exceeded and
  * diskpace quota is not exceeded.
  * @param int $current_user_id The current user identifier (used to select i18n message)
  * @param int|WpWikiplace $wikiplace An instance of WpWikiplace (faster) or the wikiplace id (int), checks the
  * subscriptions associated to the wikiplace and the quotas of the subscription buyer.
  * @return boolean/string True if user can, or string message explaining why she can't
  * <ul>
  * <li><b>wp-no-active-sub</b> you have no active subscription</li>
  * <li><b>wp-wikiplace-no-active-sub</b> wikiplace has no active subscription associated</li>
  * <li><b>wp-page-quota-exceeded</b> your page quota exceeded</li>
  * <li><b>wp-wikiplace-page-quota-exceeded</b> the subscriber page quota exceeded</li>
  * <li><b>wp-diskspace-quota-exceeded</b> your diskspace quota exceeded</li>
  * <li><b>wp-wikiplace-diskspace-quota-exceeded</b> the subscriber diskspace quota exceeded</li>
  * </ul>
  */
 public static function userCanUploadNewFile($current_user_id, $wikiplace)
 {
     if (is_int($wikiplace)) {
         $wikiplace = WpWikiplace::getById($wikiplace);
     }
     if (!$wikiplace instanceof WpWikiplace) {
         throw new MWException('Invalid $wikiplace argument.');
     }
     $subscription = self::newFromId($wikiplace->getSubscriptionId());
     if (!$subscription instanceof WpSubscription) {
         return 'wp-wikiplace-no-active-sub';
         // "THE OWNER subscription ..."
     } else {
         if (!$subscription->isActive()) {
             if ($wikiplace->isOwner($current_user_id)) {
                 return 'wp-no-active-sub';
                 // "YOUR subscription ..."
             } else {
                 return 'wp-wikiplace-no-active-sub';
                 // "THE OWNER subscription ..."
             }
         }
     }
     if (!$wikiplace->isOwner($current_user_id) && !WpMember::IsMember($wikiplace, $current_user_id)) {
         return 'wp-not-owner-or-member';
     }
     $plan = $subscription->getPlan();
     $max_pages = $plan->getNbWikiplacePages();
     $owner_pages_nb = WpPage::countPagesOwnedByUser($wikiplace->getOwnerUserId());
     if ($owner_pages_nb >= $max_pages) {
         if ($wikiplace->isOwner($current_user_id)) {
             return 'wp-page-quota-exceeded';
             // "YOUR quota..."
         } else {
             return 'wp-wikiplace-page-quota-exceeded';
             // "THE OWNER quota ..."
         }
     }
     $max_diskspace = $plan->getDiskspace();
     $owner_diskspace_usage = WpPage::countDiskspaceUsageByUser($wikiplace->getOwnerUserId());
     if ($owner_diskspace_usage >= $max_diskspace) {
         if ($wikiplace->isOwner($current_user_id)) {
             return 'wp-diskspace-quota-exceeded';
             // "YOUR quota..."
         } else {
             return 'wp-wikiplace-diskspace-quota-exceeded';
             // "THE OWNER quota ..."
         }
     }
     return true;
 }