2011-04-03 14:48:36 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-13 16:21:04 -07:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-04-03 14:48:36 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-13 16:21:04 -07:00
|
|
|
final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
|
2011-04-03 14:48:36 -07:00
|
|
|
|
|
|
|
protected $packageID;
|
2012-03-30 15:46:32 -07:00
|
|
|
|
|
|
|
// this can be a project or a user. We assume that all members of a project
|
|
|
|
// owner also own the package; use the loadAffiliatedUserPHIDs method if
|
|
|
|
// you want to recursively grab all user ids that own a package
|
2011-04-03 14:48:36 -07:00
|
|
|
protected $userPHID;
|
|
|
|
|
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
2011-04-03 22:03:27 -07:00
|
|
|
) + parent::getConfiguration();
|
2011-04-03 14:48:36 -07:00
|
|
|
}
|
|
|
|
|
2011-04-03 23:23:36 -07:00
|
|
|
public static function loadAllForPackages(array $packages) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($packages, 'PhabricatorOwnersPackage');
|
2011-04-03 23:23:36 -07:00
|
|
|
if (!$packages) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
return id(new PhabricatorOwnersOwner())->loadAllWhere(
|
|
|
|
'packageID IN (%Ls)',
|
|
|
|
mpull($packages, 'getID'));
|
|
|
|
}
|
|
|
|
|
2012-03-30 15:46:32 -07:00
|
|
|
// Loads all user phids affiliated with a set of packages. This includes both
|
|
|
|
// user owners and all members of any project owners
|
|
|
|
public static function loadAffiliatedUserPHIDs(array $package_ids) {
|
2012-04-05 15:19:58 -07:00
|
|
|
if (!$package_ids) {
|
|
|
|
return array();
|
|
|
|
}
|
2012-03-30 15:46:32 -07:00
|
|
|
$owners = id(new PhabricatorOwnersOwner())->loadAllWhere(
|
|
|
|
'packageID IN (%Ls)',
|
|
|
|
$package_ids);
|
|
|
|
|
|
|
|
$all_phids = phid_group_by_type(mpull($owners, 'getUserPHID'));
|
|
|
|
|
|
|
|
$user_phids = idx($all_phids,
|
|
|
|
PhabricatorPHIDConstants::PHID_TYPE_USER,
|
|
|
|
array());
|
|
|
|
|
|
|
|
$users_in_project_phids = array();
|
2012-08-07 18:02:05 -07:00
|
|
|
$project_phids = idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ);
|
|
|
|
if ($project_phids) {
|
|
|
|
$query = id(new PhabricatorEdgeQuery())
|
|
|
|
->withSourcePHIDs($project_phids)
|
|
|
|
->withEdgeTypes(array(PhabricatorEdgeConfig::TYPE_PROJ_MEMBER));
|
|
|
|
$query->execute();
|
|
|
|
$users_in_project_phids = $query->getDestinationPHIDs();
|
2012-03-30 15:46:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return array_unique(array_merge($users_in_project_phids, $user_phids));
|
|
|
|
}
|
2011-04-03 14:48:36 -07:00
|
|
|
}
|