@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.

Add Drydock log types and more logging

Summary: Ref T9252. Make log types modular so they can be translated and have complicated rendering logic if necessary (currently, none have this).

Test Plan: {F855330}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9252

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

+232 -27
+12
src/__phutil_library_map__.php
··· 830 830 'DrydockFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockFilesystemInterface.php', 831 831 'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php', 832 832 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 833 + 'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php', 834 + 'DrydockLeaseActivatedLogType' => 'applications/drydock/logtype/DrydockLeaseActivatedLogType.php', 833 835 'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php', 834 836 'DrydockLeaseDatasource' => 'applications/drydock/typeahead/DrydockLeaseDatasource.php', 835 837 'DrydockLeaseDestroyWorker' => 'applications/drydock/worker/DrydockLeaseDestroyWorker.php', 838 + 'DrydockLeaseDestroyedLogType' => 'applications/drydock/logtype/DrydockLeaseDestroyedLogType.php', 836 839 'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php', 837 840 'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php', 838 841 'DrydockLeasePHIDType' => 'applications/drydock/phid/DrydockLeasePHIDType.php', 839 842 'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php', 843 + 'DrydockLeaseQueuedLogType' => 'applications/drydock/logtype/DrydockLeaseQueuedLogType.php', 840 844 'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php', 845 + 'DrydockLeaseReleasedLogType' => 'applications/drydock/logtype/DrydockLeaseReleasedLogType.php', 841 846 'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php', 842 847 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', 843 848 'DrydockLeaseUpdateWorker' => 'applications/drydock/worker/DrydockLeaseUpdateWorker.php', ··· 850 855 'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php', 851 856 'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php', 852 857 'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php', 858 + 'DrydockLogType' => 'applications/drydock/logtype/DrydockLogType.php', 853 859 'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php', 854 860 'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php', 855 861 'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php', ··· 4569 4575 'DrydockDAO', 4570 4576 'PhabricatorPolicyInterface', 4571 4577 ), 4578 + 'DrydockLeaseAcquiredLogType' => 'DrydockLogType', 4579 + 'DrydockLeaseActivatedLogType' => 'DrydockLogType', 4572 4580 'DrydockLeaseController' => 'DrydockController', 4573 4581 'DrydockLeaseDatasource' => 'PhabricatorTypeaheadDatasource', 4574 4582 'DrydockLeaseDestroyWorker' => 'DrydockWorker', 4583 + 'DrydockLeaseDestroyedLogType' => 'DrydockLogType', 4575 4584 'DrydockLeaseListController' => 'DrydockLeaseController', 4576 4585 'DrydockLeaseListView' => 'AphrontView', 4577 4586 'DrydockLeasePHIDType' => 'PhabricatorPHIDType', 4578 4587 'DrydockLeaseQuery' => 'DrydockQuery', 4588 + 'DrydockLeaseQueuedLogType' => 'DrydockLogType', 4579 4589 'DrydockLeaseReleaseController' => 'DrydockLeaseController', 4590 + 'DrydockLeaseReleasedLogType' => 'DrydockLogType', 4580 4591 'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine', 4581 4592 'DrydockLeaseStatus' => 'DrydockConstants', 4582 4593 'DrydockLeaseUpdateWorker' => 'DrydockWorker', ··· 4592 4603 'DrydockLogListView' => 'AphrontView', 4593 4604 'DrydockLogQuery' => 'DrydockQuery', 4594 4605 'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 4606 + 'DrydockLogType' => 'Phobject', 4595 4607 'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow', 4596 4608 'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow', 4597 4609 'DrydockManagementReleaseLeaseWorkflow' => 'DrydockManagementWorkflow',
+19
src/applications/drydock/logtype/DrydockLeaseAcquiredLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseAcquiredLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.acquired'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Lease Acquired'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-link yellow'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Lease acquired.'); 17 + } 18 + 19 + }
+19
src/applications/drydock/logtype/DrydockLeaseActivatedLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseActivatedLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.activated'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Lease Activated'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-link green'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Lease activated.'); 17 + } 18 + 19 + }
+19
src/applications/drydock/logtype/DrydockLeaseDestroyedLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseDestroyedLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.destroyed'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Lease Destroyed'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-link grey'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Lease destroyed.'); 17 + } 18 + 19 + }
+19
src/applications/drydock/logtype/DrydockLeaseQueuedLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseQueuedLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.queued'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Lease Queued'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-link blue'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Lease queued for acquisition.'); 17 + } 18 + 19 + }
+19
src/applications/drydock/logtype/DrydockLeaseReleasedLogType.php
··· 1 + <?php 2 + 3 + final class DrydockLeaseReleasedLogType extends DrydockLogType { 4 + 5 + const LOGCONST = 'core.lease.released'; 6 + 7 + public function getLogTypeName() { 8 + return pht('Lease Released'); 9 + } 10 + 11 + public function getLogTypeIcon(array $data) { 12 + return 'fa-link black'; 13 + } 14 + 15 + public function renderLog(array $data) { 16 + return pht('Lease released.'); 17 + } 18 + 19 + }
+69
src/applications/drydock/logtype/DrydockLogType.php
··· 1 + <?php 2 + 3 + abstract class DrydockLogType extends Phobject { 4 + 5 + private $viewer; 6 + private $log; 7 + 8 + abstract public function getLogTypeName(); 9 + abstract public function getLogTypeIcon(array $data); 10 + abstract public function renderLog(array $data); 11 + 12 + public function setViewer(PhabricatorUser $viewer) { 13 + $this->viewer = $viewer; 14 + return $this; 15 + } 16 + 17 + public function getViewer() { 18 + return $this->viewer; 19 + } 20 + 21 + final public function setLog(DrydockLog $log) { 22 + $this->log = $log; 23 + return $this; 24 + } 25 + 26 + final public function getLog() { 27 + return $this->log; 28 + } 29 + 30 + final public function getLogTypeConstant() { 31 + $class = new ReflectionClass($this); 32 + 33 + $const = $class->getConstant('LOGCONST'); 34 + if ($const === false) { 35 + throw new Exception( 36 + pht( 37 + '"%s" class "%s" must define a "%s" property.', 38 + __CLASS__, 39 + get_class($this), 40 + 'LOGCONST')); 41 + } 42 + 43 + $limit = self::getLogTypeConstantByteLimit(); 44 + if (!is_string($const) || (strlen($const) > $limit)) { 45 + throw new Exception( 46 + pht( 47 + '"%s" class "%s" has an invalid "%s" property. Field constants '. 48 + 'must be strings and no more than %s bytes in length.', 49 + __CLASS__, 50 + get_class($this), 51 + 'LOGCONST', 52 + new PhutilNumber($limit))); 53 + } 54 + 55 + return $const; 56 + } 57 + 58 + final private static function getLogTypeConstantByteLimit() { 59 + return 64; 60 + } 61 + 62 + final public static function getAllLogTypes() { 63 + return id(new PhutilClassMapQuery()) 64 + ->setAncestorClass(__CLASS__) 65 + ->setUniqueMethod('getLogTypeConstant') 66 + ->execute(); 67 + } 68 + 69 + }
+10 -4
src/applications/drydock/storage/DrydockLease.php
··· 144 144 'objectPHID' => $this->getPHID(), 145 145 )); 146 146 147 + $this->logEvent(DrydockLeaseQueuedLogType::LOGCONST); 148 + 147 149 return $this; 148 150 } 149 151 ··· 240 242 241 243 $this 242 244 ->setResourcePHID($resource->getPHID()) 245 + ->attachResource($resource) 243 246 ->setStatus($new_status) 244 247 ->save(); 245 248 ··· 250 253 251 254 $this->isAcquired = true; 252 255 256 + $this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST); 257 + 253 258 if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) { 254 259 $this->didActivate(); 255 260 } ··· 347 352 $viewer = PhabricatorUser::getOmnipotentUser(); 348 353 $need_update = false; 349 354 350 - // TODO: This is just a placeholder to get some data in the table. 351 - $this->logEvent('activated'); 355 + $this->logEvent(DrydockLeaseActivatedLogType::LOGCONST); 352 356 353 357 $commands = id(new DrydockCommandQuery()) 354 358 ->setViewer($viewer) ··· 382 386 383 387 $log->setLeasePHID($this->getPHID()); 384 388 385 - $resource = $this->getResource(); 386 - if ($resource) { 389 + $resource_phid = $this->getResourcePHID(); 390 + if ($resource_phid) { 391 + $resource = $this->getResource(); 392 + 387 393 $log->setResourcePHID($resource->getPHID()); 388 394 $log->setBlueprintPHID($resource->getBlueprintPHID()); 389 395 }
+42 -23
src/applications/drydock/view/DrydockLogListView.php
··· 16 16 17 17 $view = new PHUIObjectItemListView(); 18 18 19 + $types = DrydockLogType::getAllLogTypes(); 20 + 19 21 $rows = array(); 20 22 foreach ($logs as $log) { 21 23 $blueprint_phid = $log->getBlueprintPHID(); ··· 40 42 } 41 43 42 44 if ($log->isComplete()) { 43 - // TODO: This is a placeholder. 44 - $type = $log->getType(); 45 - $data = print_r($log->getData(), true); 45 + $type_key = $log->getType(); 46 + if (isset($types[$type_key])) { 47 + $type_object = id(clone $types[$type_key]) 48 + ->setLog($log) 49 + ->setViewer($viewer); 50 + 51 + $log_data = $log->getData(); 52 + 53 + $type = $type_object->getLogTypeName(); 54 + $icon = $type_object->getLogTypeIcon($log_data); 55 + $data = $type_object->renderLog($log_data); 56 + } else { 57 + $type = pht('<Unknown: %s>', $type_key); 58 + $data = null; 59 + $icon = 'fa-question-circle red'; 60 + } 46 61 } else { 47 62 $type = phutil_tag('em', array(), pht('Restricted')); 48 63 $data = phutil_tag( 49 64 'em', 50 65 array(), 51 66 pht('You do not have permission to view this log event.')); 67 + $icon = 'fa-lock grey'; 52 68 } 53 69 54 70 $rows[] = array( 55 71 $blueprint, 56 72 $resource, 57 73 $lease, 74 + id(new PHUIIconView())->setIconFont($icon), 58 75 $type, 59 76 $data, 60 77 phabricator_datetime($log->getEpoch(), $viewer), 61 78 ); 62 79 } 63 80 64 - $table = new AphrontTableView($rows); 65 - $table->setDeviceReadyTable(true); 66 - $table->setHeaders( 67 - array( 68 - pht('Blueprint'), 69 - pht('Resource'), 70 - pht('Lease'), 71 - pht('Type'), 72 - pht('Data'), 73 - pht('Date'), 74 - )); 75 - $table->setColumnClasses( 76 - array( 77 - '', 78 - '', 79 - '', 80 - '', 81 - 'wide', 82 - '', 83 - )); 81 + $table = id(new AphrontTableView($rows)) 82 + ->setDeviceReadyTable(true) 83 + ->setHeaders( 84 + array( 85 + pht('Blueprint'), 86 + pht('Resource'), 87 + pht('Lease'), 88 + null, 89 + pht('Type'), 90 + pht('Data'), 91 + pht('Date'), 92 + )) 93 + ->setColumnClasses( 94 + array( 95 + '', 96 + '', 97 + '', 98 + 'icon', 99 + '', 100 + 'wide', 101 + '', 102 + )); 84 103 85 104 return $table; 86 105 }
+2
src/applications/drydock/worker/DrydockLeaseDestroyWorker.php
··· 32 32 $lease 33 33 ->setStatus(DrydockLeaseStatus::STATUS_DESTROYED) 34 34 ->save(); 35 + 36 + $lease->logEvent(DrydockLeaseDestroyedLogType::LOGCONST); 35 37 } 36 38 37 39 }
+2
src/applications/drydock/worker/DrydockLeaseUpdateWorker.php
··· 74 74 'objectPHID' => $lease->getPHID(), 75 75 )); 76 76 77 + $lease->logEvent(DrydockLeaseReleasedLogType::LOGCONST); 78 + 77 79 $resource = $lease->getResource(); 78 80 $blueprint = $resource->getBlueprint(); 79 81