Skip to content

Commit 274f9f2

Browse files
committed
Plugin: Azure: Move methods to parent class - refs BT#21930
1 parent 90588f2 commit 274f9f2

File tree

3 files changed

+100
-100
lines changed

3 files changed

+100
-100
lines changed

plugin/azure_active_directory/src/AzureCommand.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,106 @@ protected function generateOrRefreshToken(?AccessTokenInterface &$token)
3737
}
3838
}
3939

40+
/**
41+
* @throws Exception
42+
*
43+
* @return Generator<int, array<string, string>>
44+
*/
45+
protected function getAzureUsers(): Generator
46+
{
47+
$userFields = [
48+
'givenName',
49+
'surname',
50+
'mail',
51+
'userPrincipalName',
52+
'businessPhones',
53+
'mobilePhone',
54+
'accountEnabled',
55+
'mailNickname',
56+
'id',
57+
];
58+
59+
$query = sprintf(
60+
'$top=%d&$select=%s',
61+
AzureActiveDirectory::API_PAGE_SIZE,
62+
implode(',', $userFields)
63+
);
64+
65+
$token = null;
66+
67+
do {
68+
$this->generateOrRefreshToken($token);
69+
70+
try {
71+
$azureUsersRequest = $this->provider->request(
72+
'get',
73+
"users?$query",
74+
$token
75+
);
76+
} catch (Exception $e) {
77+
throw new Exception('Exception when requesting users from Azure: '.$e->getMessage());
78+
}
79+
80+
$azureUsersInfo = $azureUsersRequest['value'] ?? [];
81+
82+
foreach ($azureUsersInfo as $azureUserInfo) {
83+
yield $azureUserInfo;
84+
}
85+
86+
$hasNextLink = false;
87+
88+
if (!empty($azureUsersRequest['@odata.nextLink'])) {
89+
$hasNextLink = true;
90+
$query = parse_url($azureUsersRequest['@odata.nextLink'], PHP_URL_QUERY);
91+
}
92+
} while ($hasNextLink);
93+
}
94+
95+
/**
96+
* @throws Exception
97+
*
98+
* @return Generator<int, array<string, string>>
99+
*/
100+
protected function getAzureGroups(): Generator
101+
{
102+
$groupFields = [
103+
'id',
104+
'displayName',
105+
'description',
106+
];
107+
108+
$query = sprintf(
109+
'$top=%d&$select=%s',
110+
AzureActiveDirectory::API_PAGE_SIZE,
111+
implode(',', $groupFields)
112+
);
113+
114+
$token = null;
115+
116+
do {
117+
$this->generateOrRefreshToken($token);
118+
119+
try {
120+
$azureGroupsRequest = $this->provider->request('get', "groups?$query", $token);
121+
} catch (Exception $e) {
122+
throw new Exception('Exception when requesting groups from Azure: '.$e->getMessage());
123+
}
124+
125+
$azureGroupsInfo = $azureGroupsRequest['value'] ?? [];
126+
127+
foreach ($azureGroupsInfo as $azureGroupInfo) {
128+
yield $azureGroupInfo;
129+
}
130+
131+
$hasNextLink = false;
132+
133+
if (!empty($azureGroupsRequest['@odata.nextLink'])) {
134+
$hasNextLink = true;
135+
$query = parse_url($azureGroupsRequest['@odata.nextLink'], PHP_URL_QUERY);
136+
}
137+
} while ($hasNextLink);
138+
}
139+
40140
/**
41141
* @return Generator<int, array<string, string>>
42142
*

plugin/azure_active_directory/src/AzureSyncUsergroupsCommand.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -67,49 +67,4 @@ public function __invoke(): Generator
6767
}
6868
}
6969
}
70-
71-
/**
72-
* @throws Exception
73-
*
74-
* @return Generator<int, array<string, string>>
75-
*/
76-
private function getAzureGroups(): Generator
77-
{
78-
$groupFields = [
79-
'id',
80-
'displayName',
81-
'description',
82-
];
83-
84-
$query = sprintf(
85-
'$top=%d&$select=%s',
86-
AzureActiveDirectory::API_PAGE_SIZE,
87-
implode(',', $groupFields)
88-
);
89-
90-
$token = null;
91-
92-
do {
93-
$this->generateOrRefreshToken($token);
94-
95-
try {
96-
$azureGroupsRequest = $this->provider->request('get', "groups?$query", $token);
97-
} catch (Exception $e) {
98-
throw new Exception('Exception when requesting groups from Azure: '.$e->getMessage());
99-
}
100-
101-
$azureGroupsInfo = $azureGroupsRequest['value'] ?? [];
102-
103-
foreach ($azureGroupsInfo as $azureGroupInfo) {
104-
yield $azureGroupInfo;
105-
}
106-
107-
$hasNextLink = false;
108-
109-
if (!empty($azureGroupsRequest['@odata.nextLink'])) {
110-
$hasNextLink = true;
111-
$query = parse_url($azureGroupsRequest['@odata.nextLink'], PHP_URL_QUERY);
112-
}
113-
} while ($hasNextLink);
114-
}
11570
}

plugin/azure_active_directory/src/AzureSyncUsersCommand.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -88,59 +88,4 @@ function ($user) {
8888
);
8989
}
9090
}
91-
92-
/**
93-
* @throws Exception
94-
*
95-
* @return Generator<int, array<string, string>>
96-
*/
97-
private function getAzureUsers(): Generator
98-
{
99-
$userFields = [
100-
'givenName',
101-
'surname',
102-
'mail',
103-
'userPrincipalName',
104-
'businessPhones',
105-
'mobilePhone',
106-
'accountEnabled',
107-
'mailNickname',
108-
'id',
109-
];
110-
111-
$query = sprintf(
112-
'$top=%d&$select=%s',
113-
AzureActiveDirectory::API_PAGE_SIZE,
114-
implode(',', $userFields)
115-
);
116-
117-
$token = null;
118-
119-
do {
120-
$this->generateOrRefreshToken($token);
121-
122-
try {
123-
$azureUsersRequest = $this->provider->request(
124-
'get',
125-
"users?$query",
126-
$token
127-
);
128-
} catch (Exception $e) {
129-
throw new Exception('Exception when requesting users from Azure: '.$e->getMessage());
130-
}
131-
132-
$azureUsersInfo = $azureUsersRequest['value'] ?? [];
133-
134-
foreach ($azureUsersInfo as $azureUserInfo) {
135-
yield $azureUserInfo;
136-
}
137-
138-
$hasNextLink = false;
139-
140-
if (!empty($azureUsersRequest['@odata.nextLink'])) {
141-
$hasNextLink = true;
142-
$query = parse_url($azureUsersRequest['@odata.nextLink'], PHP_URL_QUERY);
143-
}
144-
} while ($hasNextLink);
145-
}
14691
}

0 commit comments

Comments
 (0)