/** * @param string $gerrit_id * @param string $email * @return GerritUser|null */ public function addGerritUser($gerrit_id, $email) { if ($this->owner->GerritUsers()->filter('AccountID', $gerrit_id)->count() != 0) { return null; } $gerrit_user = new GerritUser(); $gerrit_user->AccountID = $gerrit_id; $gerrit_user->Email = $email; $gerrit_user->write(); $this->owner->GerritUsers()->add($gerrit_user); return $gerrit_user; }
/** * @param string $icla_group_id * @return int */ public function processICLAGroup($icla_group_id) { $member_repository = $this->member_repository; $gerrit_api = $this->gerrit_api; return $this->tx_manager->transaction(function () use($icla_group_id, $member_repository, $gerrit_api) { // query gerrit service $icla_members_response = $gerrit_api->listAllMembersFromGroup($icla_group_id); $icla_members_count = count($icla_members_response); if ($icla_members_count === 0) { return; } //nothing to process... $gerrit_users = 0; foreach ($icla_members_response as $gerrit_info) { $email = @$gerrit_info['email']; $account_id = @$gerrit_info['_account_id']; if (!empty($email) && !empty($account_id)) { $member = $member_repository->findByEmail($email); if ($member) { if (is_null($member->addGerritUser($account_id, $email))) { continue; } ++$gerrit_users; } else { // we dont have a member associated with it :/ // check by account id if (!is_null($member_repository->getGerritUserByAccountId($account_id))) { continue; } $gerrit_user = new GerritUser(); $gerrit_user->AccountID = $account_id; $gerrit_user->Email = $email; $gerrit_user->write(); ++$gerrit_users; } } } return $gerrit_users; }); }
/** * @param string $account_id * @return GerritUser */ function getGerritUserByAccountId($account_id) { return GerritUser::get()->filter('AccountID', $account_id)->first(); }