Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: 1.10
Choose a base branch
from

Conversation

dimaip
Copy link

@dimaip dimaip commented Jul 25, 2019

@@ -251,7 +251,7 @@ public function updateAction(Request $request): Response
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

$this->isGrantedOr403($configuration, ResourceActions::UPDATE);
$resource = $this->findOr404($configuration);
$resource = $this->findOrCreate($configuration);
Copy link
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
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
Author

dimaip commented Aug 15, 2019

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

@dimaip
Copy link
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