Exemplo n.º 1
0
 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");
 }
Exemplo n.º 2
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");
 }
Exemplo n.º 3
0
 /**
  * Reset all usages when outdated
  * @return int/string int:Nb of Wikiplace usages reset if OK, string: the message if an error occured
  */
 public static function archiveAndResetExpiredUsages()
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin();
     $now = $dbw->addQuotes(WpSubscription::now());
     // archiving current usages
     // 3rd arg : must be an associative array of the form
     // array( 'dest1' => 'source1', ...). Source items may be literals
     // rather than field names, but strings should be quoted with
     // DatabaseBase::addQuotes()
     $success = $dbw->insertSelect('wp_old_usage', 'wp_wikiplace', array('wpou_wpw_id' => 'wpw_id', 'wpou_end_date' => $now, 'wpou_monthly_page_hits' => 'wpw_monthly_page_hits', 'wpou_monthly_bandwidth' => 'wpw_monthly_bandwidth'), array('wpw_date_expires < ' . $now), __METHOD__, array('IGNORE'));
     if (!$success) {
         return 'error while renewing archiving outdated usages.';
     }
     // renewing all active outdated records
     $success = $dbw->update('wp_wikiplace', array('wpw_date_expires = DATE_ADD(wpw_date_expires,INTERVAL 1 MONTH)', 'wpw_previous_total_page_hits = (wpw_monthly_page_hits + wpw_previous_total_page_hits)', 'wpw_monthly_page_hits' => 0, 'wpw_monthly_bandwidth' => 0), array('wpw_date_expires < ' . $now));
     if (!$success) {
         return 'error while resetting outdated usages';
     }
     $updated = $dbw->affectedRows();
     $dbw->commit();
     return $updated;
 }
Exemplo n.º 4
0
 /**
  *
  * @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);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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");
 }