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()); }
/** * Check the user has an active subscription and * wikiplace creation quota is not exceeded and * page creation quota is not exceeded * @param type $user_id * @return boolean/string True if user can, string message explaining why she can't: * <ul> * <li><b>wp-no-active-sub</b> user has no active subscription</li> * <li><b>wp-wikiplace-quota-exceeded</b> wikiplace creation quota exceeded</li> * <li><b>wp-page-quota-exceeded</b> page creation quota exceeded</li> * </ul> */ public static function userCanCreateWikiplace($user_id) { if (!is_int($user_id) || $user_id < 1) { throw new MWException('Cannot check if user can create a Wikiplace, invalid user identifier.'); } $sub = self::newActiveByUserId($user_id); if ($sub == null) { return 'wp-no-active-sub'; } $plan = $sub->getPlan(); $max_wikiplaces = $plan->getNbWikiplaces(); $user_wikiplaces_nb = WpWikiplace::countWikiplacesOwnedByUser($user_id); if ($user_wikiplaces_nb >= $max_wikiplaces) { return 'wp-wikiplace-quota-exceeded'; } $max_pages = $plan->getNbWikiplacePages(); $user_pages_nb = WpPage::countPagesOwnedByUser($user_id); if ($user_pages_nb >= $max_pages) { return 'wp-page-quota-exceeded'; } return true; // all ok }