protected function renderResultList(array $countdowns, PhabricatorSavedQuery $query, array $handles)
 {
     assert_instances_of($countdowns, 'PhabricatorCountdown');
     $viewer = $this->requireViewer();
     $list = new PHUIObjectItemListView();
     $list->setUser($viewer);
     foreach ($countdowns as $countdown) {
         $id = $countdown->getID();
         $ended = false;
         $epoch = $countdown->getEpoch();
         if ($epoch <= PhabricatorTime::getNow()) {
             $ended = true;
         }
         $item = id(new PHUIObjectItemView())->setUser($viewer)->setObject($countdown)->setObjectName("C{$id}")->setHeader($countdown->getTitle())->setHref($this->getApplicationURI("{$id}/"))->addByline(pht('Created by %s', $handles[$countdown->getAuthorPHID()]->renderLink()));
         if ($ended) {
             $item->addAttribute(pht('Launched on %s', phabricator_datetime($epoch, $viewer)));
             $item->setDisabled(true);
         } else {
             $time_left = $epoch - PhabricatorTime::getNow();
             $num = round($time_left / (60 * 60 * 24));
             $noun = pht('Days');
             if ($num < 1) {
                 $num = round($time_left / (60 * 60), 1);
                 $noun = pht('Hours');
             }
             $item->setCountdown($num, $noun);
             $item->addAttribute(phabricator_datetime($epoch, $viewer));
         }
         $list->addItem($item);
     }
     $result = new PhabricatorApplicationSearchResultView();
     $result->setObjectList($list);
     $result->setNoDataString(pht('No countdowns found.'));
     return $result;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $since = PhabricatorTime::getNow() - phutil_units('30 days in seconds');
     $until = PhabricatorTime::getNow();
     $mails = id(new PhabricatorMetaMTAMailQuery())->setViewer($viewer)->withDateCreatedBetween($since, $until)->execute();
     $unfiltered = array();
     foreach ($mails as $mail) {
         $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
         foreach ($unfiltered_actors as $phid) {
             if (empty($unfiltered[$phid])) {
                 $unfiltered[$phid] = 0;
             }
             $unfiltered[$phid]++;
         }
     }
     arsort($unfiltered);
     $table = id(new PhutilConsoleTable())->setBorders(true)->addColumn('user', array('title' => pht('User')))->addColumn('unfiltered', array('title' => pht('Unfiltered')));
     $handles = $viewer->loadHandles(array_keys($unfiltered));
     $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
     foreach ($unfiltered as $phid => $count) {
         $table->addRow(array('user' => idx($names, $phid), 'unfiltered' => $count));
     }
     $table->draw();
     echo "\n";
     echo pht('Mail sent in the last 30 days.') . "\n";
     echo pht('"Unfiltered" is raw volume before preferences were applied.') . "\n";
     echo "\n";
     return 0;
 }
 protected function loadTasks(PhutilArgumentParser $args)
 {
     $ids = $args->getArg('id');
     $class = $args->getArg('class');
     $min_failures = $args->getArg('min-failure-count');
     if (!$ids && !$class && !$min_failures) {
         throw new PhutilArgumentUsageException(pht('Use --id, --class, or --min-failure-count to select tasks.'));
     }
     $active_query = new PhabricatorWorkerActiveTaskQuery();
     $archive_query = new PhabricatorWorkerArchiveTaskQuery();
     if ($ids) {
         $active_query = $active_query->withIDs($ids);
         $archive_query = $archive_query->withIDs($ids);
     }
     if ($class) {
         $class_array = array($class);
         $active_query = $active_query->withClassNames($class_array);
         $archive_query = $archive_query->withClassNames($class_array);
     }
     if ($min_failures) {
         $active_query = $active_query->withFailureCountBetween($min_failures, null);
         $archive_query = $archive_query->withFailureCountBetween($min_failures, null);
     }
     $active_tasks = $active_query->execute();
     $archive_tasks = $archive_query->execute();
     $tasks = mpull($active_tasks, null, 'getID') + mpull($archive_tasks, null, 'getID');
     if ($ids) {
         foreach ($ids as $id) {
             if (empty($tasks[$id])) {
                 throw new PhutilArgumentUsageException(pht('No task exists with id "%s"!', $id));
             }
         }
     }
     if ($class && $min_failures) {
         if (!$tasks) {
             throw new PhutilArgumentUsageException(pht('No task exists with class "%s" and at least %d failures!', $class, $min_failures));
         }
     } else {
         if ($class) {
             if (!$tasks) {
                 throw new PhutilArgumentUsageException(pht('No task exists with class "%s"!', $class));
             }
         } else {
             if ($min_failures) {
                 if (!$tasks) {
                     throw new PhutilArgumentUsageException(pht('No tasks exist with at least %d failures!', $min_failures));
                 }
             }
         }
     }
     // When we lock tasks properly, this gets populated as a side effect. Just
     // fake it when doing manual CLI stuff. This makes sure CLI yields have
     // their expires times set properly.
     foreach ($tasks as $task) {
         if ($task instanceof PhabricatorWorkerActiveTask) {
             $task->setServerTime(PhabricatorTime::getNow());
         }
     }
     return $tasks;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $countdown = id(new PhabricatorCountdownQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$countdown) {
         return new Aphront404Response();
     }
     $countdown_view = id(new PhabricatorCountdownView())->setUser($viewer)->setCountdown($countdown)->setHeadless(true);
     $id = $countdown->getID();
     $title = $countdown->getTitle();
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb("C{$id}");
     $epoch = $countdown->getEpoch();
     if ($epoch >= PhabricatorTime::getNow()) {
         $icon = 'fa-clock-o';
         $color = '';
         $status = pht('Running');
     } else {
         $icon = 'fa-check-square-o';
         $color = 'dark';
         $status = pht('Launched');
     }
     $header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($countdown)->setStatus($icon, $color, $status);
     $actions = $this->buildActionListView($countdown);
     $properties = $this->buildPropertyListView($countdown, $actions);
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $timeline = $this->buildTransactionTimeline($countdown, new PhabricatorCountdownTransactionQuery());
     $add_comment = $this->buildCommentForm($countdown);
     $content = array($crumbs, $object_box, $countdown_view, $timeline, $add_comment);
     return $this->buildApplicationPage($content, array('title' => $title, 'pageObjects' => array($countdown->getPHID())));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $tasks = $this->loadTasks($args);
     foreach ($tasks as $task) {
         $can_execute = !$task->isArchived();
         if (!$can_execute) {
             $console->writeOut("**<bg:yellow> %s </bg>** %s\n", pht('ARCHIVED'), pht('%s is already archived, and can not be executed.', $this->describeTask($task)));
             continue;
         }
         // NOTE: This ignores leases, maybe it should respect them without
         // a parameter like --force?
         $task->setLeaseOwner(null);
         $task->setLeaseExpires(PhabricatorTime::getNow());
         $task->save();
         $task_data = id(new PhabricatorWorkerTaskData())->loadOneWhere('id = %d', $task->getDataID());
         $task->setData($task_data->getData());
         $console->writeOut(pht('Executing task %d (%s)...', $task->getID(), $task->getTaskClass()));
         $task = $task->executeTask();
         $ex = $task->getExecutionException();
         if ($ex) {
             throw $ex;
         }
     }
     return 0;
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $countdown = id(new PhabricatorCountdownQuery())->setViewer($viewer)->withIDs(array($id))->executeOne();
     if (!$countdown) {
         return new Aphront404Response();
     }
     $countdown_view = id(new PhabricatorCountdownView())->setUser($viewer)->setCountdown($countdown);
     $id = $countdown->getID();
     $title = $countdown->getTitle();
     $crumbs = $this->buildApplicationCrumbs()->addTextCrumb("C{$id}")->setBorder(true);
     $epoch = $countdown->getEpoch();
     if ($epoch >= PhabricatorTime::getNow()) {
         $icon = 'fa-clock-o';
         $color = '';
         $status = pht('Running');
     } else {
         $icon = 'fa-check-square-o';
         $color = 'dark';
         $status = pht('Launched');
     }
     $header = id(new PHUIHeaderView())->setHeader($title)->setUser($viewer)->setPolicyObject($countdown)->setStatus($icon, $color, $status)->setHeaderIcon('fa-rocket');
     $curtain = $this->buildCurtain($countdown);
     $subheader = $this->buildSubheaderView($countdown);
     $timeline = $this->buildTransactionTimeline($countdown, new PhabricatorCountdownTransactionQuery());
     $comment_view = id(new PhabricatorCountdownEditEngine())->setViewer($viewer)->buildEditEngineCommentView($countdown);
     $content = array($countdown_view, $timeline, $comment_view);
     $view = id(new PHUITwoColumnView())->setHeader($header)->setSubheader($subheader)->setCurtain($curtain)->setMainColumn($content);
     return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->setPageObjectPHIDs(array($countdown->getPHID()))->appendChild($view);
 }
 public function revokeToken()
 {
     if ($this->isRevocable()) {
         $this->setTokenExpires(PhabricatorTime::getNow() - 1)->save();
     }
     return $this;
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $revision = id(new DifferentialRevisionQuery())->setViewer($this->getViewer())->withPHIDs(array($object->getPHID()))->needReviewerStatus(true)->executeOne();
     // TODO: This isn't very clean, but custom fields currently rely on it.
     $object->attachReviewerStatus($revision->getReviewerStatus());
     $document->setDocumentTitle($revision->getTitle());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $revision->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateCreated());
     $document->addRelationship($revision->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $revision->getPHID(), DifferentialRevisionPHIDType::TYPECONST, PhabricatorTime::getNow());
     // If a revision needs review, the owners are the reviewers. Otherwise, the
     // owner is the author (e.g., accepted, rejected, closed).
     $status_review = ArcanistDifferentialRevisionStatus::NEEDS_REVIEW;
     if ($revision->getStatus() == $status_review) {
         $reviewers = $revision->getReviewerStatus();
         $reviewers = mpull($reviewers, 'getReviewerPHID', 'getReviewerPHID');
         if ($reviewers) {
             foreach ($reviewers as $phid) {
                 $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $phid, PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified());
                 // Bogus timestamp.
             }
         } else {
             $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_UNOWNED, $revision->getPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $revision->getDateModified());
             // Bogus timestamp.
         }
     } else {
         $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $revision->getAuthorPHID(), PhabricatorPHIDConstants::PHID_TYPE_VOID, $revision->getDateCreated());
     }
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $blog = $object;
     $document->setDocumentTitle($blog->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $blog->getDescription());
     $document->addRelationship($blog->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $blog->getPHID(), PhabricatorPhameBlogPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $credential = $object;
     $document->setDocumentTitle($credential->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $credential->getDescription());
     $document->addRelationship($credential->getIsDestroyed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $credential->getPHID(), PassphraseCredentialPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected final function executeQuery()
 {
     $future = $this->newQueryFuture();
     $drequest = $this->getRequest();
     $name = basename($drequest->getPath());
     $ttl = PhabricatorTime::getNow() + phutil_units('48 hours in seconds');
     try {
         $threshold = PhabricatorFileStorageEngine::getChunkThreshold();
         $future->setReadBufferSize($threshold);
         $source = id(new PhabricatorExecFutureFileUploadSource())->setName($name)->setTTL($ttl)->setViewPolicy(PhabricatorPolicies::POLICY_NOONE)->setExecFuture($future);
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         $file = $source->uploadFile();
         unset($unguarded);
     } catch (CommandException $ex) {
         if (!$future->getWasKilledByTimeout()) {
             throw $ex;
         }
         $this->didHitTimeLimit = true;
         $file = null;
     }
     $byte_limit = $this->getByteLimit();
     if ($byte_limit && $file->getByteSize() > $byte_limit) {
         $this->didHitByteLimit = true;
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         id(new PhabricatorDestructionEngine())->destroyObject($file);
         unset($unguarded);
         $file = null;
     }
     return $file;
 }
 public function getDisplayMinutes()
 {
     $epoch = $this->getEpoch();
     $now = PhabricatorTime::getNow();
     $minutes = (int) ceil(($epoch - $now) / 60);
     return new PhutilNumber($minutes);
 }
예제 #13
0
 protected function applyCustomInternalTransaction(PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction)
 {
     switch ($xaction->getTransactionType()) {
         case PhamePostTransaction::TYPE_TITLE:
             return $object->setTitle($xaction->getNewValue());
         case PhamePostTransaction::TYPE_SUBTITLE:
             return $object->setSubtitle($xaction->getNewValue());
         case PhamePostTransaction::TYPE_BODY:
             return $object->setBody($xaction->getNewValue());
         case PhamePostTransaction::TYPE_BLOG:
             return $object->setBlogPHID($xaction->getNewValue());
         case PhamePostTransaction::TYPE_HEADERIMAGE:
             return $object->setHeaderImagePHID($xaction->getNewValue());
         case PhamePostTransaction::TYPE_VISIBILITY:
             if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
                 $object->setDatePublished(0);
             } else {
                 if ($xaction->getNewValue() == PhameConstants::VISIBILITY_ARCHIVED) {
                     $object->setDatePublished(0);
                 } else {
                     $object->setDatePublished(PhabricatorTime::getNow());
                 }
             }
             return $object->setVisibility($xaction->getNewValue());
     }
     return parent::applyCustomInternalTransaction($object, $xaction);
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $project = $object;
     $project->updateDatasourceTokens();
     $document->setDocumentTitle($project->getName());
     $document->addRelationship($project->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $project->getPHID(), PhabricatorProjectProjectPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->ids !== null) {
         $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids);
     }
     if ($this->objectPHIDs !== null) {
         $where[] = qsprintf($conn_r, 'objectPHID IN (%Ls)', $this->objectPHIDs);
     }
     if ($this->tokens !== null) {
         $where[] = qsprintf($conn_r, 'token IN (%Ls)', $this->tokens);
     }
     if ($this->tokenTypes !== null) {
         $where[] = qsprintf($conn_r, 'tokenType IN (%Ls)', $this->tokenTypes);
     }
     if ($this->expired !== null) {
         if ($this->expired) {
             $where[] = qsprintf($conn_r, 'expires <= %d', PhabricatorTime::getNow());
         } else {
             $where[] = qsprintf($conn_r, 'expires IS NULL OR expires > %d', PhabricatorTime::getNow());
         }
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
 private function updateLease(DrydockLease $lease)
 {
     if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
         return;
     }
     $viewer = $this->getViewer();
     $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID();
     // Check if the lease has expired. If it is, we're going to send it a
     // release command. This command will be handled immediately below, it
     // just generates a command log and improves consistency.
     $now = PhabricatorTime::getNow();
     $expires = $lease->getUntil();
     if ($expires && $expires <= $now) {
         $command = DrydockCommand::initializeNewCommand($viewer)->setTargetPHID($lease->getPHID())->setAuthorPHID($drydock_phid)->setCommand(DrydockCommand::COMMAND_RELEASE)->save();
     }
     $commands = $this->loadCommands($lease->getPHID());
     foreach ($commands as $command) {
         if ($lease->getStatus() != DrydockLeaseStatus::STATUS_ACTIVE) {
             // Leases can't receive commands before they activate or after they
             // release.
             break;
         }
         $this->processCommand($lease, $command);
         $command->setIsConsumed(true)->save();
     }
     // If this is the task which will eventually release the lease after it
     // expires but it is still active, reschedule the task to run after the
     // lease expires. This can happen if the lease's expiration was pushed
     // forward.
     if ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE) {
         if ($this->getTaskDataValue('isExpireTask') && $expires) {
             throw new PhabricatorWorkerYieldException($expires - $now);
         }
     }
 }
 public function testOneTimeTriggerClock()
 {
     $now = PhabricatorTime::getNow();
     $clock = new PhabricatorOneTimeTriggerClock(array('epoch' => $now));
     $this->assertEqual($now, $clock->getNextEventEpoch(null, false), pht('Should trigger at specified epoch.'));
     $this->assertEqual(null, $clock->getNextEventEpoch(1, false), pht('Should trigger only once.'));
 }
 protected function collectGarbage()
 {
     $table = new PhabricatorConduitToken();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE expires <= %d
     ORDER BY dateCreated ASC LIMIT 100', $table->getTableName(), PhabricatorTime::getNow());
     return $conn_w->getAffectedRows() == 100;
 }
예제 #19
0
 public function testPhabricatorTimeStack()
 {
     $t = 1370202281;
     $time = PhabricatorTime::pushTime($t, 'UTC');
     $this->assertTrue(PhabricatorTime::getNow() === $t);
     unset($time);
     $this->assertFalse(PhabricatorTime::getNow() === $t);
 }
 protected function buildCustomEditFields($object)
 {
     $epoch_value = $object->getEpoch();
     if ($epoch_value === null) {
         $epoch_value = PhabricatorTime::getNow();
     }
     return array(id(new PhabricatorTextEditField())->setKey('name')->setLabel(pht('Name'))->setIsRequired(true)->setTransactionType(PhabricatorCountdownTransaction::TYPE_TITLE)->setDescription(pht('The countdown name.'))->setConduitDescription(pht('Rename the countdown.'))->setConduitTypeDescription(pht('New countdown name.'))->setValue($object->getTitle()), id(new PhabricatorEpochEditField())->setKey('epoch')->setLabel(pht('End Date'))->setTransactionType(PhabricatorCountdownTransaction::TYPE_EPOCH)->setDescription(pht('Date when the countdown ends.'))->setConduitDescription(pht('Change the end date of the countdown.'))->setConduitTypeDescription(pht('New countdown end date.'))->setValue($epoch_value), id(new PhabricatorRemarkupEditField())->setKey('description')->setLabel(pht('Description'))->setTransactionType(PhabricatorCountdownTransaction::TYPE_DESCRIPTION)->setDescription(pht('Description of the countdown.'))->setConduitDescription(pht('Change the countdown description.'))->setConduitTypeDescription(pht('New description.'))->setValue($object->getDescription()));
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $initiative = $object;
     $document->setDocumentTitle($initiative->getName());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $initiative->getOwnerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $initiative->getDateCreated());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_OWNER, $initiative->getOwnerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $initiative->getDateCreated());
     $document->addRelationship($initiative->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $initiative->getPHID(), FundInitiativePHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $post = $object;
     $document->setDocumentTitle($post->getTitle());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $post->getBody());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $post->getBloggerPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $post->getDateCreated());
     $document->addRelationship($post->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $post->getPHID(), PhabricatorPhamePostPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 protected function collectGarbage()
 {
     $cache = new PhabricatorKeyValueDatabaseCache();
     $conn_w = $cache->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE cacheExpires < %d
     ORDER BY cacheExpires ASC LIMIT 100', $cache->getTableName(), PhabricatorTime::getNow());
     return $conn_w->getAffectedRows() == 100;
 }
 public function collectGarbage()
 {
     $ttl = phutil_units('90 days in seconds');
     $table = new MultimeterEvent();
     $conn_w = $table->establishConnection('w');
     queryfx($conn_w, 'DELETE FROM %T WHERE epoch < %d LIMIT 100', $table->getTableName(), PhabricatorTime::getNow() - $ttl);
     return $conn_w->getAffectedRows() == 100;
 }
 protected function collectGarbage()
 {
     $files = id(new PhabricatorFile())->loadAllWhere('ttl < %d LIMIT 100', PhabricatorTime::getNow());
     foreach ($files as $file) {
         $file->delete();
     }
     return count($files) == 100;
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $mock = $object;
     $document->setDocumentTitle($mock->getName());
     $document->addField(PhabricatorSearchDocumentFieldType::FIELD_BODY, $mock->getDescription());
     $document->addRelationship(PhabricatorSearchRelationship::RELATIONSHIP_AUTHOR, $mock->getAuthorPHID(), PhabricatorPeopleUserPHIDType::TYPECONST, $mock->getDateCreated());
     $document->addRelationship($mock->isClosed() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $mock->getPHID(), PholioMockPHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 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;
 }
예제 #28
0
 public function newEvent($type, $label, $cost)
 {
     if (!$this->isActive()) {
         return null;
     }
     $event = id(new MultimeterEvent())->setEventType($type)->setEventLabel($label)->setResourceCost($cost)->setEpoch(PhabricatorTime::getNow());
     $this->events[] = $event;
     return $event;
 }
 protected function buildAbstractDocument(PhabricatorSearchAbstractDocument $document, $object)
 {
     $package = $object;
     $document->setDocumentTitle($package->getName());
     // TODO: These are bogus, but not currently stored on packages.
     $document->setDocumentCreated(PhabricatorTime::getNow());
     $document->setDocumentModified(PhabricatorTime::getNow());
     $document->addRelationship($package->isArchived() ? PhabricatorSearchRelationship::RELATIONSHIP_CLOSED : PhabricatorSearchRelationship::RELATIONSHIP_OPEN, $package->getPHID(), PhabricatorOwnersPackagePHIDType::TYPECONST, PhabricatorTime::getNow());
 }
 public function getEndDate($aux_fields)
 {
     $end = idx($aux_fields, 'isdc:sprint:enddate')->getProxy()->getFieldValue();
     if (is_null($end)) {
         return PhabricatorTime::getNow() + 1209600;
     } else {
         return $end;
     }
 }