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

[WIP] Refactor event system #106

Closed
wants to merge 3 commits into from
Closed

Conversation

Baachi
Copy link
Contributor

@Baachi Baachi commented Jan 21, 2013

Hey,

I refactored the event system a little bit. Now you can configure which listeners should be triggerd and which not.
So if you have some issues with upload a file/image, like #8. You can disable the event listener and upload the file by hand.

Feedback, please!

Todo

  • Tests
  • Test it in a real application
  • Make it workable with MongoDBODM

@Baachi
Copy link
Contributor Author

Baachi commented Feb 27, 2013

@ftassi Any feedback?

@ioleo
Copy link

ioleo commented Apr 4, 2013

@Baachi nice one 👍

@Baachi Baachi mentioned this pull request Apr 8, 2013
@nifr
Copy link

nifr commented Apr 22, 2013

I recently came across the error where the upload handler was not triggered if only the image had been changed.
I was able to fix it in my case with the solution suggested in #96.

Now im back with the same situation in a new project... having this issue solved in the bundle would be nice.

@dustin10 Any comments/proposals on this PR ? I would be willing to help out if something's missing.

@ftassi
Copy link
Collaborator

ftassi commented May 21, 2013

Hi @Baachi thanks for the PR and sorry for late responding. Here are my thoughts about it.
I like the idea of being able to define which listener should be triggered, but I think your PR needs to be tweaked a bit before it can be merged.

We have 4 events that should trigger 4 different actions:

  • prePersist and preUpdate is used for uploading the file
  • preUpdate is also used for deleting the previous file if configured to
  • postUpload is used for injecting the File instance in the Entity
  • postRemove is used for deleting/unlinking the uploaded file

The user should be able to configure those 4 behaviours independently and I also would like to let the user free to define them globally or for at mapping level (specific mapping config should override globals).

Sadly we're not able to tag or untag listeners at runtime(are we?), I think we need to always call the listeners, pass the configuration data to the PropertyMapping class and use it to decide what to do for each uploadable field. This is an example of what I'm talking about (as the bundle already do something like this): https://github.com/dustin10/VichUploaderBundle/blob/master/Storage/AbstractStorage.php#L94

Does this make sense for you?

@@ -28,6 +28,9 @@ public function getConfigTreeBuilder()
->scalarNode('storage')->defaultValue('vich_uploader.storage.file_system')->end()
->scalarNode('twig')->defaultTrue()->end()
->scalarNode('gaufrette')->defaultFalse()->end()
->scalarNode('upload_on_persist')->defaultTrue()->end()
->scalarNode('unlink_on_remove')->defaultTrue()->end()
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be delete_on_remove for consistence with mapping node
also delete_on_update is missing here

@Baachi
Copy link
Contributor Author

Baachi commented May 23, 2013

@ftassi Attach the listeners at runtime is not easy, because we can not use the DIC. But your suggestions make sense and i will follow your suggestions. I hope i will find some time at this weekend to finish this PR.

@ftassi
Copy link
Collaborator

ftassi commented May 23, 2013

👌

@leopro
Copy link

leopro commented Jun 14, 2013

a possible alternative solution could be listen preFlush event instead of preUpdate, something like this:

/**
 * I listen this event instead of preUpdate because 
 * if change only the not mapped property doctrine does not dispatch the preUpdate event
 */
public function preFlush(PreFlushEventArgs $args)
{
    $uow = $args->getEntityManager()->getUnitOfWork();
    $identities = $uow->getIdentityMap();

    foreach ($identities as $key => $identity) {
        foreach ($identity as $id => $entity) {
            if ($entity instanceof UploadableInterface) {
                //...
            }
        }
    }
}

I have taken this piece of code from a project in which I used an interface, but it's easy implement it via annotations

@sirian
Copy link

sirian commented Oct 8, 2013

any news?

@Baachi
Copy link
Contributor Author

Baachi commented Oct 8, 2013

@sirian Currently i'm very busy, but if you want send PR's to my branch and i will merge it, so it will be vissible here.
Maybe i will find some time at the weekend.

@K-Phoen
Copy link
Collaborator

K-Phoen commented Nov 20, 2013

What's the status of this PR?

@Baachi
Copy link
Contributor Author

Baachi commented Nov 21, 2013

I'm currently haven't any project which use the VichUploaderBundle and currently i'm busy. There are many things todo, @ftassi want some more features before he will merge it.

@K-Phoen K-Phoen mentioned this pull request Dec 24, 2013
11 tasks
@Baachi
Copy link
Contributor Author

Baachi commented Mar 25, 2014

@K-Phoen can i close this PR?

@K-Phoen
Copy link
Collaborator

K-Phoen commented Mar 26, 2014

Yep :)

Do you think there are still things in your PR that we should backport into the actual codebase?

@Baachi
Copy link
Contributor Author

Baachi commented Mar 26, 2014

I don't think so, you do a great job with this PR #183 .

@Baachi Baachi closed this Mar 26, 2014
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.

7 participants