コード例 #1
0
 public function testParseLocalTime()
 {
     $u = new PhabricatorUser();
     $u->setTimezoneIdentifier('UTC');
     $v = new PhabricatorUser();
     $v->setTimezoneIdentifier('America/Los_Angeles');
     $t = 1370202281;
     // 2013-06-02 12:44:41 -0700
     $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $u));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $v));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $u));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $v));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $u));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $v));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 19:44:41', $u));
     $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41', $v));
     $this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $u));
     $this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $v));
     unset($time);
     $t = 1370239200;
     // 2013-06-02 23:00:00 -0700
     $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
     // For the UTC user, midnight was 6 hours ago because it's early in the
     // morning for htem. For the PDT user, midnight was 23 hours ago.
     $this->assertEqual($t + -6 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $u));
     $this->assertEqual($t + -23 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $v));
     unset($time);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $subscription_phid = $args->getArg('subscription');
     if (!$subscription_phid) {
         throw new PhutilArgumentUsageException(pht('Specify which subscription to invoice with %s.', '--subscription'));
     }
     $subscription = id(new PhortuneSubscriptionQuery())->setViewer($viewer)->withPHIDs(array($subscription_phid))->needTriggers(true)->executeOne();
     if (!$subscription) {
         throw new PhutilArgumentUsageException(pht('Unable to load subscription with PHID "%s".', $subscription_phid));
     }
     $now = $args->getArg('now');
     $now = $this->parseTimeArgument($now);
     if (!$now) {
         $now = PhabricatorTime::getNow();
     }
     $time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());
     $console->writeOut("%s\n", pht('Set current time to %s.', phabricator_datetime(PhabricatorTime::getNow(), $viewer)));
     $auto_range = $args->getArg('auto-range');
     $last_arg = $args->getArg('last');
     $next_arg = $args->getARg('next');
     if (!$auto_range && !$last_arg && !$next_arg) {
         throw new PhutilArgumentUsageException(pht('Specify a billing range with %s and %s, or use %s.', '--last', '--next', '--auto-range'));
     } else {
         if (!$auto_range & (!$last_arg || !$next_arg)) {
             throw new PhutilArgumentUsageException(pht('When specifying %s or %s, you must specify both arguments ' . 'to define the beginning and end of the billing range.', '--last', '--next'));
         } else {
             if (!$auto_range && ($last_arg && $next_arg)) {
                 $last_time = $this->parseTimeArgument($args->getArg('last'));
                 $next_time = $this->parseTimeArgument($args->getArg('next'));
             } else {
                 if ($auto_range && ($last_arg || $next_arg)) {
                     throw new PhutilArgumentUsageException(pht('Use either %s or %s and %s to specify the ' . 'billing range, but not both.', '--auto-range', '--last', '--next'));
                 } else {
                     $trigger = $subscription->getTrigger();
                     $event = $trigger->getEvent();
                     if (!$event) {
                         throw new PhutilArgumentUsageException(pht('Unable to calculate %s, this subscription has not been ' . 'scheduled for billing yet. Wait for the trigger daemon to ' . 'schedule the subscription.', '--auto-range'));
                     }
                     $last_time = $event->getLastEventEpoch();
                     $next_time = $event->getNextEventEpoch();
                 }
             }
         }
     }
     $console->writeOut("%s\n", pht('Preparing to invoice subscription "%s" from %s to %s.', $subscription->getSubscriptionName(), $last_time ? phabricator_datetime($last_time, $viewer) : pht('subscription creation'), phabricator_datetime($next_time, $viewer)));
     PhabricatorWorker::setRunAllTasksInProcess(true);
     if (!$args->getArg('force')) {
         $console->writeOut("**<bg:yellow> %s </bg>**\n%s\n", pht('WARNING'), phutil_console_wrap(pht('Manually invoicing will double bill payment accounts if the ' . 'range overlaps an existing or future invoice. This script is ' . 'intended for testing and development, and should not be part ' . 'of routine billing operations. If you continue, you may ' . 'incorrectly overcharge customers.')));
         if (!phutil_console_confirm(pht('Really invoice this subscription?'))) {
             throw new Exception(pht('Declining to invoice.'));
         }
     }
     PhabricatorWorker::scheduleTask('PhortuneSubscriptionWorker', array('subscriptionPHID' => $subscription->getPHID(), 'trigger.last-epoch' => $last_time, 'trigger.this-epoch' => $next_time, 'manual' => true), array('objectPHID' => $subscription->getPHID()));
     return 0;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $triggers = $this->loadTriggers($args);
     $now = $args->getArg('now');
     $now = $this->parseTimeArgument($now);
     if (!$now) {
         $now = PhabricatorTime::getNow();
     }
     $time_guard = PhabricatorTime::pushTime($now, date_default_timezone_get());
     $console->writeOut("%s\n", pht('Set current time to %s.', phabricator_datetime(PhabricatorTime::getNow(), $viewer)));
     $last_time = $this->parseTimeArgument($args->getArg('last'));
     $next_time = $this->parseTimeArgument($args->getArg('next'));
     PhabricatorWorker::setRunAllTasksInProcess(true);
     foreach ($triggers as $trigger) {
         $console->writeOut("%s\n", pht('Executing trigger %s.', $this->describeTrigger($trigger)));
         $event = $trigger->getEvent();
         if ($event) {
             if (!$last_time) {
                 $last_time = $event->getLastEventEpoch();
             }
             if (!$next_time) {
                 $next_time = $event->getNextEventEpoch();
             }
         }
         if (!$next_time) {
             $console->writeOut("%s\n", pht('Trigger is not scheduled to execute. Use --next to simluate ' . 'a scheduled event.'));
             continue;
         } else {
             $console->writeOut("%s\n", pht('Executing event as though it was scheduled to execute at %s.', phabricator_datetime($next_time, $viewer)));
         }
         if (!$last_time) {
             $console->writeOut("%s\n", pht('Executing event as though it never previously executed.'));
         } else {
             $console->writeOut("%s\n", pht('Executing event as though it previously executed at %s.', phabricator_datetime($last_time, $viewer)));
         }
         $trigger->executeTrigger($last_time, $next_time);
         $reschedule_time = $trigger->getNextEventEpoch($next_time, $is_reschedule = true);
         if (!$reschedule_time) {
             $console->writeOut("%s\n", pht('After executing under these conditions, this event would never ' . 'execute again.'));
         } else {
             $console->writeOut("%s\n", pht('After executing under these conditions, this event would ' . 'next execute at %s.', phabricator_datetime($reschedule_time, $viewer)));
         }
     }
     return 0;
 }
コード例 #4
0
 public function testCustomPolicyRuleLunarPhase()
 {
     $user_a = $this->generateNewTestUser();
     $author = $this->generateNewTestUser();
     $policy = id(new PhabricatorPolicy())->setRules(array(array('action' => PhabricatorPolicy::ACTION_ALLOW, 'rule' => 'PhabricatorLunarPhasePolicyRule', 'value' => 'new')))->save();
     $task = ManiphestTask::initializeNewTask($author);
     $task->setViewPolicy($policy->getPHID());
     $task->save();
     $time_a = PhabricatorTime::pushTime(934354800, 'UTC');
     $can_a_view = PhabricatorPolicyFilter::hasCapability($user_a, $task, PhabricatorPolicyCapability::CAN_VIEW);
     $this->assertTrue($can_a_view);
     unset($time_a);
     $time_b = PhabricatorTime::pushTime(1116745200, 'UTC');
     $can_a_view = PhabricatorPolicyFilter::hasCapability($user_a, $task, PhabricatorPolicyCapability::CAN_VIEW);
     $this->assertFalse($can_a_view);
     unset($time_b);
 }
コード例 #5
0
 public function testTimestampsStartDay()
 {
     $u = new PhabricatorUser();
     $u->setTimezoneIdentifier('America/Los_Angeles');
     $days = $this->getAllDays();
     foreach ($days as $day) {
         $data = CalendarTimeUtil::getTimestamps($u, $day, 1);
         $this->assertEqual($day, $data['epoch_stamps'][0]->format('l'));
     }
     $t = 1370202281;
     // 2013-06-02 12:44:41 -0700 -- a Sunday
     $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
     foreach ($days as $day) {
         $data = CalendarTimeUtil::getTimestamps($u, $day, 1);
         $this->assertEqual($day, $data['epoch_stamps'][0]->format('l'));
     }
     unset($time);
 }