@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Write a trivial log when starting a repository operation

Summary:
Depends on D19672. Ref T13197. See PHI873. This writes a trivial log when we begin acting on a working copy and makes it look reasonable in the UI.

This is mostly just to prove that logging works properly.

Test Plan: {F5887697}

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19673

+150 -15
+2
src/__phutil_library_map__.php
··· 1168 1168 'DrydockManagementUpdateResourceWorkflow' => 'applications/drydock/management/DrydockManagementUpdateResourceWorkflow.php', 1169 1169 'DrydockManagementWorkflow' => 'applications/drydock/management/DrydockManagementWorkflow.php', 1170 1170 'DrydockObjectAuthorizationView' => 'applications/drydock/view/DrydockObjectAuthorizationView.php', 1171 + 'DrydockOperationWorkLogType' => 'applications/drydock/logtype/DrydockOperationWorkLogType.php', 1171 1172 'DrydockQuery' => 'applications/drydock/query/DrydockQuery.php', 1172 1173 'DrydockRepositoryOperation' => 'applications/drydock/storage/DrydockRepositoryOperation.php', 1173 1174 'DrydockRepositoryOperationController' => 'applications/drydock/controller/DrydockRepositoryOperationController.php', ··· 6575 6576 'DrydockManagementUpdateResourceWorkflow' => 'DrydockManagementWorkflow', 6576 6577 'DrydockManagementWorkflow' => 'PhabricatorManagementWorkflow', 6577 6578 'DrydockObjectAuthorizationView' => 'AphrontView', 6579 + 'DrydockOperationWorkLogType' => 'DrydockLogType', 6578 6580 'DrydockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6579 6581 'DrydockRepositoryOperation' => array( 6580 6582 'DrydockDAO',
+4 -1
src/applications/drydock/controller/DrydockBlueprintViewController.php
··· 58 58 $log_query = id(new DrydockLogQuery()) 59 59 ->withBlueprintPHIDs(array($blueprint->getPHID())); 60 60 61 + $log_table = $this->buildLogTable($log_query) 62 + ->setHideBlueprints(true); 63 + 61 64 $logs = $this->buildLogBox( 62 - $log_query, 65 + $log_table, 63 66 $this->getApplicationURI("blueprint/{$id}/logs/query/all/")); 64 67 65 68 $view = id(new PHUITwoColumnView())
+6 -3
src/applications/drydock/controller/DrydockController.php
··· 79 79 ->addRawContent($table); 80 80 } 81 81 82 - protected function buildLogBox(DrydockLogQuery $query, $all_uri) { 82 + protected function buildLogTable(DrydockLogQuery $query) { 83 83 $viewer = $this->getViewer(); 84 84 85 85 $logs = $query ··· 89 89 90 90 $log_table = id(new DrydockLogListView()) 91 91 ->setUser($viewer) 92 - ->setLogs($logs) 93 - ->render(); 92 + ->setLogs($logs); 93 + 94 + return $log_table; 95 + } 94 96 97 + protected function buildLogBox(DrydockLogListView $log_table, $all_uri) { 95 98 $log_header = id(new PHUIHeaderView()) 96 99 ->setHeader(pht('Logs')) 97 100 ->addActionLink(
+4 -1
src/applications/drydock/controller/DrydockLeaseViewController.php
··· 43 43 $log_query = id(new DrydockLogQuery()) 44 44 ->withLeasePHIDs(array($lease->getPHID())); 45 45 46 + $log_table = $this->buildLogTable($log_query) 47 + ->setHideLeases(true); 48 + 46 49 $logs = $this->buildLogBox( 47 - $log_query, 50 + $log_table, 48 51 $this->getApplicationURI("lease/{$id}/logs/query/all/")); 49 52 50 53 $crumbs = $this->buildApplicationCrumbs();
+4 -1
src/applications/drydock/controller/DrydockRepositoryOperationViewController.php
··· 50 50 $log_query = id(new DrydockLogQuery()) 51 51 ->withOperationPHIDs(array($operation->getPHID())); 52 52 53 + $log_table = $this->buildLogTable($log_query) 54 + ->setHideOperations(true); 55 + 53 56 $logs = $this->buildLogBox( 54 - $log_query, 57 + $log_table, 55 58 $this->getApplicationURI("operation/{$id}/logs/query/all/")); 56 59 57 60 $view = id(new PHUITwoColumnView())
+11 -7
src/applications/drydock/controller/DrydockResourceViewController.php
··· 48 48 $log_query = id(new DrydockLogQuery()) 49 49 ->withResourcePHIDs(array($resource->getPHID())); 50 50 51 - $log_box = $this->buildLogBox( 52 - $log_query, 51 + $log_table = $this->buildLogTable($log_query) 52 + ->setHideResources(true); 53 + 54 + $logs = $this->buildLogBox( 55 + $log_table, 53 56 $this->getApplicationURI("resource/{$id}/logs/query/all/")); 54 57 55 58 $crumbs = $this->buildApplicationCrumbs(); ··· 86 89 $view = id(new PHUITwoColumnView()) 87 90 ->setHeader($header) 88 91 ->setCurtain($curtain) 89 - ->setMainColumn(array( 90 - $object_box, 91 - $lease_box, 92 - $log_box, 93 - )); 92 + ->setMainColumn( 93 + array( 94 + $object_box, 95 + $lease_box, 96 + $logs, 97 + )); 94 98 95 99 return $this->newPage() 96 100 ->setTitle($title)
+19
src/applications/drydock/logtype/DrydockOperationWorkLogType.php
··· 1 + <?php 2 + 3 + final class DrydockOperationWorkLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.operation.work'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Started Work'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-check green'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Started this operation in a working copy.'); 17 + } 18 + 19 + }
+2 -2
src/applications/drydock/phid/DrydockRepositoryOperationPHIDType.php
··· 5 5 const TYPECONST = 'DRYO'; 6 6 7 7 public function getTypeName() { 8 - return pht('Drydock Repository Operation'); 8 + return pht('Repository Operation'); 9 9 } 10 10 11 11 public function newObject() { ··· 33 33 $operation = $objects[$phid]; 34 34 $id = $operation->getID(); 35 35 36 - $handle->setName(pht('Drydock Repository Operation %d', $id)); 36 + $handle->setName(pht('Repository Operation %d', $id)); 37 37 $handle->setURI("/drydock/operation/{$id}/"); 38 38 } 39 39 }
+37
src/applications/drydock/storage/DrydockRepositoryOperation.php
··· 25 25 private $repository = self::ATTACHABLE; 26 26 private $object = self::ATTACHABLE; 27 27 private $implementation = self::ATTACHABLE; 28 + private $workingCopyLease = self::ATTACHABLE; 28 29 29 30 public static function initializeNewOperation( 30 31 DrydockRepositoryOperationType $op) { ··· 88 89 89 90 public function getImplementation() { 90 91 return $this->implementation; 92 + } 93 + 94 + public function getWorkingCopyLease() { 95 + return $this->assertAttached($this->workingCopyLease); 96 + } 97 + 98 + public function attachWorkingCopyLease(DrydockLease $lease) { 99 + $this->workingCopyLease = $lease; 100 + return $this; 101 + } 102 + 103 + public function hasWorkingCopyLease() { 104 + return ($this->workingCopyLease !== self::ATTACHABLE); 91 105 } 92 106 93 107 public function getProperty($key, $default = null) { ··· 189 203 return $this->getProperty('exec.workingcopy.error'); 190 204 } 191 205 206 + public function logEvent($type, array $data = array()) { 207 + $log = id(new DrydockLog()) 208 + ->setEpoch(PhabricatorTime::getNow()) 209 + ->setType($type) 210 + ->setData($data); 211 + 212 + $log->setOperationPHID($this->getPHID()); 213 + 214 + if ($this->hasWorkingCopyLease()) { 215 + $lease = $this->getWorkingCopyLease(); 216 + $log->setLeasePHID($lease->getPHID()); 217 + 218 + $resource_phid = $lease->getResourcePHID(); 219 + if ($resource_phid) { 220 + $resource = $lease->getResource(); 221 + 222 + $log->setResourcePHID($resource->getPHID()); 223 + $log->setBlueprintPHID($resource->getBlueprintPHID()); 224 + } 225 + } 226 + 227 + return $log->save(); 228 + } 192 229 193 230 194 231 /* -( PhabricatorPolicyInterface )----------------------------------------- */
+57
src/applications/drydock/view/DrydockLogListView.php
··· 3 3 final class DrydockLogListView extends AphrontView { 4 4 5 5 private $logs; 6 + private $hideBlueprints; 7 + private $hideResources; 8 + private $hideLeases; 9 + private $hideOperations; 10 + 11 + public function setHideBlueprints($hide_blueprints) { 12 + $this->hideBlueprints = $hide_blueprints; 13 + return $this; 14 + } 15 + 16 + public function getHideBlueprints() { 17 + return $this->hideBlueprints; 18 + } 19 + 20 + public function setHideResources($hide_resources) { 21 + $this->hideResources = $hide_resources; 22 + return $this; 23 + } 24 + 25 + public function getHideResources() { 26 + return $this->hideResources; 27 + } 28 + 29 + public function setHideLeases($hide_leases) { 30 + $this->hideLeases = $hide_leases; 31 + return $this; 32 + } 33 + 34 + public function getHideLeases() { 35 + return $this->hideLeases; 36 + } 37 + 38 + public function setHideOperations($hide_operations) { 39 + $this->hideOperations = $hide_operations; 40 + return $this; 41 + } 42 + 43 + public function getHideOperations() { 44 + return $this->hideOperations; 45 + } 6 46 7 47 public function setLogs(array $logs) { 8 48 assert_instances_of($logs, 'DrydockLog'); ··· 41 81 $lease = null; 42 82 } 43 83 84 + $operation_phid = $log->getOperationPHID(); 85 + if ($operation_phid) { 86 + $operation = $viewer->renderHandle($operation_phid); 87 + } else { 88 + $operation = null; 89 + } 90 + 44 91 if ($log->isComplete()) { 45 92 $type_key = $log->getType(); 46 93 if (isset($types[$type_key])) { ··· 72 119 $blueprint, 73 120 $resource, 74 121 $lease, 122 + $operation, 75 123 id(new PHUIIconView())->setIcon($icon), 76 124 $type, 77 125 $data, ··· 86 134 pht('Blueprint'), 87 135 pht('Resource'), 88 136 pht('Lease'), 137 + pht('Operation'), 89 138 null, 90 139 pht('Type'), 91 140 pht('Data'), 92 141 pht('Date'), 93 142 )) 143 + ->setColumnVisibility( 144 + array( 145 + !$this->getHideBlueprints(), 146 + !$this->getHideResources(), 147 + !$this->getHideLeases(), 148 + !$this->getHideOperations(), 149 + )) 94 150 ->setColumnClasses( 95 151 array( 152 + '', 96 153 '', 97 154 '', 98 155 '',
+4
src/applications/drydock/worker/DrydockRepositoryOperationUpdateWorker.php
··· 59 59 // No matter what happens here, destroy the lease away once we're done. 60 60 $lease->setReleaseOnDestruction(true); 61 61 62 + $operation->attachWorkingCopyLease($lease); 63 + 64 + $operation->logEvent(DrydockOperationWorkLogType::LOGCONST); 65 + 62 66 $operation->applyOperation($interface); 63 67 64 68 } catch (PhabricatorWorkerYieldException $ex) {