Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Add, remove and move #17

Closed

Conversation

ElectricMaxxx
Copy link
Member

@ElectricMaxxx ElectricMaxxx commented May 20, 2016

This PR does the implemenetation of the the base methods of the EditableRepository in both repositories. We will hopefully get the move method when puli/repository#26 is ready, but i will start with it before the merge and use the interface defined by @wouterj

ToDo:

  • add()
  • remove()
  • move()
  • clear()

Note: i branched from the state #15 will rebase on master when its merged, so the other commits should disappear.

@dantleech
Copy link
Member

Looks good! will have a proper look later on.


$resolvedPath = $this->resolvePath($query);

$this->removeResource($resolvedPath, $deleted);
Copy link
Member

Choose a reason for hiding this comment

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

Can we change this to:

return $this->removeResource($resolvedPath);

and have removeResource simply return the number of items deleted?

@ElectricMaxxx
Copy link
Member Author

hey @dantleech

i did the changes you whant me to do, but i think the thing with the path isn't correct. The injected path can not be the destination path. otherwise adding of a collection of resources will completly wrong. Lets do an example:

$path = /some/path
When adding a node/document with name = path the way we do is correct, we just need to assert the name against the rest of the path. So $parentPath = /some and $localName = path
What would be when adding two resources, one with name = pathA and one with name = pathB, than the localName doesn't match to injected path as the final destination anymore.
I try to imagine creating a file there i would say lets create a file with name bla.tx in directory /home/max so the target directory is our parent path. Same when adding two or more files into one directory.


$document = $resource->getPayload();
$document->setName($resource->getName());
if ($document instanceof HierarchyInterface) {
Copy link
Member

Choose a reason for hiding this comment

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

Documents do not require a "name" method, they also do not need to implement the HierearchyInterface in order to have a parent, nor would they necessarily have either a "parent" or a "name" mapping as they could be using an "ID/path" ID strategy (where you would set the path directly).

In the Syluus resource bundle I force the user to use the name and parent mappings, but that could be more flexible.

I am not even sure it makes sense to be able to create documents here at all - you cannot gaurantee that a document doesn't have required fields which cannot be set using this API.

/cc @dbu @wouterj

Copy link
Member Author

Choose a reason for hiding this comment

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

I think creation and validation of fields/properties should be done outside. i.e. in a controller of rest-resources-bundle - the point where in the input will be created.

Copy link
Member

Choose a reason for hiding this comment

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

Currently creation and edition would be/is done either by SonataAdmin or SyliusResourceBundle - which supports both HTML and REST endpoints for editing and creating new objects.

I see the Resource system as providing links to these endpoints which are capable of dealing with the resource's payload.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think we should open complete CRUD endpoints on Phpcr and PhpcrOdm here (over resource-rest-bundle) on the complete node/documents to enable all frontend applications like admins, to work on the path based structure. The content-bundle would give a REST endpoint on based on the content's route (and the dynamic routing) to have CRUD on content only. a use case would be the frontend editing. That would be my big picture in 4 lines :-)

Copy link
Member

Choose a reason for hiding this comment

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

Regarding the above code.

We don't even need to set the name or parent. We are being passed the payload - i.e. the document. It should already be ready-to-persist without further modification or?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dantleech
Copy link
Member

On reflection -- what is the use case for "add" ?

With both the ODM and PHPCR the class/node-types may require fields which cannot be set by simply creating a Document/Node.

}

/**
* @expectedException \InvalidArgumentException
Copy link
Member

Choose a reason for hiding this comment

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

message

@dantleech
Copy link
Member

I am still not sure of why we need add for PHPCR nodes / ODM documents, can somebody give me a use case? /cc @wouterj @webmozart


$resolvedPath = $this->resolvePath($query);

return $this->removeResource($resolvedPath, $deleted);
Copy link
Member

Choose a reason for hiding this comment

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

Passing deleted does not make any sense.

@ElectricMaxxx
Copy link
Member Author

Will work on the rest of the hints tonight.

/**
* @author Maximilian Berghoff <[email protected]>
*/
class FalsyResource implements PuliResource
Copy link
Member

Choose a reason for hiding this comment

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

Why not use GenericResource here?

@dantleech
Copy link
Member

@ElectricMaxxx would you mind if i fork this PR and merge only the move and remove parts? As I currently don't know how add is going to be useful or if we are doing that correctly.

After move and remove are merged this PR will just be about add.

@ElectricMaxxx
Copy link
Member Author

ElectricMaxxx commented May 31, 2016 via email

@dantleech
Copy link
Member

Will do

/**
* {@inheritdoc}
*/
public function remove($query, $language = 'glob')
Copy link
Member

Choose a reason for hiding this comment

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

@ElectricMaxxx I think this is for removing multiple resources? But we are only removing one?

@dantleech
Copy link
Member

Forked and replaced by: #23

@dantleech dantleech closed this Jun 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants