From 04e0da56e7d3954e46758c9c61b2f53a5aebfb45 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Sat, 21 Sep 2013 16:58:38 +0200 Subject: [PATCH] fix issue, default foler is set on content creation --- core/lib/Thelia/Action/Content.php | 3 +-- core/lib/Thelia/Model/Content.php | 30 +++++++++++++++++++++++ templates/admin/default/content-edit.html | 6 ++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Action/Content.php b/core/lib/Thelia/Action/Content.php index 57ba90867..4c8810a40 100644 --- a/core/lib/Thelia/Action/Content.php +++ b/core/lib/Thelia/Action/Content.php @@ -47,8 +47,7 @@ class Content extends BaseAction implements EventSubscriberInterface ->setVisible($event->getVisible()) ->setLocale($event->getLocale()) ->setTitle($event->getTitle()) - ->addFolder(FolderQuery::create()->findPk($event->getDefaultFolder())) - ->save() + ->create($event->getDefaultFolder()) ; $event->setContent($content); diff --git a/core/lib/Thelia/Model/Content.php b/core/lib/Thelia/Model/Content.php index 47e90ab09..508913a97 100755 --- a/core/lib/Thelia/Model/Content.php +++ b/core/lib/Thelia/Model/Content.php @@ -2,9 +2,11 @@ namespace Thelia\Model; +use Propel\Runtime\Propel; use Thelia\Core\Event\Content\ContentEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Model\Base\Content as BaseContent; +use Thelia\Model\Map\ContentTableMap; use Thelia\Tools\URL; use Propel\Runtime\Connection\ConnectionInterface; @@ -43,6 +45,34 @@ class Content extends BaseContent return $default_folder == null ? 0 : $default_folder->getFolderId(); } + public function create($defaultFolderId) + { + $con = Propel::getWriteConnection(ContentTableMap::DATABASE_NAME); + + $con->beginTransaction(); + + $this->dispatchEvent(TheliaEvents::BEFORE_CREATECONTENT, new ContentEvent($this)); + + try { + $this->save($con); + + $cf = new ContentFolder(); + $cf->setContentId($this->getId()) + ->setFolderId($defaultFolderId) + ->setDefaultFolder(1) + ->save($con); + + $this->setPosition($this->getNextPosition())->save($con); + + $con->commit(); + } catch(\Exception $ex) { + + $con->rollback(); + + throw $ex; + } + } + /** * {@inheritDoc} diff --git a/templates/admin/default/content-edit.html b/templates/admin/default/content-edit.html index e8ef4a5b1..a7b55dfb8 100644 --- a/templates/admin/default/content-edit.html +++ b/templates/admin/default/content-edit.html @@ -100,10 +100,10 @@