-
Notifications
You must be signed in to change notification settings - Fork 75
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
EMongoFile: missing setFile afterInsert #122
Comments
Hmm let me check this out I might be able to associate the database file etc without having to do another round trip. |
I did find a way of doing this but I reverted it to do it the way you showed minaly because it was actually more performant to just query again for the result of a single row that is likely to be in working set. |
Maybe it's better to modify the getFile() method. If I call getFile() and the model is in the mongodb (means $this->_id is assigned) I expect to work with the methods of MongoGridFSFile: 'write' to the filesystem, getResource() for streaming ... So maybe like below:
public function getFile()
{
if(!empty($this->_id) && !(($this->_file instanceof MongoGridFSFile)))
{
$this->_file=$this->getCollection()->get($this->_id);
}
|
But the best would be to implement the magic methods __call, __get, ... to work directly In this case your implementation is always uptodate with the driver and I can do like: $mongofile->write(), $mongofile->getResource() for streaming |
tbh the getFilename etc should be getFile() anyway for KISS and DRY programming reasons so that has been done now. About the function use, I have an idea, just change the __call:
That should do it. Then that solves adding that to getFile(), instead you can just use the EMOngoFile straight off |
Nice, we had the same idea ;-) |
Oh yeah I see that's what you meant by your second comment lol |
Missing the change in getFile() in your commit
public function getFile()
{
if(!empty($this->_id) && !(($this->_file instanceof MongoGridFSFile)))
{
$this->_file=$this->getCollection()->get($this->_id);
}
|
With the change in __call and insert it shouldn't be needed? Can you give a case where it is? |
oh, didn't see the change: setfile in insert. But with the getFile() from above you don't need to setfile(...) in insert (or maybe update too??). The getFile() implemention from above ensures always to work with the gridFS file if it has an _id, independent of inserted, updated,... before. |
True that actually, no need to get the file if you don't need to work on it again. Updating will just work no need to do anything with that, inserting is the problem but yeah I see what you mean. I'll change it |
That should do it: 291f11e |
Thanks, I will test it. |
If EMongoFile->insert() is executed, the _file=null (or points to a maybe not existing CUploadedFile)
But I expect the _file property is set to the MongoGridFSFile that was inserted.
So you should call $this->setFile in the insert method after storeFile.
if($this->getCollection()->storeFile($this->getFilename(), $this->getRawDocument())){
Not a good performance, but necessary for more operations after inserting (maybe for export, converting ...) a model.
The text was updated successfully, but these errors were encountered: