forked from dustin10/VichUploaderBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use preFlush event introduced in Doctrine 2.2 and minior refactoring (c…
…loses dustin10#8, dustin10#89, dustin10#123)
- Loading branch information
Showing
10 changed files
with
46 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,32 +3,30 @@ | |
namespace Vich\UploaderBundle\EventListener\Doctrine; | ||
|
||
use Doctrine\Common\EventArgs; | ||
use Doctrine\ORM\Events; | ||
|
||
/** | ||
* CleanListener | ||
* | ||
* Listen to the update event to delete old files accordingly. | ||
* | ||
* @author Kévin Gomez <[email protected]> | ||
* @author Konstantin Myakshin <[email protected]> | ||
*/ | ||
class CleanListener extends BaseListener | ||
{ | ||
/** | ||
* The events the listener is subscribed to. | ||
* | ||
* @return array The array of events. | ||
* {@inheritdoc} | ||
*/ | ||
public function getSubscribedEvents() | ||
{ | ||
return array( | ||
'preUpdate', | ||
); | ||
return array(Events::preFlush); | ||
} | ||
|
||
/** | ||
* @param EventArgs $event The event. | ||
* {@inheritdoc} | ||
*/ | ||
public function preUpdate(EventArgs $event) | ||
public function preFlush(EventArgs $event) | ||
{ | ||
$object = $this->adapter->getObjectFromArgs($event); | ||
|
||
|
@@ -38,7 +36,6 @@ public function preUpdate(EventArgs $event) | |
|
||
foreach ($this->getUploadableFields($object) as $field) { | ||
$this->handler->clean($object, $field); | ||
$this->adapter->recomputeChangeSet($event); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,33 +3,30 @@ | |
namespace Vich\UploaderBundle\EventListener\Doctrine; | ||
|
||
use Doctrine\Common\EventArgs; | ||
use Doctrine\ORM\Events; | ||
|
||
/** | ||
* UploadListener | ||
* | ||
* Handles file uploads. | ||
* | ||
* @author Kévin Gomez <[email protected]> | ||
* @author Konstantin Myakshin <[email protected]> | ||
*/ | ||
class UploadListener extends BaseListener | ||
{ | ||
/** | ||
* The events the listener is subscribed to. | ||
* | ||
* @return array The array of events. | ||
* {@inheritdoc} | ||
*/ | ||
public function getSubscribedEvents() | ||
{ | ||
return array( | ||
'prePersist', | ||
'preUpdate', | ||
); | ||
return array(Events::preFlush); | ||
} | ||
|
||
/** | ||
* @param EventArgs $event The event. | ||
* {@inheritdoc} | ||
*/ | ||
public function prePersist(EventArgs $event) | ||
public function preFlush(EventArgs $event) | ||
{ | ||
$object = $this->adapter->getObjectFromArgs($event); | ||
|
||
|
@@ -41,22 +38,4 @@ public function prePersist(EventArgs $event) | |
$this->handler->upload($object, $field); | ||
} | ||
} | ||
|
||
/** | ||
* @param EventArgs $event The event. | ||
*/ | ||
public function preUpdate(EventArgs $event) | ||
{ | ||
$object = $this->adapter->getObjectFromArgs($event); | ||
|
||
if (!$this->isUploadable($object)) { | ||
return; | ||
} | ||
|
||
foreach ($this->getUploadableFields($object) as $field) { | ||
$this->handler->upload($object, $field); | ||
} | ||
|
||
$this->adapter->recomputeChangeSet($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.