Merge branch 'master' into frontend

This commit is contained in:
Manuel Raynaud
2013-12-16 15:45:04 +01:00
42 changed files with 541 additions and 64 deletions

View File

@@ -18,7 +18,7 @@ class AdminLog extends BaseAdminLog
* @param Request $request
* @param Base\Admin $adminUser
*/
public static function append($resource, $action, $message, Request $request, BaseAdminUser $adminUser = null) {
public static function append($resource, $action, $message, Request $request, BaseAdminUser $adminUser = null, $withRequestContent = true) {
$log = new AdminLog();
@@ -29,7 +29,7 @@ class AdminLog extends BaseAdminLog
->setResource($resource)
->setAction($action)
->setMessage($message)
->setRequest($request->__toString())
->setRequest($request->toString($withRequestContent))
;
try {

View File

@@ -106,7 +106,11 @@ class Category extends BaseCategory
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETECATEGORY, new CategoryEvent($this));
$this->reorderBeforeDelete();
$this->reorderBeforeDelete(
array(
"parent" => $this->getParent(),
)
);
return true;
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class CategoryDocument extends BaseCategoryDocument
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class CategoryDocument extends BaseCategoryDocument
{
return $this->getCategoryId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"category_id" => $this->getCategoryId(),
)
);
return true;
}
}

View File

@@ -9,6 +9,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class CategoryImage extends BaseCategoryImage
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -52,4 +53,13 @@ class CategoryImage extends BaseCategoryImage
return $this->getCategoryId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"category_id" => $this->getCategoryId(),
)
);
return true;
}
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ContentDocument extends BaseContentDocument
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class ContentDocument extends BaseContentDocument
{
return $this->getContentId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"content_id" => $this->getContentId(),
)
);
return true;
}
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ContentImage extends BaseContentImage
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class ContentImage extends BaseContentImage
{
return $this->getContentId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"content_id" => $this->getContentId(),
)
);
return true;
}
}

View File

@@ -94,7 +94,11 @@ class Folder extends BaseFolder
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETEFOLDER, new FolderEvent($this));
$this->reorderBeforeDelete();
$this->reorderBeforeDelete(
array(
"parent" => $this->getParent(),
)
);
return true;
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class FolderDocument extends BaseFolderDocument
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class FolderDocument extends BaseFolderDocument
{
return $this->getFolderId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"folder_id" => $this->getFolderId(),
)
);
return true;
}
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class FolderImage extends BaseFolderImage
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class FolderImage extends BaseFolderImage
{
return $this->getFolderId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"folder_id" => $this->getFolderId(),
)
);
return true;
}
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ProductDocument extends BaseProductDocument
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -50,4 +51,14 @@ class ProductDocument extends BaseProductDocument
return $this->getProductId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"product_id" => $this->getProductId(),
)
);
return true;
}
}

View File

@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
class ProductImage extends BaseProductImage
{
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
use \Thelia\Model\Tools\PositionManagementTrait;
/**
@@ -49,4 +50,14 @@ class ProductImage extends BaseProductImage
{
return $this->getProductId();
}
public function preDelete(ConnectionInterface $con = null)
{
$this->reorderBeforeDelete(
array(
"product_id" => $this->getProductId(),
)
);
return true;
}
}

View File

@@ -199,19 +199,26 @@ trait PositionManagementTrait {
}
}
protected function reorderBeforeDelete()
protected function reorderBeforeDelete($fields = array())
{
// Find DATABASE_NAME constant
$mapClassName = self::TABLE_MAP;
$sql = sprintf("UPDATE `%s` SET position=(position-1) WHERE parent=:parent AND position>:position", $mapClassName::TABLE_NAME);
$data = array();
$whereCriteria = array();
foreach($fields as $field => $value) {
$whereCriteria[] = $field . '=:' . $field;
$data[':' . $field] = $value;
}
$data[':position'] = $this->getPosition();
$sql = sprintf("UPDATE `%s` SET position=(position-1) WHERE " . (count($whereCriteria)>0 ? implode(" AND ", $whereCriteria) : '1') . " AND position>:position", $mapClassName::TABLE_NAME);
$con = Propel::getConnection($mapClassName::DATABASE_NAME);
$statement = $con->prepare($sql);
$statement->execute(array(
':parent' => $this->getParent(),
':position' => $this->getPosition()
));
$statement->execute($data);
}
}