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

Define common ID and PHID export fields in SearchEngine

Summary:
Ref T13049. All exportable objects should always have these fields, so make them builtins.

This also sets things up for extensions (like custom fields).

Test Plan: Exported user data, got the same export as before.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13049

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

+66 -30
+1 -9
src/applications/diffusion/query/DiffusionPullLogSearchEngine.php
··· 49 49 50 50 protected function newExportFields() { 51 51 return array( 52 - id(new PhabricatorIDExportField()) 53 - ->setKey('id') 54 - ->setLabel(pht('ID')), 55 - id(new PhabricatorPHIDExportField()) 56 - ->setKey('phid') 57 - ->setLabel(pht('PHID')), 58 52 id(new PhabricatorPHIDExportField()) 59 53 ->setKey('repositoryPHID') 60 54 ->setLabel(pht('Repository PHID')), ··· 82 76 ); 83 77 } 84 78 85 - public function newExport(array $events) { 79 + protected function newExportData(array $events) { 86 80 $viewer = $this->requireViewer(); 87 81 88 82 $phids = array(); ··· 112 106 } 113 107 114 108 $export[] = array( 115 - 'id' => $event->getID(), 116 - 'phid' => $event->getPHID(), 117 109 'repositoryPHID' => $repository_phid, 118 110 'repository' => $repository_name, 119 111 'pullerPHID' => $puller_phid,
+1 -9
src/applications/people/query/PhabricatorPeopleSearchEngine.php
··· 322 322 323 323 protected function newExportFields() { 324 324 return array( 325 - id(new PhabricatorIDExportField()) 326 - ->setKey('id') 327 - ->setLabel(pht('ID')), 328 - id(new PhabricatorPHIDExportField()) 329 - ->setKey('phid') 330 - ->setLabel(pht('PHID')), 331 325 id(new PhabricatorStringExportField()) 332 326 ->setKey('username') 333 327 ->setLabel(pht('Username')), ··· 340 334 ); 341 335 } 342 336 343 - public function newExport(array $users) { 337 + protected function newExportData(array $users) { 344 338 $viewer = $this->requireViewer(); 345 339 346 340 $export = array(); 347 341 foreach ($users as $user) { 348 342 $export[] = array( 349 - 'id' => $user->getID(), 350 - 'phid' => $user->getPHID(), 351 343 'username' => $user->getUsername(), 352 344 'realName' => $user->getRealName(), 353 345 'created' => $user->getDateCreated(),
-11
src/applications/search/controller/PhabricatorApplicationSearchController.php
··· 449 449 $format->setViewer($viewer); 450 450 451 451 $export_data = $engine->newExport($objects); 452 - 453 - if (count($export_data) !== count($objects)) { 454 - throw new Exception( 455 - pht( 456 - 'Search engine exported the wrong number of objects, expected '. 457 - '%s but got %s.', 458 - phutil_count($objects), 459 - phutil_count($export_data))); 460 - } 461 - 462 452 $objects = array_values($objects); 463 - $export_data = array_values($export_data); 464 453 465 454 $field_list = $engine->newExportFieldList(); 466 455 $field_list = mpull($field_list, null, 'getKey');
+64 -1
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 1455 1455 } 1456 1456 1457 1457 final public function newExportFieldList() { 1458 - return $this->newExportFields(); 1458 + $builtin_fields = array( 1459 + id(new PhabricatorIDExportField()) 1460 + ->setKey('id') 1461 + ->setLabel(pht('ID')), 1462 + id(new PhabricatorPHIDExportField()) 1463 + ->setKey('phid') 1464 + ->setLabel(pht('PHID')), 1465 + ); 1466 + 1467 + $fields = mpull($builtin_fields, null, 'getKey'); 1468 + 1469 + $export_fields = $this->newExportFields(); 1470 + foreach ($export_fields as $export_field) { 1471 + $key = $export_field->getKey(); 1472 + 1473 + if (isset($fields[$key])) { 1474 + throw new Exception( 1475 + pht( 1476 + 'Search engine ("%s") defines an export field with a key ("%s") '. 1477 + 'that collides with another field. Each field must have a '. 1478 + 'unique key.', 1479 + get_class($this), 1480 + $key)); 1481 + } 1482 + 1483 + $fields[$key] = $export_field; 1484 + } 1485 + 1486 + return $fields; 1487 + } 1488 + 1489 + final public function newExport(array $objects) { 1490 + $objects = array_values($objects); 1491 + $n = count($objects); 1492 + 1493 + $maps = array(); 1494 + foreach ($objects as $object) { 1495 + $maps[] = array( 1496 + 'id' => $object->getID(), 1497 + 'phid' => $object->getPHID(), 1498 + ); 1499 + } 1500 + 1501 + $export_data = $this->newExportData($objects); 1502 + $export_data = array_values($export_data); 1503 + if (count($export_data) !== count($objects)) { 1504 + throw new Exception( 1505 + pht( 1506 + 'Search engine ("%s") exported the wrong number of objects, '. 1507 + 'expected %s but got %s.', 1508 + get_class($this), 1509 + phutil_count($objects), 1510 + phutil_count($export_data))); 1511 + } 1512 + 1513 + for ($ii = 0; $ii < $n; $ii++) { 1514 + $maps[$ii] += $export_data[$ii]; 1515 + } 1516 + 1517 + return $maps; 1459 1518 } 1460 1519 1461 1520 protected function newExportFields() { 1462 1521 return array(); 1522 + } 1523 + 1524 + protected function newExportData(array $objects) { 1525 + throw new PhutilMethodNotImplementedException(); 1463 1526 } 1464 1527 1465 1528 }