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; }
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 parseDateTime($value) { if (!strlen($value)) { return null; } return PhabricatorTime::parseLocalTime($value, $this->getViewer()); }
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; }
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; }
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); } } }
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); }
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); }
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) { $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 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()); }
public function getDisplayMinutes() { $epoch = $this->getEpoch(); $now = PhabricatorTime::getNow(); $minutes = (int) ceil(($epoch - $now) / 60); return new PhutilNumber($minutes); }
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 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 render() { require_celerity_resource('phui-calendar-day-css'); $viewer = $this->getUser(); $hours = $this->getHoursOfDay(); $js_hours = array(); $js_today_events = array(); foreach ($hours as $hour) { $js_hours[] = array('hour' => $hour->format('G'), 'displayTime' => phabricator_time($hour->format('U'), $viewer)); } $first_event_hour = null; $js_today_all_day_events = array(); $all_day_events = $this->getAllDayEvents(); $day_start = $this->getDateTime(); $day_end = id(clone $day_start)->modify('+1 day'); $day_start_epoch = $day_start->format('U'); $day_end_epoch = $day_end->format('U') - 1; foreach ($all_day_events as $all_day_event) { $all_day_start = $all_day_event->getEpochStart(); $all_day_end = $all_day_event->getEpochEnd(); if ($all_day_start < $day_end_epoch && $all_day_end > $day_start_epoch) { $js_today_all_day_events[] = array('name' => $all_day_event->getName(), 'id' => $all_day_event->getEventID(), 'viewerIsInvited' => $all_day_event->getViewerIsInvited(), 'uri' => $all_day_event->getURI(), 'displayIcon' => $all_day_event->getIcon(), 'displayIconColor' => $all_day_event->getIconColor()); } } $this->events = msort($this->events, 'getEpochStart'); $first_event_hour = $this->getDateTime()->setTime(8, 0, 0); $midnight = $this->getDateTime()->setTime(0, 0, 0); foreach ($this->events as $event) { if ($event->getIsAllDay()) { continue; } if ($event->getEpochStart() <= $day_end_epoch && $event->getEpochEnd() > $day_start_epoch) { if ($event->getEpochStart() < $midnight->format('U') && $event->getEpochEnd() > $midnight->format('U')) { $first_event_hour = clone $midnight; } if ($event->getEpochStart() < $first_event_hour->format('U') && $event->getEpochStart() > $midnight->format('U')) { $first_event_hour = PhabricatorTime::getDateTimeFromEpoch($event->getEpochStart(), $viewer); $first_event_hour->setTime($first_event_hour->format('h'), 0, 0); } $event_start = max($event->getEpochStart(), $day_start_epoch); $event_end = min($event->getEpochEnd(), $day_end_epoch); $day_duration = ($day_end_epoch - $first_event_hour->format('U')) / 60; $top = ($event_start - $first_event_hour->format('U')) / ($day_end_epoch - $first_event_hour->format('U')) * $day_duration; $top = max(0, $top); $height = ($event_end - $event_start) / ($day_end_epoch - $first_event_hour->format('U')) * $day_duration; $height = min($day_duration, $height); $js_today_events[] = array('eventStartEpoch' => $event->getEpochStart(), 'eventEndEpoch' => $event->getEpochEnd(), 'eventName' => $event->getName(), 'eventID' => $event->getEventID(), 'viewerIsInvited' => $event->getViewerIsInvited(), 'uri' => $event->getURI(), 'offset' => '0', 'width' => '100%', 'top' => $top . 'px', 'height' => $height . 'px', 'canEdit' => $event->getCanEdit(), 'displayIcon' => $event->getIcon(), 'displayIconColor' => $event->getIconColor()); } } $header = $this->renderDayViewHeader(); $sidebar = id(new PHUICalendarWeekView())->setViewer($this->getViewer())->setEvents($this->events)->setDateTime($this->getDateTime())->render(); $warnings = $this->getQueryRangeWarning(); $table_id = celerity_generate_unique_node_id(); $table_wrapper = phutil_tag('div', array('id' => $table_id), ''); Javelin::initBehavior('day-view', array('year' => $first_event_hour->format('Y'), 'month' => $first_event_hour->format('m'), 'day' => $first_event_hour->format('d'), 'query' => $this->getQuery(), 'allDayEvents' => $js_today_all_day_events, 'todayEvents' => $js_today_events, 'hours' => $js_hours, 'firstEventHour' => $first_event_hour->format('G'), 'firstEventHourEpoch' => $first_event_hour->format('U'), 'tableID' => $table_id)); $table_box = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($table_wrapper)->setFormErrors($warnings)->setFlush(true); $layout = id(new AphrontMultiColumnView())->addColumn($sidebar, 'third phui-day-view-upcoming')->addColumn($table_box, 'thirds phui-day-view-column')->setFluidLayout(true); $layout = id(new PHUIBoxView())->appendChild($layout)->addClass('phui-calendar-box'); return $layout; }
private function buildCalendarDayView(PhabricatorUser $user) { $viewer = $this->getViewer(); $class = 'PhabricatorCalendarApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return null; } $midnight = PhabricatorTime::getTodayMidnightDateTime($viewer); $week_end = clone $midnight; $week_end = $week_end->modify('+3 days'); $range_start = $midnight->format('U'); $range_end = $week_end->format('U'); $events = id(new PhabricatorCalendarEventQuery())->setViewer($viewer)->withDateRange($range_start, $range_end)->withInvitedPHIDs(array($user->getPHID()))->withIsCancelled(false)->needRSVPs(array($viewer->getPHID()))->execute(); $event_views = array(); foreach ($events as $event) { $viewer_is_invited = $event->isRSVPInvited($viewer->getPHID()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $event, PhabricatorPolicyCapability::CAN_EDIT); $epoch_min = $event->getStartDateTimeEpoch(); $epoch_max = $event->getEndDateTimeEpoch(); $event_view = id(new AphrontCalendarEventView())->setCanEdit($can_edit)->setEventID($event->getID())->setEpochRange($epoch_min, $epoch_max)->setIsAllDay($event->getIsAllDay())->setIcon($event->getIcon())->setViewerIsInvited($viewer_is_invited)->setName($event->getName())->setDatetimeSummary($event->renderEventDate($viewer, true))->setURI($event->getURI()); $event_views[] = $event_view; } $event_views = msort($event_views, 'getEpochStart'); $day_view = id(new PHUICalendarWeekView())->setViewer($viewer)->setView('week')->setEvents($event_views)->setWeekLength(3)->render(); $header = id(new PHUIHeaderView())->setHeader(pht('Calendar'))->setHref(urisprintf('/calendar/?invited=%s#R', $user->getUsername())); $box = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($day_view)->addClass('calendar-profile-box')->setBackground(PHUIObjectBoxView::GREY); return $box; }
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.')); }
private function buildCalendarDayView(PhabricatorUser $user) { $viewer = $this->getViewer(); $class = 'PhabricatorCalendarApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return null; } $midnight = PhabricatorTime::getTodayMidnightDateTime($viewer); $week_end = clone $midnight; $week_end = $week_end->modify('+3 days'); $range_start = $midnight->format('U'); $range_end = $week_end->format('U'); $query = id(new PhabricatorCalendarEventQuery())->setViewer($viewer)->withDateRange($range_start, $range_end)->withInvitedPHIDs(array($user->getPHID()))->withIsCancelled(false); $statuses = $query->execute(); $phids = mpull($statuses, 'getUserPHID'); $events = array(); foreach ($statuses as $status) { $viewer_is_invited = $status->getIsUserInvited($user->getPHID()); $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $status, PhabricatorPolicyCapability::CAN_EDIT); $event = id(new AphrontCalendarEventView())->setCanEdit($can_edit)->setEventID($status->getID())->setEpochRange($status->getDateFrom(), $status->getDateTo())->setIsAllDay($status->getIsAllDay())->setIcon($status->getIcon())->setViewerIsInvited($viewer_is_invited)->setName($status->getName())->setURI($status->getURI()); $events[] = $event; } $events = msort($events, 'getEpochStart'); $day_view = id(new PHUICalendarWeekView())->setViewer($viewer)->setView('week')->setEvents($events)->setWeekLength(3)->render(); $header = id(new PHUIHeaderView())->setHeader(pht('Calendar'))->setHref(urisprintf('/calendar/?invitedPHIDs=%s#R', $user->getPHID())); $box = id(new PHUIObjectBoxView())->setHeader($header)->appendChild($day_view)->setBackground(PHUIObjectBoxView::GREY); return $box; }
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 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 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; }
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; }
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 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()); }
protected function collectGarbage() { $files = id(new PhabricatorFile())->loadAllWhere('ttl < %d LIMIT 100', PhabricatorTime::getNow()); foreach ($files as $file) { $file->delete(); } return count($files) == 100; }