Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/doorkeeper/engine/DoorkeeperImportEngine.php b/src/applications/doorkeeper/engine/DoorkeeperImportEngine.php
index 7bc65b6230..f4cf151a97 100644
--- a/src/applications/doorkeeper/engine/DoorkeeperImportEngine.php
+++ b/src/applications/doorkeeper/engine/DoorkeeperImportEngine.php
@@ -1,107 +1,113 @@
<?php
final class DoorkeeperImportEngine extends Phobject {
private $viewer;
private $refs = array();
private $phids = array();
private $localOnly;
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
}
public function getViewer() {
return $this->viewer;
}
public function setRefs(array $refs) {
assert_instances_of($refs, 'DoorkeeperObjectRef');
$this->refs = $refs;
return $this;
}
public function getRefs() {
return $this->refs;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function needLocalOnly($local_only) {
$this->localOnly = $local_only;
return $this;
}
public function execute() {
$refs = $this->getRefs();
$viewer = $this->getViewer();
$keys = mpull($refs, 'getObjectKey');
if ($keys) {
$xobjs = id(new DoorkeeperExternalObjectQuery())
->setViewer($viewer)
->withObjectKeys($keys)
->execute();
$xobjs = mpull($xobjs, null, 'getObjectKey');
foreach ($refs as $ref) {
$xobj = idx($xobjs, $ref->getObjectKey());
if (!$xobj) {
$xobj = $ref
->newExternalObject()
->setImporterPHID($viewer->getPHID());
+
+ // NOTE: Fill the new external object into the object map, so we'll
+ // reference the same external object if more than one ref is the
+ // same. This prevents issues later where we double-populate
+ // external objects when handed duplicate refs.
+ $xobjs[$ref->getObjectKey()] = $xobj;
}
$ref->attachExternalObject($xobj);
}
}
if ($this->phids) {
$xobjs = id(new DoorkeeperExternalObjectQuery())
->setViewer($viewer)
->withPHIDs($this->phids)
->execute();
foreach ($xobjs as $xobj) {
$ref = $xobj->getRef();
$ref->attachExternalObject($xobj);
$refs[$ref->getObjectKey()] = $ref;
}
}
if (!$this->localOnly) {
$bridges = id(new PhutilSymbolLoader())
->setAncestorClass('DoorkeeperBridge')
->loadObjects();
foreach ($bridges as $key => $bridge) {
if (!$bridge->isEnabled()) {
unset($bridges[$key]);
}
$bridge->setViewer($viewer);
}
$working_set = $refs;
foreach ($bridges as $bridge) {
$bridge_refs = array();
foreach ($working_set as $key => $ref) {
if ($bridge->canPullRef($ref)) {
$bridge_refs[$key] = $ref;
unset($working_set[$key]);
}
}
if ($bridge_refs) {
$bridge->pullRefs($bridge_refs);
}
}
}
return $refs;
}
public function executeOne() {
return head($this->execute());
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 18:34 (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1127481
Default Alt Text
(3 KB)

Event Timeline