Recettes : Listener pour supprimer la recette en même temps que le Content
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 126 KiB |
@@ -25,5 +25,11 @@
|
|||||||
<loop name="recipe_steps" class="Recettes\Loop\StepsLoop"/>
|
<loop name="recipe_steps" class="Recettes\Loop\StepsLoop"/>
|
||||||
</loops>
|
</loops>
|
||||||
|
|
||||||
|
<services>
|
||||||
|
<service id="recipe.listener" class="Recettes\EventListener\ContentListener" scope="request">
|
||||||
|
<argument type="service" id="request"/>
|
||||||
|
<tag name="kernel.event_subscriber"/>
|
||||||
|
</service>
|
||||||
|
</services>
|
||||||
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
61
local/modules/Recettes/EventListener/ContentListener.php
Normal file
61
local/modules/Recettes/EventListener/ContentListener.php
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Recettes\EventListener;
|
||||||
|
|
||||||
|
use Propel\Runtime\Propel;
|
||||||
|
use Recettes\Model\RecipeProductsQuery;
|
||||||
|
use Recettes\Model\RecipeQuery;
|
||||||
|
use Recettes\Model\RecipeStepsQuery;
|
||||||
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
use Thelia\Action\BaseAction;
|
||||||
|
use Thelia\Model\Event\ContentEvent;
|
||||||
|
use Thelia\Core\HttpFoundation\Request;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ContentListener extends BaseAction implements EventSubscriberInterface
|
||||||
|
{
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
public function __construct(Request $request)
|
||||||
|
{
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function getSubscribedEvents()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ContentEvent::PRE_DELETE => [ "deleteRecipeBeforeContent", 100 ]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deleteRecipeBeforeContent(ContentEvent $event)
|
||||||
|
{
|
||||||
|
$con = Propel::getConnection();
|
||||||
|
|
||||||
|
$contentId = $this->request->request->get('content_id');
|
||||||
|
$recipeId = RecipeQuery::create()
|
||||||
|
->findOneByContentId($contentId)
|
||||||
|
->getId();
|
||||||
|
|
||||||
|
if ($recipeId)
|
||||||
|
{
|
||||||
|
RecipeStepsQuery::create()
|
||||||
|
->filterByRecipeId($recipeId)
|
||||||
|
->find($con)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
RecipeProductsQuery::create()
|
||||||
|
->filterByRecipeId($recipeId)
|
||||||
|
->find($con)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
RecipeQuery::create()
|
||||||
|
->findOneByContentId($contentId)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user