diff --git a/getmemberships.php b/getmemberships.php index 3494e3c..debe738 100755 --- a/getmemberships.php +++ b/getmemberships.php @@ -8,13 +8,38 @@ $client->setCheckSslCertificate(true); $limit = 100; $offset = 0; -$projectList = getProjectList($limit, $offset, $client); -print_r($getProjectList); -die; +list($projectsById, $projectsByDomain) = getProjectList($limit, $offset, $client); $userList = getUserList($limit, $offset, $client); $membershipMapping = getUserMemberships($userList, $client); +//print_r($projectsById); +//print_r($projectsByDomain); //print_r($membershipMapping); +function getProjectList($limit, $offset, $client) { + // We'll set a more realistic total user count after the first loop. + $totalProjects = 99999; + // Get a complete user list with email address. + while ($offset + $limit < $totalProjects) { + $listing = $client->project->all([ + 'limit' => $limit, + 'offset' => $offset, + ]); + foreach ($listing['projects'] as $project) { + // 0 is a magic number. This might(?) fail if we ever add other project custom fields. + if ($project['custom_fields'][0]['value']) { + $domain = $project['custom_fields'][0]['value']; + $projectsByDomain[$domain] = $project['identifier']; + } + $projectsById[$project['id']] = $project['identifier']; + } + $totalProjects = $listing['total_count']; + $offset += $limit; + }; + $projects[] = $projectsById; + $projects[] = $projectsByDomain; + return $projects; +} + /* * Returns an array of all users. Key is user ID, value is email address. */