Creating record

@param HCResourceAuthorRequest $request
@return JsonResponse
@throws \Exception
13047
public function store(HCResourceAuthorRequest $request): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            $resourceAuthor = $this->service->getRepository()->create($request->getRecordData());

            $this->connection->commit();
        } catch (\Throwable $exception) {
            $this->connection->rollBack();

            report($exception);

            return $this->response->error($exception->getMessage());
        }

        event(new HCResourceAuthorCreated($resourceAuthor));

        if ($request->has('hc_new')) {

            $resourceAuthor->label = $resourceAuthor->name;

            return $this->response->success("Created", $resourceAuthor);
        } else {

            return $this->response->success("Created");
        }

    }
573742
public function postAction(Request $request)
    {
        try {
            return $this->createJsonResponse($this->get('oauth.server')->grant(
                $this->getRequestData($request, 'snakelize')
            ));
        } catch (InvalidGrantException $e) {
            return new JsonResponse('Unavailable to create access token : bad credentials.', 401);
        } catch (\InvalidArgumentException $e) {
            return new JsonResponse('Invalid or missing fields for grant type.', 400);
        }
    }
844366
public function store(CreateUserRequest $request)
    {
        $user = User::create([
            'name' => $request->input('name'),
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('password')),
        ]);

        event(new UserCreated($user));

        return Response::json(['created' => true ]);
    }
1166132
public function update(HCUserRequest $request, string $id): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            $record = $this->service->updateUser(
                $id,
                $request->getUserInput(),
                $request->getRoles(),
                $request->getPersonalData()
            );

            if ($request->wantToActivate()) {
                $this->service->activateUser($record->id);
            }

            $this->connection->commit();

        } catch (\Throwable $exception) {
            $this->connection->rollBack();

            report($exception);

            return $this->response->error($exception->getMessage());
        }

        return $this->response->success(trans('HCCore::users.message.user_updated'), $record);
    }
150029
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New Role');
        app('soda.interface')->breadcrumbs()->addLink(route('soda.roles.index'), 'Roles');

        try {
            $role = $this->roles->newInstance($request);
            $permissionIds = $this->roles->getPermissions();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'role']));
        }

        return soda_cms_view('data.roles.view', compact('role', 'permissionIds'));
    }
940655
public function uploadArchiveAction(Request $request)
    {
        $files = $request->files->all();

        foreach ($files as $file) {
            $object = $this->crud->create(
                PublicFile::class,
                [],
                ['file' => $file]
            );
        }

        $zip = new \ZipArchive();
        $zip->open($this->fileUtils->getPath($object));
        $json = $zip->getFromName('workspace.json');
        $zip->close();

        $data = json_decode($json, true);
        $data['archive'] = $this->serializer->serialize($object);

        return new JsonResponse($data);
    }
581139
public function createLogStore(CreateLogStoreRequest $request)
    {
        $headers                      = array();
        $params                       = array();
        $resource                     = '/logstores';
        $project                      = $request->getProject() !== null ? $request->getProject() : '';
        $headers["x-log-bodyrawsize"] = 0;
        $headers["Content-Type"]      = "application/json";
        $body                         = array(
            "logStoreName" => $request->getLogStore(),
            "ttl"          => (int) ( $request->getTtl() ),
            "shardCount"   => (int) ( $request->getShardCount() )
        );
        $body_str                     = json_encode($body);
        list( $resp, $header ) = $this->send("POST", $project, $body_str, $resource, $params, $headers);
        $requestId = isset ( $header ['x-log-requestid'] ) ? $header ['x-log-requestid'] : '';
        $resp      = $this->parseToJson($resp, $requestId);

        return new CreateLogStoreResponse($resp, $header);
    }
544448
public static function create(ServerRequestInterface $request)
    {
        $method = strtolower($request->getMethod());
        $query = $request->getQueryParams();
        $post = $request->getParsedBody();

        $input = new PsrInput(array_merge($query, $post));
        $input->setMethod($request->getMethod());

        $filter = $input->getFilter() instanceof NullFilter ? null : $input->getFilter();

        // Sort by importance
        $input->get = new Input($query, $filter);
        $input->post = new Input($method === 'post' ? $post : [], $filter);
        $input->files = new PsrFilesInput($request->getUploadedFiles(), $filter);
        $input->put = new Input($method === 'put' ? $post : [], $filter);
        $input->patch = new Input($method === 'patch' ? $post : [], $filter);
        $input->delete = new Input($method === 'delete' ? $post : [], $filter);
        $input->link = new Input($method === 'link' ? $post : [], $filter);
        $input->unlink = new Input($method === 'unlink' ? $post : [], $filter);
        $input->request = new Input(array_merge($query, $post));

        // Super Globals
        $input->server = new Input($request->getServerParams(), $filter);
        $input->header = new PsrHeaderInput($request->getHeaders(), $filter);
        $input->cookie = new CookieInput($request->getCookieParams(), $filter);

        return $input;
    }
454099
private function createNotFoundResponse($request, $exception)
    {
        $message = $exception->getMessage();
        if (empty($message)) {
            $message = 'Uri ' . $request->getRequestUri() . ' could not be found';
        }

        return new JsonResponse(
            [
                'status'  => 'ERROR',
                'message' => $message
            ],
            JsonResponse::HTTP_NOT_FOUND
        );
    }
1207577
public function store(HCUserRequest $request): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            $record = $this->service->createUser(
                $request->getUserInput(),
                $request->getPersonalData(),
                $request->getRoles(),
                $request->filled('send_welcome_email'),
                $request->filled('send_password')
            );

            $this->connection->commit();
        } catch (\Throwable $exception) {
            $this->connection->rollBack();

            report($exception);

            return $this->response->error($exception->getMessage());
        }

        return $this->response->success(trans('HCCore::users.message.user_updated'), $record);
    }
210126
public function createUser($properties): UserRecord
    {
        $request = $properties instanceof Request\CreateUser
            ? $properties
            : Request\CreateUser::withProperties($properties);

        $response = $this->client->createUser($request);

        $uid = JSON::decode((string) $response->getBody(), true)['localId'];

        return $this->getUser($uid);
    }
308933
public function handleCreateFolder(SS_HTTPRequest $request)
    {

        if (!Injector::inst()->get('Folder')->canCreate()) {
            return $this->httpError(403);
        }

        $parentID = (int)$request->postVar('parentID');

        /** @var Folder $parentRecord */
        $parentRecord = Folder::get()->byID($parentID);

        $name = $request->postVar('title') ? $request->postVar('title') : _t('AssetAdmin.NEWFOLDER', "NewFolder");
        if ($parentRecord && $parentRecord->ID) {
            $filename = Controller::join_links($parentRecord->FullPath, $name);
        } else {
            $filename = Controller::join_links(ASSETS_PATH, $name);
        }

        /** @var Folder $record */
        $record = Folder::create(array(
            'ParentID' => $parentID,
            'Name' => basename($filename),
            'Title' => basename($filename),
            'Filename' => $filename
        ));

        // Ensure uniqueness
        $i = 2;
        if (substr($record->Filename, -1) == "/") {
            $baseFilename = substr($record->Filename, 0, -1);
        } else {
            $baseFilename = $record->Filename;
        }
        $baseFilename .= "-";
        while (file_exists($record->FullPath)) {
            $record->Filename = $baseFilename . $i . '/';
            $i++;
        }

        $record->Name = $record->Title = basename($record->Filename);

        mkdir($record->FullPath);
        @chmod($record->FullPath, (int)Config::inst()->get('Filesystem', 'file_create_mask'));

        $record->write();

        $response = new SS_HTTPResponse(
            Convert::array2json($this->createFolderJson($record)), 200
        );

        return $response->addHeader('Content-Type', 'application/json');
    }
447948
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New '.ucwords(trans('soda::terminology.field')));
        app('soda.interface')->breadcrumbs()->addLink(route('soda.fields.index'), ucwords(trans('soda::terminology.field_plural')));

        try {
            $field = $this->fields->newInstance($request);
            $fieldTypes = $this->fields->getFieldTypes();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => trans('soda::terminology.field')]));
        }

        return soda_cms_view('data.fields.view', compact('field', 'fieldTypes'));
    }
304216
public function createAndLoginAction(Request $request)
    {
        //there is a little bit of computation involved here (ie, do we need to validate the account or stuff like this)
        //but keep it easy for now because an other route could be relevant
        $selfLog = true;
        $autoOrganization = $this->container
            ->get('claroline.config.platform_config_handler')
            ->getParameter('force_organization_creation');

        $organizationRepository = $this->container->get('claroline.persistence.object_manager')
            ->getRepository('ClarolineCoreBundle:Organization\Organization');

        //step one: creation the organization if it's here. If it exists, we fetch it.
        $data = $this->decodeRequest($request);

        if ($selfLog && 'anon.' === $this->container->get('security.token_storage')->getToken()->getUser()) {
            $this->options['create'][] = Options::USER_SELF_LOG;
        }

        $organization = null;

        if ($autoOrganization) {
            //try to find orga first
            //first find by vat
            if (isset($data['mainOrganization'])) {
                if (isset($data['mainOrganization']['vat']) && null !== $data['mainOrganization']['vat']) {
                    $organization = $organizationRepository
                      ->findOneBy(['vat' => $data['mainOrganization']['vat']]);
                //then by code
                } else {
                    $organization = $organizationRepository
                      ->findOneBy(['code' => $data['mainOrganization']['code']]);
                }
            }

            if (!$organization && isset($data['mainOrganization'])) {
                $organization = $this->crud->create(
                    'Claroline\CoreBundle\Entity\Organization\Organization',
                    $data['mainOrganization']
                );
            }

            //error handling
            if (is_array($organization)) {
                return new JsonResponse($organization, 400);
            }
        }

        $user = $this->crud->create(
            User::class,
            $this->decodeRequest($request),
            array_merge($this->options['create'], [Options::VALIDATE_FACET])
        );

        //error handling
        if (is_array($user)) {
            return new JsonResponse($user, 400);
        }

        if ($organization) {
            $this->crud->replace($user, 'mainOrganization', $organization);
        }

        return new JsonResponse(
            $this->serializer->serialize($user, $this->options['get']),
            201
        );
    }
726318
public static function create_from_request($request) {
        if($type = $request->getVar('accept')) {
            try {
                if(array_key_exists($type, self::$lookup)) {
                    return self::create(self::$lookup[$type]);
                }
            } catch(\Exception $e) {}
        }
        $types = $request->getAcceptMimetypes();
        foreach($types as $type) {
            try {
                return self::create($type);
            } catch(RestUserException $e) {}
        }
        return self::create();
    }
762121
public function fileHistoryForm($request = null)
    {
        // Get ID either from posted back value, or url parameter
        if (!$request) {
            $this->jsonError(400);
            return null;
        }
        $id = $request->param('ID');
        if (!$id) {
            $this->jsonError(400);
            return null;
        }
        $versionID = $request->param('VersionID');
        if (!$versionID) {
            $this->jsonError(400);
            return null;
        }
        $form = $this->getFileHistoryForm([
            'RecordID' => $id,
            'RecordVersion' => $versionID,
        ]);
        return $form;
    }
1251498
public function store(UserRequest $request)
    {
        $input = $request->except('roles');

        if ($request->has('password')) {
            $input['password'] = bcrypt($request->password);
        } else {
            unset($input['password']);
        }

        $record = $this->model->create($input);

        if ($request->has('roles')) {
            $record->syncRoles($request->roles);
        }

        $this->notify([
            'type' => 'success',
            'title' => 'Successful create user!',
            'description' => 'User is created successfully!',
        ]);

        return redirect(route('user.edit', ['id' => $record->id]));
    }