diff --git a/resources/sql/autopatches/20180914.drydock.01.operationphid.sql b/resources/sql/autopatches/20180914.drydock.01.operationphid.sql new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20180914.drydock.01.operationphid.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_drydock.drydock_log + ADD operationPHID VARBINARY(64); diff --git a/src/applications/drydock/query/DrydockLogQuery.php b/src/applications/drydock/query/DrydockLogQuery.php --- a/src/applications/drydock/query/DrydockLogQuery.php +++ b/src/applications/drydock/query/DrydockLogQuery.php @@ -5,6 +5,7 @@ private $blueprintPHIDs; private $resourcePHIDs; private $leasePHIDs; + private $operationPHIDs; public function withBlueprintPHIDs(array $phids) { $this->blueprintPHIDs = $phids; @@ -21,6 +22,11 @@ return $this; } + public function withOperationPHIDs(array $phids) { + $this->operationPHIDs = $phids; + return $this; + } + public function newResultObject() { return new DrydockLog(); } @@ -93,6 +99,27 @@ $log->attachLease($lease); } + $operation_phids = array_filter(mpull($logs, 'getOperationPHID')); + if ($operation_phids) { + $operations = id(new DrydockRepositoryOperationQuery()) + ->setParentQuery($this) + ->setViewer($this->getViewer()) + ->withPHIDs($operation_phids) + ->execute(); + $operations = mpull($operations, null, 'getPHID'); + } else { + $operations = array(); + } + + foreach ($logs as $key => $log) { + $operation = null; + $operation_phid = $log->getOperationPHID(); + if ($operation_phid) { + $operation = idx($operations, $operation_phid); + } + $log->attachOperation($operation); + } + return $logs; } @@ -120,6 +147,13 @@ $this->leasePHIDs); } + if ($this->operationPHIDs !== null) { + $where[] = qsprintf( + $conn, + 'operationPHID IN (%Ls)', + $this->operationPHIDs); + } + return $where; } diff --git a/src/applications/drydock/storage/DrydockLog.php b/src/applications/drydock/storage/DrydockLog.php --- a/src/applications/drydock/storage/DrydockLog.php +++ b/src/applications/drydock/storage/DrydockLog.php @@ -6,6 +6,7 @@ protected $blueprintPHID; protected $resourcePHID; protected $leasePHID; + protected $operationPHID; protected $epoch; protected $type; protected $data = array(); @@ -13,6 +14,7 @@ private $blueprint = self::ATTACHABLE; private $resource = self::ATTACHABLE; private $lease = self::ATTACHABLE; + private $operation = self::ATTACHABLE; protected function getConfiguration() { return array( @@ -24,6 +26,7 @@ 'blueprintPHID' => 'phid?', 'resourcePHID' => 'phid?', 'leasePHID' => 'phid?', + 'operationPHID' => 'phid?', 'type' => 'text64', ), self::CONFIG_KEY_SCHEMA => array( @@ -36,6 +39,9 @@ 'key_lease' => array( 'columns' => array('leasePHID', 'type'), ), + 'key_operation' => array( + 'columns' => array('operationPHID', 'type'), + ), 'epoch' => array( 'columns' => array('epoch'), ), @@ -70,6 +76,16 @@ return $this->assertAttached($this->lease); } + public function attachOperation( + DrydockRepositoryOperation $operation = null) { + $this->operation = $operation; + return $this; + } + + public function getOperation() { + return $this->assertAttached($this->operation); + } + public function isComplete() { if ($this->getBlueprintPHID() && !$this->getBlueprint()) { return false; @@ -83,6 +99,10 @@ return false; } + if ($this->getOperationPHID() && !$this->getOperation()) { + return false; + } + return true; } @@ -108,8 +128,8 @@ public function describeAutomaticCapability($capability) { return pht( - 'To view log details, you must be able to view the associated '. - 'blueprint, resource and lease.'); + 'To view log details, you must be able to view all associated '. + 'blueprints, resources, leases, and repository operations.'); } }