Skip to content

bug #10544: create new resource on update if not found#102

Open
dimaip wants to merge 1 commit intoSylius:1.10from
dimaip:patch-1
Open

bug #10544: create new resource on update if not found#102
dimaip wants to merge 1 commit intoSylius:1.10from
dimaip:patch-1

Conversation

@dimaip
Copy link
Copy Markdown

@dimaip dimaip commented Jul 25, 2019


$this->isGrantedOr403($configuration, ResourceActions::UPDATE);
$resource = $this->findOr404($configuration);
$resource = $this->findOrCreate($configuration);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be conditional, since it's only for PUT requests, the PATCH should return 404 if the resource does not exists.

        if ($request->isMethod(Request::METHOD_PUT)) {
            $resource = $this->findOrCreate($configuration);            
        } else {
            $resource = $this->findOr404($configuration);
        }

@vvasiloi
Copy link
Copy Markdown
Contributor

This has to be added before

https://github.com/Sylius/SyliusResourceBundle/blob/master/src/Bundle/Controller/ResourceUpdateHandler.php#L41

        if (!$manager->contains($resource)) {
            $manager->persist($resource);
        }

Otherwise new resources won't be created.

@dimaip
Copy link
Copy Markdown
Author

dimaip commented Aug 15, 2019

Ah, I was just wondering why it didn't update anything. Will test.

@dimaip
Copy link
Copy Markdown
Author

dimaip commented Oct 28, 2019

Duh, I just realised I haven't updated this PR. Feel free to take over or I'll try to find the time to finish it later, after the project launch.

@lchrusciel lchrusciel changed the base branch from master to 1.10 April 15, 2022 12:25
@lchrusciel lchrusciel requested a review from a team as a code owner April 15, 2022 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants