[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DoorkeeperImportEngine extends Phobject { 4 5 private $viewer; 6 private $refs = array(); 7 private $phids = array(); 8 private $localOnly; 9 private $throwOnMissingLink; 10 11 public function setViewer(PhabricatorUser $viewer) { 12 $this->viewer = $viewer; 13 return $this; 14 } 15 16 public function getViewer() { 17 return $this->viewer; 18 } 19 20 public function setRefs(array $refs) { 21 assert_instances_of($refs, 'DoorkeeperObjectRef'); 22 $this->refs = $refs; 23 return $this; 24 } 25 26 public function getRefs() { 27 return $this->refs; 28 } 29 30 public function withPHIDs(array $phids) { 31 $this->phids = $phids; 32 return $this; 33 } 34 35 public function needLocalOnly($local_only) { 36 $this->localOnly = $local_only; 37 return $this; 38 } 39 40 41 /** 42 * Configure behavior if remote refs can not be retrieved because an 43 * authentication link is missing. 44 */ 45 public function setThrowOnMissingLink($throw) { 46 $this->throwOnMissingLink = $throw; 47 return $this; 48 } 49 50 public function execute() { 51 $refs = $this->getRefs(); 52 $viewer = $this->getViewer(); 53 54 $keys = mpull($refs, 'getObjectKey'); 55 if ($keys) { 56 $xobjs = id(new DoorkeeperExternalObjectQuery()) 57 ->setViewer($viewer) 58 ->withObjectKeys($keys) 59 ->execute(); 60 $xobjs = mpull($xobjs, null, 'getObjectKey'); 61 foreach ($refs as $ref) { 62 $xobj = idx($xobjs, $ref->getObjectKey()); 63 if (!$xobj) { 64 $xobj = $ref 65 ->newExternalObject() 66 ->setImporterPHID($viewer->getPHID()); 67 68 // NOTE: Fill the new external object into the object map, so we'll 69 // reference the same external object if more than one ref is the 70 // same. This prevents issues later where we double-populate 71 // external objects when handed duplicate refs. 72 $xobjs[$ref->getObjectKey()] = $xobj; 73 } 74 $ref->attachExternalObject($xobj); 75 } 76 } 77 78 if ($this->phids) { 79 $xobjs = id(new DoorkeeperExternalObjectQuery()) 80 ->setViewer($viewer) 81 ->withPHIDs($this->phids) 82 ->execute(); 83 foreach ($xobjs as $xobj) { 84 $ref = $xobj->getRef(); 85 $ref->attachExternalObject($xobj); 86 $refs[$ref->getObjectKey()] = $ref; 87 } 88 } 89 90 if (!$this->localOnly) { 91 $bridges = id(new PhutilSymbolLoader()) 92 ->setAncestorClass('DoorkeeperBridge') 93 ->loadObjects(); 94 95 foreach ($bridges as $key => $bridge) { 96 if (!$bridge->isEnabled()) { 97 unset($bridges[$key]); 98 } 99 $bridge->setViewer($viewer); 100 $bridge->setThrowOnMissingLink($this->throwOnMissingLink); 101 } 102 103 $working_set = $refs; 104 foreach ($bridges as $bridge) { 105 $bridge_refs = array(); 106 foreach ($working_set as $key => $ref) { 107 if ($bridge->canPullRef($ref)) { 108 $bridge_refs[$key] = $ref; 109 unset($working_set[$key]); 110 } 111 } 112 if ($bridge_refs) { 113 $bridge->pullRefs($bridge_refs); 114 } 115 } 116 } 117 118 return $refs; 119 } 120 121 public function executeOne() { 122 return head($this->execute()); 123 } 124 125 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |