-
Notifications
You must be signed in to change notification settings - Fork 19
Added ability to import a file into the repository #34
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
Conversation
$fileNode = $parentNode->addNode($filename, 'nt:file'); | ||
$contentNode = $fileNode->addNode('jcr:content', 'nt:unstructured'); | ||
$content = file_get_contents($file); | ||
$contentNode->setProperty('jcr:data', $content, PropertyType::BINARY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you can also just fopen and pass the stream handle as content, to avoid memory issues with larger files. you should try that.
great idea! actually, i propose to have this command in phpcr-utils instead, so that we can also provide it with jackalope and inside symfony. can be very useful. a command for exporting an nt:file (or any binary property) into a file would also be nice. |
|
||
$filename = basename($file); | ||
$fileNode = $parentNode->addNode($filename, 'nt:file'); | ||
$contentNode = $fileNode->addNode('jcr:content', 'nt:unstructured'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also allow to push a stream into any property of an existing node as an alternative. in some of our projects, we just put a binary stream into a property instead of having the nt:file node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. not sure how to elegantly handle that - it would be quite a different behavior (e.g. no node type detection, no wrapping node, etc). Maybe file:import /path/to/file --to-property=/foo/bar
or another command file:get-contents /path/to/file /path/to/property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the to-property option. a separate command clutters up the list of commands and can be counter-inuitive which to use. --to-property would require the containing node to already exist and create/update the property.
@dbu cheers! passing the handle would be excellent, will also add the nodename argument. With regards to having this command in phpcr-utils - I have a couple of counter propositions:
With respect to (1) phpcr-utils contains an incomplete "selection" of commands, phpcr-shell has almost all possible PHPCR commands (52 of them), all of which are designed in a consistent way and all of which are functionally tested. For (2), although it may sound extreme, I think given the current development trajectory of Another possibility would be to reduce the number of commands in DoctrinePHPCRBundle to a minimum (removing all node type commands etc.). The current version of Just some ideas. Obviously for the future.. :) |
hm, i see the problem. imho it is very useful to have phpcr commands on the symfony console. then again, nobody is trying to provide a full sql client implementation in console commands, so its a different story there. can the shell itself be started as a console command? what is useful in the console is that the same access configuration as for the application is used. then we might just provide the most basic commands and for the rest have people start the shell (can you also run a command of the shell from a script, non-interactively?). in the end it would mean wrapping lots of commands inside one command probably - kind of like namespacing them and hiding out of the main command list: |
re. starting the shell as a console command, I was thinking the same thing this morning - we could either embed the shell and wrap it in a single command, or we could depend on the shell being installed and call it with For executing commands you can currently do Launching the shell with |
The "bad" side of launching the shell independently is that the transport libraries will probably not be at the same version. |
can't we embed the shell in a symfony project? i guess it would mean running the console component inside a command that runs within the symfony application, but if its not relying on any globals or doing other ugly things, this should work, no? passing the configuration allows to select from multiple connections, if they are configured. reading the symfony app config from outside symfony sounds like a quite confusing hack to me. |
Or should it be |
i think we should keep all doctrine parts out of this, only the phpcr commands and then i would go with calling that command just phpcr. |
and |
yeah exactly. I'm sure its possible, sounds cool :) |
Updated this command. It can now import to a single property, override the mime-type detection and infer the node name from the path (like in bash).
Will add the inverse command (dump to external file) before merging |
btw. PR for replacing (or supplementing) DoctrinePHPCRBundle commands here: doctrine/DoctrinePHPCRBundle#151 |
Added ability to import a file into the repository
Automatically detects mime type with finfo.