Path: blob/master/src/applications/owners/storage/PhabricatorOwnersOwner.php
12256 views
<?php12final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {34protected $packageID;56// this can be a project or a user. We assume that all members of a project7// owner also own the package; use the loadAffiliatedUserPHIDs method if8// you want to recursively grab all user ids that own a package9protected $userPHID;1011protected function getConfiguration() {12return array(13self::CONFIG_TIMESTAMPS => false,14self::CONFIG_KEY_SCHEMA => array(15'packageID' => array(16'columns' => array('packageID', 'userPHID'),17'unique' => true,18),19'userPHID' => array(20'columns' => array('userPHID'),21),22),23) + parent::getConfiguration();24}2526public static function loadAllForPackages(array $packages) {27assert_instances_of($packages, 'PhabricatorOwnersPackage');28if (!$packages) {29return array();30}31return id(new PhabricatorOwnersOwner())->loadAllWhere(32'packageID IN (%Ls)',33mpull($packages, 'getID'));34}3536// Loads all user phids affiliated with a set of packages. This includes both37// user owners and all members of any project owners38public static function loadAffiliatedUserPHIDs(array $package_ids) {39if (!$package_ids) {40return array();41}4243$owners = id(new PhabricatorOwnersOwner())->loadAllWhere(44'packageID IN (%Ls)',45$package_ids);4647$type_user = PhabricatorPeopleUserPHIDType::TYPECONST;48$type_project = PhabricatorProjectProjectPHIDType::TYPECONST;4950$user_phids = array();51$project_phids = array();52foreach ($owners as $owner) {53$owner_phid = $owner->getUserPHID();54switch (phid_get_type($owner_phid)) {55case PhabricatorPeopleUserPHIDType::TYPECONST:56$user_phids[] = $owner_phid;57break;58case PhabricatorProjectProjectPHIDType::TYPECONST:59$project_phids[] = $owner_phid;60break;61}62}6364if ($project_phids) {65$projects = id(new PhabricatorProjectQuery())66->setViewer(PhabricatorUser::getOmnipotentUser())67->withPHIDs($project_phids)68->needMembers(true)69->execute();70foreach ($projects as $project) {71foreach ($project->getMemberPHIDs() as $member_phid) {72$user_phids[] = $member_phid;73}74}75}7677$user_phids = array_fuse($user_phids);78return array_values($user_phids);79}80}818283