protected function insertRoleServiceAccess()
    {
        $rolesInZip = $this->package->getResourceFromZip('system/role.json');
        $imported = false;

        if (!empty($rolesInZip)) {
            try {
                foreach ($rolesInZip as $riz) {
                    $rsa = $riz['role_service_access_by_role_id'];
                    $role = Role::whereName($riz['name'])->first();
                    if (!empty($role) && !empty($rsa)) {
                        $newRoleId = $role->id;
                        $cleanedRsa = [];
                        foreach ($rsa as $r) {
                            $originId = $r['id'];
                            $this->fixCommonFields($r);
                            $newServiceId = $this->getNewServiceId($r['service_id']);

                            if (empty($newServiceId) && !empty($r['service_id'])) {
                                $this->log(
                                    'warning',
                                    'Skipping relation role_service_access_by_role_id with id ' .
                                    $originId .
                                    ' for Role ' .
                                    $riz['name'] .
                                    '. Service not found for ' .
                                    $r['service_id']
                                );
                                continue;
                            }

                            $r['service_id'] = $newServiceId;
                            $r['role_id'] = $newRoleId;

                            if ($this->isDuplicateRoleServiceAccess($r)) {
                                $this->log(
                                    'notice',
                                    'Skipping duplicate role_service_access relation with id ' . $originId . '.'
                                );
                                continue;
                            }

                            $cleanedRsa[] = $r;
                        }

                        if (!empty($cleanedRsa)) {
                            $roleUpdate = ['role_service_access_by_role_id' => $cleanedRsa];
                            $result =
                                ServiceManager::handleRequest(
                                    'system', Verbs::PATCH, 'role/' . $newRoleId, [], [], $roleUpdate, null, true, true
                                );
                            if ($result->getStatusCode() >= 300) {
                                throw ResponseFactory::createExceptionFromResponse($result);
                            }
                            $imported = true;
                        }
                    } elseif (!empty($rsa) && empty($role)) {
                        $this->log(
                            'warning',
                            'Skipping all Role Service Access for ' . $riz['name'] . ' No imported role found.'
                        );
                        \Log::debug('Skipped Role Service Access.', $riz);
                    } else {
                        $this->log('notice', 'No Role Service Access for role ' . $riz['name']);
                    }
                }
            } catch (\Exception $e) {
//                if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
//                    $this->log(
//                        'error',
//                        'Failed to insert role service access records for roles. ' .
//                        $this->getErrorDetails($e)
//                    );
//                }
//                throw new InternalServerErrorException(
//                    'Failed to insert role service access records for roles. ' .
//                    $this->getErrorDetails($e)
//                );
                $this->throwExceptions($e, 'Failed to insert role service access records for roles');
            }
        }

        return $imported;
    }
protected function insertRoleServiceAccess()
    {
        $rolesInZip = $this->package->getResourceFromZip('system/role.json');
        $imported = false;

        if (!empty($rolesInZip)) {
            try {
                foreach ($rolesInZip as $riz) {
                    $rsa = $riz['role_service_access_by_role_id'];
                    $role = Role::whereName($riz['name'])->first();
                    if (!empty($role) && !empty($rsa)) {
                        $newRoleId = $role->id;
                        $cleanedRsa = [];
                        foreach ($rsa as $r) {
                            $originId = $r['id'];
                            $this->fixCommonFields($r);
                            $newServiceId = $this->getNewServiceId($r['service_id']);

                            if (empty($newServiceId) && !empty($r['service_id'])) {
                                $this->log(
                                    'warning',
                                    'Skipping relation role_service_access_by_role_id with id ' .
                                    $originId .
                                    ' for Role ' .
                                    $riz['name'] .
                                    '. Service not found for ' .
                                    $r['service_id']
                                );
                                continue;
                            }

                            $r['service_id'] = $newServiceId;
                            $r['role_id'] = $newRoleId;

                            if ($this->isDuplicateRoleServiceAccess($r)) {
                                $this->log(
                                    'notice',
                                    'Skipping duplicate role_service_access relation with id ' . $originId . '.'
                                );
                                continue;
                            }

                            $cleanedRsa[] = $r;
                        }

                        if (!empty($cleanedRsa)) {
                            $roleUpdate = ['role_service_access_by_role_id' => $cleanedRsa];
                            $result =
                                ServiceManager::handleRequest(
                                    'system', Verbs::PATCH, 'role/' . $newRoleId, [], [], $roleUpdate, null, true, true
                                );
                            if ($result->getStatusCode() >= 300) {
                                throw ResponseFactory::createExceptionFromResponse($result);
                            }
                            $imported = true;
                        }
                    } elseif (!empty($rsa) && empty($role)) {
                        $this->log(
                            'warning',
                            'Skipping all Role Service Access for ' . $riz['name'] . ' No imported role found.'
                        );
                        \Log::debug('Skipped Role Service Access.', $riz);
                    } else {
                        $this->log('notice', 'No Role Service Access for role ' . $riz['name']);
                    }
                }
            } catch (\Exception $e) {
//                if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
//                    $this->log(
//                        'error',
//                        'Failed to insert role service access records for roles. ' .
//                        $this->getErrorDetails($e)
//                    );
//                }
//                throw new InternalServerErrorException(
//                    'Failed to insert role service access records for roles. ' .
//                    $this->getErrorDetails($e)
//                );
                $this->throwExceptions($e, 'Failed to insert role service access records for roles');
            }
        }

        return $imported;
    }
protected function insertRoleServiceAccess ( ) { $ rolesInZip = $ this -> package -> getResourceFromZip ( 'system/role.json' ) ; $ imported = false ; if ( ! empty ( $ rolesInZip ) ) { try { foreach ( $ rolesInZip as $ riz ) { $ rsa = $ riz [ 'role_service_access_by_role_id' ] ; $ role = Role :: whereName ( $ riz [ 'name' ] ) -> first ( ) ; if ( ! empty ( $ role ) && ! empty ( $ rsa ) ) { $ newRoleId = $ role -> id ; $ cleanedRsa = [ ] ; foreach ( $ rsa as $ r ) { $ originId = $ r [ 'id' ] ; $ this -> fixCommonFields ( $ r ) ; $ newServiceId = $ this -> getNewServiceId ( $ r [ 'service_id' ] ) ; if ( empty ( $ newServiceId ) && ! empty ( $ r [ 'service_id' ] ) ) { $ this -> log ( 'warning' , 'Skipping relation role_service_access_by_role_id with id ' . $ originId . ' for Role ' . $ riz [ 'name' ] . '. Service not found for ' . $ r [ 'service_id' ] ) ; continue ; } $ r [ 'service_id' ] = $ newServiceId ; $ r [ 'role_id' ] = $ newRoleId ; if ( $ this -> isDuplicateRoleServiceAccess ( $ r ) ) { $ this -> log ( 'notice' , 'Skipping duplicate role_service_access relation with id ' . $ originId . '.' ) ; continue ; } $ cleanedRsa [ ] = $ r ; } if ( ! empty ( $ cleanedRsa ) ) { $ roleUpdate = [ 'role_service_access_by_role_id' => $ cleanedRsa ] ; $ result = ServiceManager :: handleRequest ( 'system' , Verbs :: PATCH , 'role/' . $ newRoleId , [ ] , [ ] , $ roleUpdate , null , true , true ) ; if ( $ result -> getStatusCode ( ) >= 300 ) { throw ResponseFactory :: createExceptionFromResponse ( $ result ) ; } $ imported = true ; } } elseif ( ! empty ( $ rsa ) && empty ( $ role ) ) { $ this -> log ( 'warning' , 'Skipping all Role Service Access for ' . $ riz [ 'name' ] . ' No imported role found.' ) ; \ Log :: debug ( 'Skipped Role Service Access.' , $ riz ) ; } else { $ this -> log ( 'notice' , 'No Role Service Access for role ' . $ riz [ 'name' ] ) ; } } } catch ( \ Exception $ e ) { //                if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) { //                    $this->log( //                        'error', //                        'Failed to insert role service access records for roles. ' . //                        $this->getErrorDetails($e) //                    ); //                } //                throw new InternalServerErrorException( //                    'Failed to insert role service access records for roles. ' . //                    $this->getErrorDetails($e) //                ); $ this -> throwExceptions ( $ e , 'Failed to insert role service access records for roles' ) ; } } return $ imported ; }
Imports Role Service Access relations for role.

@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
Imports Role Service Access relations for role .