Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
5.0 kB · 170 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171<?php
final class PhabricatorDaemonBulkJobMonitorController extends PhabricatorDaemonBulkJobController {
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer();
$job = id(new PhabricatorWorkerBulkJobQuery()) ->setViewer($viewer) ->withIDs(array($request->getURIData('id'))) ->executeOne(); if (!$job) { return new Aphront404Response(); }
// If the user clicks "Continue" on a completed job, take them back to // whatever application sent them here. if ($request->getStr('done')) { if ($request->isFormPost()) { $done_uri = $job->getDoneURI(); return id(new AphrontRedirectResponse())->setURI($done_uri); } }
$title = pht('Bulk Job %d', $job->getID());
if ($job->getStatus() == PhabricatorWorkerBulkJob::STATUS_CONFIRM) { $can_edit = PhabricatorPolicyFilter::hasCapability( $viewer, $job, PhabricatorPolicyCapability::CAN_EDIT);
if ($can_edit) { if ($request->isFormPost()) { $type_status = PhabricatorWorkerBulkJobTransaction::TYPE_STATUS;
$xactions = array(); $xactions[] = id(new PhabricatorWorkerBulkJobTransaction()) ->setTransactionType($type_status) ->setNewValue(PhabricatorWorkerBulkJob::STATUS_WAITING);
$editor = id(new PhabricatorWorkerBulkJobEditor()) ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnMissingFields(true) ->applyTransactions($job, $xactions);
return id(new AphrontRedirectResponse()) ->setURI($job->getMonitorURI()); } else { $dialog = $this->newDialog() ->setTitle(pht('Confirm Bulk Job'));
$confirm = $job->getDescriptionForConfirm(); $confirm = (array)$confirm; foreach ($confirm as $paragraph) { $dialog->appendParagraph($paragraph); }
$dialog ->appendParagraph( pht('Start work on this bulk job?')) ->addCancelButton($job->getManageURI(), pht('Details')) ->addSubmitButton(pht('Start Work'));
return $dialog; } } else { return $this->newDialog() ->setTitle(pht('Waiting For Confirmation')) ->appendParagraph( pht( 'This job is waiting for confirmation before work begins.')) ->addCancelButton($job->getManageURI(), pht('Details')); } }
$dialog = $this->newDialog() ->setTitle(pht('%s: %s', $title, $job->getStatusName())) ->addCancelButton($job->getManageURI(), pht('Details'));
switch ($job->getStatus()) { case PhabricatorWorkerBulkJob::STATUS_WAITING: $dialog->appendParagraph( pht('This job is waiting for tasks to be queued.')); break; case PhabricatorWorkerBulkJob::STATUS_RUNNING: $dialog->appendParagraph( pht('This job is running.')); break; case PhabricatorWorkerBulkJob::STATUS_COMPLETE: $dialog->appendParagraph( pht('This job is complete.')); break; }
$counts = $job->loadTaskStatusCounts(); if ($counts) { $dialog->appendParagraph($this->renderProgress($counts)); }
switch ($job->getStatus()) { case PhabricatorWorkerBulkJob::STATUS_COMPLETE: $dialog->addHiddenInput('done', true); $dialog->addSubmitButton(pht('Continue')); break; default: Javelin::initBehavior('bulk-job-reload'); break; }
return $dialog; }
private function renderProgress(array $counts) { $this->requireResource('bulk-job-css');
$states = array( PhabricatorWorkerBulkTask::STATUS_DONE => array( 'class' => 'bulk-job-progress-slice-green', ), PhabricatorWorkerBulkTask::STATUS_RUNNING => array( 'class' => 'bulk-job-progress-slice-blue', ), PhabricatorWorkerBulkTask::STATUS_WAITING => array( 'class' => 'bulk-job-progress-slice-empty', ), PhabricatorWorkerBulkTask::STATUS_FAIL => array( 'class' => 'bulk-job-progress-slice-red', ), );
$total = array_sum($counts); $offset = 0; $bars = array(); foreach ($states as $state => $spec) { $size = idx($counts, $state, 0); if (!$size) { continue; }
$classes = array(); $classes[] = 'bulk-job-progress-slice'; $classes[] = $spec['class'];
$width = ($size / $total); $bars[] = phutil_tag( 'div', array( 'class' => implode(' ', $classes), 'style' => 'left: '.sprintf('%.2f%%', 100 * $offset).'; '. 'width: '.sprintf('%.2f%%', 100 * $width).';', ), '');
$offset += $width; }
return phutil_tag( 'div', array( 'class' => 'bulk-job-progress-bar', ), $bars); }
}