@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

Allow Drydock logs to be associated with RepositoryOperation objects

Summary: Ref T13197. See PHI873. I want to give RepositoryOperation objects access to Drydock logging like leases, resources, and blueprints currently have. This just does the schema/query changes, no actual UI or new logging yet.

Test Plan: Ran storage upgrade, poked around the UI looking for anything broken.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13197

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

+58 -2
+2
resources/sql/autopatches/20180914.drydock.01.operationphid.sql
··· 1 + ALTER TABLE {$NAMESPACE}_drydock.drydock_log 2 + ADD operationPHID VARBINARY(64);
+34
src/applications/drydock/query/DrydockLogQuery.php
··· 5 5 private $blueprintPHIDs; 6 6 private $resourcePHIDs; 7 7 private $leasePHIDs; 8 + private $operationPHIDs; 8 9 9 10 public function withBlueprintPHIDs(array $phids) { 10 11 $this->blueprintPHIDs = $phids; ··· 18 19 19 20 public function withLeasePHIDs(array $phids) { 20 21 $this->leasePHIDs = $phids; 22 + return $this; 23 + } 24 + 25 + public function withOperationPHIDs(array $phids) { 26 + $this->operationPHIDs = $phids; 21 27 return $this; 22 28 } 23 29 ··· 93 99 $log->attachLease($lease); 94 100 } 95 101 102 + $operation_phids = array_filter(mpull($logs, 'getOperationPHID')); 103 + if ($operation_phids) { 104 + $operations = id(new DrydockRepositoryOperationQuery()) 105 + ->setParentQuery($this) 106 + ->setViewer($this->getViewer()) 107 + ->withPHIDs($operation_phids) 108 + ->execute(); 109 + $operations = mpull($operations, null, 'getPHID'); 110 + } else { 111 + $operations = array(); 112 + } 113 + 114 + foreach ($logs as $key => $log) { 115 + $operation = null; 116 + $operation_phid = $log->getOperationPHID(); 117 + if ($operation_phid) { 118 + $operation = idx($operations, $operation_phid); 119 + } 120 + $log->attachOperation($operation); 121 + } 122 + 96 123 return $logs; 97 124 } 98 125 ··· 118 145 $conn, 119 146 'leasePHID IN (%Ls)', 120 147 $this->leasePHIDs); 148 + } 149 + 150 + if ($this->operationPHIDs !== null) { 151 + $where[] = qsprintf( 152 + $conn, 153 + 'operationPHID IN (%Ls)', 154 + $this->operationPHIDs); 121 155 } 122 156 123 157 return $where;
+22 -2
src/applications/drydock/storage/DrydockLog.php
··· 6 6 protected $blueprintPHID; 7 7 protected $resourcePHID; 8 8 protected $leasePHID; 9 + protected $operationPHID; 9 10 protected $epoch; 10 11 protected $type; 11 12 protected $data = array(); ··· 13 14 private $blueprint = self::ATTACHABLE; 14 15 private $resource = self::ATTACHABLE; 15 16 private $lease = self::ATTACHABLE; 17 + private $operation = self::ATTACHABLE; 16 18 17 19 protected function getConfiguration() { 18 20 return array( ··· 24 26 'blueprintPHID' => 'phid?', 25 27 'resourcePHID' => 'phid?', 26 28 'leasePHID' => 'phid?', 29 + 'operationPHID' => 'phid?', 27 30 'type' => 'text64', 28 31 ), 29 32 self::CONFIG_KEY_SCHEMA => array( ··· 35 38 ), 36 39 'key_lease' => array( 37 40 'columns' => array('leasePHID', 'type'), 41 + ), 42 + 'key_operation' => array( 43 + 'columns' => array('operationPHID', 'type'), 38 44 ), 39 45 'epoch' => array( 40 46 'columns' => array('epoch'), ··· 70 76 return $this->assertAttached($this->lease); 71 77 } 72 78 79 + public function attachOperation( 80 + DrydockRepositoryOperation $operation = null) { 81 + $this->operation = $operation; 82 + return $this; 83 + } 84 + 85 + public function getOperation() { 86 + return $this->assertAttached($this->operation); 87 + } 88 + 73 89 public function isComplete() { 74 90 if ($this->getBlueprintPHID() && !$this->getBlueprint()) { 75 91 return false; ··· 80 96 } 81 97 82 98 if ($this->getLeasePHID() && !$this->getLease()) { 99 + return false; 100 + } 101 + 102 + if ($this->getOperationPHID() && !$this->getOperation()) { 83 103 return false; 84 104 } 85 105 ··· 108 128 109 129 public function describeAutomaticCapability($capability) { 110 130 return pht( 111 - 'To view log details, you must be able to view the associated '. 112 - 'blueprint, resource and lease.'); 131 + 'To view log details, you must be able to view all associated '. 132 + 'blueprints, resources, leases, and repository operations.'); 113 133 } 114 134 115 135 }