protected function persistLocalModel($user, $resource_hash) { // Will be used to check if the user already exist locally $mno_id_map = MnoIdMap::findMnoIdMapByMnoIdAndEntityName($resource_hash['id'], 'APPUSER', 'USERS'); $user->save("Users", false); // We make sure that the mnoIdMap is created before we start to parse the user's teams to bloc kany eventual recursive loop $this->findOrCreateIdMap($resource_hash, $user); // Add user to corresponding teams if (!$mno_id_map) { // User does not exist locally => we add him to its teams $mno_teams = $resource_hash['teams']; $team_mapper = new TeamMapper(); for ($j = 0; $j < count($mno_teams); $j++) { $team_hash = $mno_teams[$j]; // Retrieve the local group if exists or create it based on data from Connec! Entity::Team otherwise $group_model = $team_mapper->fetchConnecResource($team_hash['id']); $group_members = array_keys($group_model->getMembers()["Users"]); // At this stage, the user should exist (has been saved before), and have an id defined array_push($group_members, "Users:" . json_encode($user->id)); $group_model->set('group_members', $group_members); // Will save the new users list for the team $team_mapper->persistLocalModel($group_model, null); } } }