Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phid/query/PhabricatorObjectListQuery.php
| Show All 39 Lines | final class PhabricatorObjectListQuery extends Phobject { | ||||
| } | } | ||||
| public function getObjectList() { | public function getObjectList() { | ||||
| return $this->objectList; | return $this->objectList; | ||||
| } | } | ||||
| public function execute() { | public function execute() { | ||||
| $names = $this->getObjectList(); | $names = $this->getObjectList(); | ||||
| $names = array_unique(array_filter(preg_split('/[\s,]+/', $names))); | |||||
| $objects = $this->loadObjects($names); | // First, normalize any internal whitespace so we don't get weird results | ||||
| // if linebreaks hit in weird spots. | |||||
| $names = preg_replace('/\s+/', ' ', $names); | |||||
| // Split the list on commas. | |||||
| $names = explode(',', $names); | |||||
| // Trim and remove empty tokens. | |||||
| foreach ($names as $key => $name) { | |||||
| $name = trim($name); | |||||
| if (!strlen($name)) { | |||||
| unset($names[$key]); | |||||
| continue; | |||||
| } | |||||
| $names[$key] = $name; | |||||
| } | |||||
| // Remove duplicates. | |||||
| $names = array_unique($names); | |||||
| $name_map = array(); | |||||
| foreach ($names as $name) { | |||||
| $parts = explode(' ', $name); | |||||
| // If this looks like a monogram, ignore anything after the first token. | |||||
| // This allows us to parse "O123 Package Name" as though it was "O123", | |||||
| // which we can look up. | |||||
| if (preg_match('/^[A-Z]\d+\z/', $parts[0])) { | |||||
| $name_map[$parts[0]] = $name; | |||||
| } else { | |||||
| // For anything else, split it on spaces and use each token as a | |||||
| // value. This means "alincoln htaft", separated with a space instead | |||||
| // of with a comma, is two different users. | |||||
| foreach ($parts as $part) { | |||||
| $name_map[$part] = $part; | |||||
| } | |||||
| } | |||||
| } | |||||
| $objects = $this->loadObjects(array_keys($name_map)); | |||||
| $types = array(); | $types = array(); | ||||
| foreach ($objects as $name => $object) { | foreach ($objects as $name => $object) { | ||||
| $types[phid_get_type($object->getPHID())][] = $name; | $types[phid_get_type($object->getPHID())][] = $name; | ||||
| } | } | ||||
| $invalid = array(); | $invalid = array(); | ||||
| if ($this->getAllowedTypes()) { | if ($this->getAllowedTypes()) { | ||||
| $allowed = array_fuse($this->getAllowedTypes()); | $allowed = array_fuse($this->getAllowedTypes()); | ||||
| foreach ($types as $type => $names_of_type) { | foreach ($types as $type => $names_of_type) { | ||||
| if (empty($allowed[$type])) { | if (empty($allowed[$type])) { | ||||
| $invalid[] = $names_of_type; | $invalid[] = $names_of_type; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $invalid = array_mergev($invalid); | $invalid = array_mergev($invalid); | ||||
| $missing = array(); | $missing = array(); | ||||
| foreach ($names as $name) { | foreach ($name_map as $key => $name) { | ||||
| if (empty($objects[$name])) { | if (empty($objects[$key])) { | ||||
| $missing[] = $name; | $missing[] = $name; | ||||
| } | } | ||||
| } | } | ||||
| // NOTE: We could couple this less tightly with Differential, but it is | // NOTE: We could couple this less tightly with Differential, but it is | ||||
| // currently the only thing that uses it, and we'd have to add a lot of | // currently the only thing that uses it, and we'd have to add a lot of | ||||
| // extra API to loosen this. It's not clear that this will be useful | // extra API to loosen this. It's not clear that this will be useful | ||||
| // elsewhere any time soon, so let's cross that bridge when we come to it. | // elsewhere any time soon, so let's cross that bridge when we come to it. | ||||
| ▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines | |||||