Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/owners/storage/PhabricatorOwnersOwner.php
12256 views
1
<?php
2
3
final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
4
5
protected $packageID;
6
7
// this can be a project or a user. We assume that all members of a project
8
// owner also own the package; use the loadAffiliatedUserPHIDs method if
9
// you want to recursively grab all user ids that own a package
10
protected $userPHID;
11
12
protected function getConfiguration() {
13
return array(
14
self::CONFIG_TIMESTAMPS => false,
15
self::CONFIG_KEY_SCHEMA => array(
16
'packageID' => array(
17
'columns' => array('packageID', 'userPHID'),
18
'unique' => true,
19
),
20
'userPHID' => array(
21
'columns' => array('userPHID'),
22
),
23
),
24
) + parent::getConfiguration();
25
}
26
27
public static function loadAllForPackages(array $packages) {
28
assert_instances_of($packages, 'PhabricatorOwnersPackage');
29
if (!$packages) {
30
return array();
31
}
32
return id(new PhabricatorOwnersOwner())->loadAllWhere(
33
'packageID IN (%Ls)',
34
mpull($packages, 'getID'));
35
}
36
37
// Loads all user phids affiliated with a set of packages. This includes both
38
// user owners and all members of any project owners
39
public static function loadAffiliatedUserPHIDs(array $package_ids) {
40
if (!$package_ids) {
41
return array();
42
}
43
44
$owners = id(new PhabricatorOwnersOwner())->loadAllWhere(
45
'packageID IN (%Ls)',
46
$package_ids);
47
48
$type_user = PhabricatorPeopleUserPHIDType::TYPECONST;
49
$type_project = PhabricatorProjectProjectPHIDType::TYPECONST;
50
51
$user_phids = array();
52
$project_phids = array();
53
foreach ($owners as $owner) {
54
$owner_phid = $owner->getUserPHID();
55
switch (phid_get_type($owner_phid)) {
56
case PhabricatorPeopleUserPHIDType::TYPECONST:
57
$user_phids[] = $owner_phid;
58
break;
59
case PhabricatorProjectProjectPHIDType::TYPECONST:
60
$project_phids[] = $owner_phid;
61
break;
62
}
63
}
64
65
if ($project_phids) {
66
$projects = id(new PhabricatorProjectQuery())
67
->setViewer(PhabricatorUser::getOmnipotentUser())
68
->withPHIDs($project_phids)
69
->needMembers(true)
70
->execute();
71
foreach ($projects as $project) {
72
foreach ($project->getMemberPHIDs() as $member_phid) {
73
$user_phids[] = $member_phid;
74
}
75
}
76
}
77
78
$user_phids = array_fuse($user_phids);
79
return array_values($user_phids);
80
}
81
}
82
83