fix issue, default foler is set on content creation

This commit is contained in:
Manuel Raynaud
2013-09-21 16:58:38 +02:00
parent 4e3768e0e9
commit 04e0da56e7
3 changed files with 34 additions and 5 deletions

View File

@@ -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}