Inital commit
This commit is contained in:
@@ -11,7 +11,12 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Propel\Runtime\Propel;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Thelia\Core\Event\File\FileDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
|
||||
@@ -19,21 +24,24 @@ use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\UpdateSeoEvent;
|
||||
use Thelia\Core\Event\ViewCheckEvent;
|
||||
use Thelia\Model\FolderDocumentQuery;
|
||||
use Thelia\Model\FolderImageQuery;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Model\Folder as FolderModel;
|
||||
use Thelia\Model\Map\FolderTableMap;
|
||||
|
||||
/**
|
||||
* Class Folder
|
||||
* @package Thelia\Action
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class Folder extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
public function update(FolderUpdateEvent $event)
|
||||
public function update(FolderUpdateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
|
||||
if (null !== $folder = FolderQuery::create()->findPk($event->getFolderId())) {
|
||||
$folder->setDispatcher($event->getDispatcher());
|
||||
$folder->setDispatcher($dispatcher);
|
||||
|
||||
$folder
|
||||
->setParent($event->getParent())
|
||||
@@ -53,32 +61,60 @@ class Folder extends BaseAction implements EventSubscriberInterface
|
||||
/**
|
||||
* Change Folder SEO
|
||||
*
|
||||
* @param \Thelia\Core\Event\UpdateSeoEvent $event
|
||||
*
|
||||
* @return mixed
|
||||
* @param UpdateSeoEvent $event
|
||||
* @param $eventName
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
* @return Object
|
||||
*/
|
||||
public function updateSeo(UpdateSeoEvent $event)
|
||||
public function updateSeo(UpdateSeoEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
return $this->genericUpdateSeo(FolderQuery::create(), $event);
|
||||
return $this->genericUpdateSeo(FolderQuery::create(), $event, $dispatcher);
|
||||
}
|
||||
|
||||
public function delete(FolderDeleteEvent $event)
|
||||
public function delete(FolderDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
if (null !== $folder = FolderQuery::create()->findPk($event->getFolderId())) {
|
||||
$folder->setDispatcher($event->getDispatcher())
|
||||
->delete();
|
||||
$con = Propel::getWriteConnection(FolderTableMap::DATABASE_NAME);
|
||||
$con->beginTransaction();
|
||||
|
||||
$event->setFolder($folder);
|
||||
try {
|
||||
$fileList = ['images' => [], 'documentList' => []];
|
||||
|
||||
// Get folder's files to delete after folder deletion
|
||||
$fileList['images']['list'] = FolderImageQuery::create()
|
||||
->findByFolderId($event->getFolderId());
|
||||
$fileList['images']['type'] = TheliaEvents::IMAGE_DELETE;
|
||||
|
||||
$fileList['documentList']['list'] = FolderDocumentQuery::create()
|
||||
->findByFolderId($event->getFolderId());
|
||||
$fileList['documentList']['type'] = TheliaEvents::DOCUMENT_DELETE;
|
||||
|
||||
// Delete folder
|
||||
$folder->setDispatcher($dispatcher)
|
||||
->delete($con);
|
||||
|
||||
$event->setFolder($folder);
|
||||
|
||||
// Dispatch delete folder's files event
|
||||
foreach ($fileList as $fileTypeList) {
|
||||
foreach ($fileTypeList['list'] as $fileToDelete) {
|
||||
$fileDeleteEvent = new FileDeleteEvent($fileToDelete);
|
||||
$dispatcher->dispatch($fileTypeList['type'], $fileDeleteEvent);
|
||||
}
|
||||
}
|
||||
|
||||
$con->commit();
|
||||
} catch (\Exception $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FolderCreateEvent $event
|
||||
*/
|
||||
public function create(FolderCreateEvent $event)
|
||||
public function create(FolderCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$folder = new FolderModel();
|
||||
$folder->setDispatcher($event->getDispatcher());
|
||||
$folder->setDispatcher($dispatcher);
|
||||
|
||||
$folder
|
||||
->setParent($event->getParent())
|
||||
@@ -90,23 +126,22 @@ class Folder extends BaseAction implements EventSubscriberInterface
|
||||
$event->setFolder($folder);
|
||||
}
|
||||
|
||||
public function toggleVisibility(FolderToggleVisibilityEvent $event)
|
||||
public function toggleVisibility(FolderToggleVisibilityEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
$folder = $event->getFolder();
|
||||
|
||||
$folder
|
||||
->setDispatcher($event->getDispatcher())
|
||||
->setDispatcher($dispatcher)
|
||||
->setVisible(!$folder->getVisible())
|
||||
->save();
|
||||
|
||||
$event->setFolder($folder);
|
||||
|
||||
}
|
||||
|
||||
public function updatePosition(UpdatePositionEvent $event)
|
||||
public function updatePosition(UpdatePositionEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
if (null !== $folder = FolderQuery::create()->findPk($event->getObjectId())) {
|
||||
$folder->setDispatcher($event->getDispatcher());
|
||||
$folder->setDispatcher($dispatcher);
|
||||
|
||||
switch ($event->getMode()) {
|
||||
case UpdatePositionEvent::POSITION_ABSOLUTE:
|
||||
@@ -123,24 +158,37 @@ class Folder extends BaseAction implements EventSubscriberInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
* Check if is a folder view and if folder_id is visible
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
* @param ViewCheckEvent $event
|
||||
* @param string $eventName
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function viewCheck(ViewCheckEvent $event, $eventName, EventDispatcherInterface $dispatcher)
|
||||
{
|
||||
if ($event->getView() == 'folder') {
|
||||
$folder = FolderQuery::create()
|
||||
->filterById($event->getViewId())
|
||||
->filterByVisible(1)
|
||||
->count();
|
||||
|
||||
if ($folder == 0) {
|
||||
$dispatcher->dispatch(TheliaEvents::VIEW_FOLDER_ID_NOT_VISIBLE, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ViewCheckEvent $event
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function viewFolderIdNotVisible(ViewCheckEvent $event)
|
||||
{
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
@@ -151,7 +199,10 @@ class Folder extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::FOLDER_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
|
||||
|
||||
TheliaEvents::FOLDER_UPDATE_POSITION => array("updatePosition", 128),
|
||||
TheliaEvents::FOLDER_UPDATE_SEO => array('updateSeo', 128)
|
||||
TheliaEvents::FOLDER_UPDATE_SEO => array('updateSeo', 128),
|
||||
|
||||
TheliaEvents::VIEW_CHECK => array('viewCheck', 128),
|
||||
TheliaEvents::VIEW_FOLDER_ID_NOT_VISIBLE => array('viewFolderIdNotVisible', 128),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user