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

Support export of user activity logs

Summary:
Depends on D18966. Ref T13049. Adds export support to user activity logs.

These don't have PHIDs. We could add them, but just make the "phid" column test if the objects have PHIDs or not for now.

Test Plan:
- Exported user activity logs, got sensible output (with no PHIDs).
- Exported some users to make sure I didn't break PHIDs, got an export with PHIDs.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

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

+119 -7
+3 -2
src/applications/people/application/PhabricatorPeopleApplication.php
··· 42 42 return array( 43 43 '/people/' => array( 44 44 $this->getQueryRoutePattern() => 'PhabricatorPeopleListController', 45 - 'logs/(?:query/(?P<queryKey>[^/]+)/)?' 46 - => 'PhabricatorPeopleLogsController', 45 + 'logs/' => array( 46 + $this->getQueryRoutePattern() => 'PhabricatorPeopleLogsController', 47 + ), 47 48 'invite/' => array( 48 49 '(?:query/(?P<queryKey>[^/]+)/)?' 49 50 => 'PhabricatorPeopleInviteListController',
+98
src/applications/people/query/PhabricatorPeopleLogSearchEngine.php
··· 128 128 return id(new PhabricatorApplicationSearchResultView()) 129 129 ->setTable($table); 130 130 } 131 + 132 + protected function newExportFields() { 133 + $viewer = $this->requireViewer(); 134 + 135 + $fields = array( 136 + $fields[] = id(new PhabricatorPHIDExportField()) 137 + ->setKey('actorPHID') 138 + ->setLabel(pht('Actor PHID')), 139 + $fields[] = id(new PhabricatorStringExportField()) 140 + ->setKey('actor') 141 + ->setLabel(pht('Actor')), 142 + $fields[] = id(new PhabricatorPHIDExportField()) 143 + ->setKey('userPHID') 144 + ->setLabel(pht('User PHID')), 145 + $fields[] = id(new PhabricatorStringExportField()) 146 + ->setKey('user') 147 + ->setLabel(pht('User')), 148 + $fields[] = id(new PhabricatorStringExportField()) 149 + ->setKey('action') 150 + ->setLabel(pht('Action')), 151 + $fields[] = id(new PhabricatorStringExportField()) 152 + ->setKey('actionName') 153 + ->setLabel(pht('Action Name')), 154 + $fields[] = id(new PhabricatorStringExportField()) 155 + ->setKey('session') 156 + ->setLabel(pht('Session')), 157 + $fields[] = id(new PhabricatorStringExportField()) 158 + ->setKey('old') 159 + ->setLabel(pht('Old Value')), 160 + $fields[] = id(new PhabricatorStringExportField()) 161 + ->setKey('new') 162 + ->setLabel(pht('New Value')), 163 + ); 164 + 165 + if ($viewer->getIsAdmin()) { 166 + $fields[] = id(new PhabricatorStringExportField()) 167 + ->setKey('remoteAddress') 168 + ->setLabel(pht('Remote Address')); 169 + } 170 + 171 + return $fields; 172 + } 173 + 174 + protected function newExportData(array $logs) { 175 + $viewer = $this->requireViewer(); 176 + 177 + 178 + $phids = array(); 179 + foreach ($logs as $log) { 180 + $phids[] = $log->getUserPHID(); 181 + $phids[] = $log->getActorPHID(); 182 + } 183 + $handles = $viewer->loadHandles($phids); 184 + 185 + $action_map = PhabricatorUserLog::getActionTypeMap(); 186 + 187 + $export = array(); 188 + foreach ($logs as $log) { 189 + 190 + $user_phid = $log->getUserPHID(); 191 + if ($user_phid) { 192 + $user_name = $handles[$user_phid]->getName(); 193 + } else { 194 + $user_name = null; 195 + } 196 + 197 + $actor_phid = $log->getActorPHID(); 198 + if ($actor_phid) { 199 + $actor_name = $handles[$actor_phid]->getName(); 200 + } else { 201 + $actor_name = null; 202 + } 203 + 204 + $action = $log->getAction(); 205 + $action_name = idx($action_map, $action, pht('Unknown ("%s")', $action)); 206 + 207 + $map = array( 208 + 'actorPHID' => $actor_phid, 209 + 'actor' => $actor_name, 210 + 'userPHID' => $user_phid, 211 + 'user' => $user_name, 212 + 'action' => $action, 213 + 'actionName' => $action_name, 214 + 'session' => substr($log->getSession(), 0, 6), 215 + 'old' => $log->getOldValue(), 216 + 'new' => $log->getNewValue(), 217 + ); 218 + 219 + if ($viewer->getIsAdmin()) { 220 + $map['remoteAddress'] = $log->getRemoteAddr(); 221 + } 222 + 223 + $export[] = $map; 224 + } 225 + 226 + return $export; 227 + } 228 + 131 229 }
+18 -5
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 1455 1455 } 1456 1456 1457 1457 final public function newExportFieldList() { 1458 + $object = $this->newResultObject(); 1459 + 1458 1460 $builtin_fields = array( 1459 1461 id(new PhabricatorIDExportField()) 1460 1462 ->setKey('id') 1461 1463 ->setLabel(pht('ID')), 1462 - id(new PhabricatorPHIDExportField()) 1464 + ); 1465 + 1466 + if ($object->getConfigOption(LiskDAO::CONFIG_AUX_PHID)) { 1467 + $builtin_fields[] = id(new PhabricatorPHIDExportField()) 1463 1468 ->setKey('phid') 1464 - ->setLabel(pht('PHID')), 1465 - ); 1469 + ->setLabel(pht('PHID')); 1470 + } 1466 1471 1467 1472 $fields = mpull($builtin_fields, null, 'getKey'); 1468 1473 ··· 1507 1512 } 1508 1513 1509 1514 final public function newExport(array $objects) { 1515 + $object = $this->newResultObject(); 1516 + $has_phid = $object->getConfigOption(LiskDAO::CONFIG_AUX_PHID); 1517 + 1510 1518 $objects = array_values($objects); 1511 1519 $n = count($objects); 1512 1520 1513 1521 $maps = array(); 1514 1522 foreach ($objects as $object) { 1515 - $maps[] = array( 1523 + $map = array( 1516 1524 'id' => $object->getID(), 1517 - 'phid' => $object->getPHID(), 1518 1525 ); 1526 + 1527 + if ($has_phid) { 1528 + $map['phid'] = $object->getPHID(); 1529 + } 1530 + 1531 + $maps[] = $map; 1519 1532 } 1520 1533 1521 1534 $export_data = $this->newExportData($objects);