+ * $query->filterByAttributeTemplatecol('fooValue'); // WHERE attribute_templatecol = 'fooValue'
+ * $query->filterByAttributeTemplatecol('%fooValue%'); // WHERE attribute_templatecol LIKE '%fooValue%'
+ *
+ *
+ * @param string $attributeTemplatecol The value to use as filter.
+ * Accepts wildcards (* and % trigger a LIKE)
+ * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
+ *
+ * @return ChildAttributeTemplateQuery The current query, for fluid interface
+ */
+ public function filterByAttributeTemplatecol($attributeTemplatecol = null, $comparison = null)
+ {
+ if (null === $comparison) {
+ if (is_array($attributeTemplatecol)) {
+ $comparison = Criteria::IN;
+ } elseif (preg_match('/[\%\*]/', $attributeTemplatecol)) {
+ $attributeTemplatecol = str_replace('*', '%', $attributeTemplatecol);
+ $comparison = Criteria::LIKE;
+ }
+ }
+
+ return $this->addUsingAlias(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL, $attributeTemplatecol, $comparison);
+ }
+
/**
* Filter the query on the created_at column
*
diff --git a/core/lib/Thelia/Model/CategoryDocument.php b/core/lib/Thelia/Model/CategoryDocument.php
index 5724e2df1..0917ab30c 100755
--- a/core/lib/Thelia/Model/CategoryDocument.php
+++ b/core/lib/Thelia/Model/CategoryDocument.php
@@ -25,4 +25,28 @@ class CategoryDocument extends BaseCategoryDocument
return true;
}
+
+ /**
+ * Set Document parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setCategoryId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Document parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getCategoryId();
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Model/CategoryImage.php b/core/lib/Thelia/Model/CategoryImage.php
index 5bf964e10..17ee387b5 100755
--- a/core/lib/Thelia/Model/CategoryImage.php
+++ b/core/lib/Thelia/Model/CategoryImage.php
@@ -2,6 +2,8 @@
namespace Thelia\Model;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
use Thelia\Model\Base\CategoryImage as BaseCategoryImage;
use Propel\Runtime\Connection\ConnectionInterface;
@@ -25,4 +27,29 @@ class CategoryImage extends BaseCategoryImage
return true;
}
+
+ /**
+ * Set Image parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setCategoryId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Image parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getCategoryId();
+ }
+
}
diff --git a/core/lib/Thelia/Model/ContentDocument.php b/core/lib/Thelia/Model/ContentDocument.php
index 8ecf3a3a9..1409b2713 100755
--- a/core/lib/Thelia/Model/ContentDocument.php
+++ b/core/lib/Thelia/Model/ContentDocument.php
@@ -25,4 +25,28 @@ class ContentDocument extends BaseContentDocument
return true;
}
+
+ /**
+ * Set Document parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setContentId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Document parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getContentId();
+ }
}
diff --git a/core/lib/Thelia/Model/ContentImage.php b/core/lib/Thelia/Model/ContentImage.php
index ac1dcf755..b6a3085d4 100755
--- a/core/lib/Thelia/Model/ContentImage.php
+++ b/core/lib/Thelia/Model/ContentImage.php
@@ -25,4 +25,28 @@ class ContentImage extends BaseContentImage
return true;
}
+
+ /**
+ * Set Image parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setContentId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Image parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getContentId();
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Model/FeatureProduct.php b/core/lib/Thelia/Model/FeatureProduct.php
index 35a9b2ddc..fe6c5d8c1 100755
--- a/core/lib/Thelia/Model/FeatureProduct.php
+++ b/core/lib/Thelia/Model/FeatureProduct.php
@@ -3,8 +3,66 @@
namespace Thelia\Model;
use Thelia\Model\Base\FeatureProduct as BaseFeatureProduct;
+use Thelia\Core\Event\TheliaEvents;
+use Propel\Runtime\Connection\ConnectionInterface;
+use Thelia\Core\Event\FeatureProductEvent;
- class FeatureProduct extends BaseFeatureProduct
+class FeatureProduct extends BaseFeatureProduct
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_CREATEFEATURE_PRODUCT, new FeatureProductEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postInsert(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_CREATEFEATURE_PRODUCT, new FeatureProductEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_UPDATEFEATURE_PRODUCT, new FeatureProductEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postUpdate(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_UPDATEFEATURE_PRODUCT, new FeatureProductEvent($this));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::BEFORE_DELETEFEATURE_PRODUCT, new FeatureProductEvent($this));
+
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function postDelete(ConnectionInterface $con = null)
+ {
+ $this->dispatchEvent(TheliaEvents::AFTER_DELETEFEATURE_PRODUCT, new FeatureProductEvent($this));
+ }
}
diff --git a/core/lib/Thelia/Model/FeatureTemplate.php b/core/lib/Thelia/Model/FeatureTemplate.php
index 47a33027a..3f28a3a10 100644
--- a/core/lib/Thelia/Model/FeatureTemplate.php
+++ b/core/lib/Thelia/Model/FeatureTemplate.php
@@ -3,8 +3,30 @@
namespace Thelia\Model;
use Thelia\Model\Base\FeatureTemplate as BaseFeatureTemplate;
+use Propel\Runtime\Connection\ConnectionInterface;
- class FeatureTemplate extends BaseFeatureTemplate
+class FeatureTemplate extends BaseFeatureTemplate
{
+ use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+ use \Thelia\Model\Tools\PositionManagementTrait;
+
+ /**
+ * Calculate next position relative to our template
+ */
+ protected function addCriteriaToPositionQuery($query)
+ {
+ $query->filterByTemplateId($this->getTemplateId());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function preInsert(ConnectionInterface $con = null)
+ {
+ // Set the current position for the new object
+ $this->setPosition($this->getNextPosition());
+
+ return true;
+ }
}
diff --git a/core/lib/Thelia/Model/FolderDocument.php b/core/lib/Thelia/Model/FolderDocument.php
index 0a86995d2..1d84d9e55 100755
--- a/core/lib/Thelia/Model/FolderDocument.php
+++ b/core/lib/Thelia/Model/FolderDocument.php
@@ -25,4 +25,28 @@ class FolderDocument extends BaseFolderDocument
return true;
}
+
+ /**
+ * Set Document parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setFolderId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Document parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getFolderId();
+ }
}
diff --git a/core/lib/Thelia/Model/FolderImage.php b/core/lib/Thelia/Model/FolderImage.php
index 58d8f928e..f9491c9a5 100755
--- a/core/lib/Thelia/Model/FolderImage.php
+++ b/core/lib/Thelia/Model/FolderImage.php
@@ -25,4 +25,28 @@ class FolderImage extends BaseFolderImage
return true;
}
+
+ /**
+ * Set Image parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setFolderId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Image parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getFolderId();
+ }
}
diff --git a/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php
index 1df6d56c1..c0df89d8f 100644
--- a/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php
+++ b/core/lib/Thelia/Model/Map/AttributeTemplateTableMap.php
@@ -57,7 +57,7 @@ class AttributeTemplateTableMap extends TableMap
/**
* The total number of columns
*/
- const NUM_COLUMNS = 6;
+ const NUM_COLUMNS = 7;
/**
* The number of lazy-loaded columns
@@ -67,7 +67,7 @@ class AttributeTemplateTableMap extends TableMap
/**
* The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS)
*/
- const NUM_HYDRATE_COLUMNS = 6;
+ const NUM_HYDRATE_COLUMNS = 7;
/**
* the column name for the ID field
@@ -89,6 +89,11 @@ class AttributeTemplateTableMap extends TableMap
*/
const POSITION = 'attribute_template.POSITION';
+ /**
+ * the column name for the ATTRIBUTE_TEMPLATECOL field
+ */
+ const ATTRIBUTE_TEMPLATECOL = 'attribute_template.ATTRIBUTE_TEMPLATECOL';
+
/**
* the column name for the CREATED_AT field
*/
@@ -111,12 +116,12 @@ class AttributeTemplateTableMap extends TableMap
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
- self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'Position', 'CreatedAt', 'UpdatedAt', ),
- self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'position', 'createdAt', 'updatedAt', ),
- self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::POSITION, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ),
- self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'POSITION', 'CREATED_AT', 'UPDATED_AT', ),
- self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'position', 'created_at', 'updated_at', ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
+ self::TYPE_PHPNAME => array('Id', 'AttributeId', 'TemplateId', 'Position', 'AttributeTemplatecol', 'CreatedAt', 'UpdatedAt', ),
+ self::TYPE_STUDLYPHPNAME => array('id', 'attributeId', 'templateId', 'position', 'attributeTemplatecol', 'createdAt', 'updatedAt', ),
+ self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID, AttributeTemplateTableMap::ATTRIBUTE_ID, AttributeTemplateTableMap::TEMPLATE_ID, AttributeTemplateTableMap::POSITION, AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL, AttributeTemplateTableMap::CREATED_AT, AttributeTemplateTableMap::UPDATED_AT, ),
+ self::TYPE_RAW_COLNAME => array('ID', 'ATTRIBUTE_ID', 'TEMPLATE_ID', 'POSITION', 'ATTRIBUTE_TEMPLATECOL', 'CREATED_AT', 'UPDATED_AT', ),
+ self::TYPE_FIELDNAME => array('id', 'attribute_id', 'template_id', 'position', 'attribute_templatecol', 'created_at', 'updated_at', ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@@ -126,12 +131,12 @@ class AttributeTemplateTableMap extends TableMap
* e.g. self::$fieldKeys[self::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
- self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'Position' => 3, 'CreatedAt' => 4, 'UpdatedAt' => 5, ),
- self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'position' => 3, 'createdAt' => 4, 'updatedAt' => 5, ),
- self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::POSITION => 3, AttributeTemplateTableMap::CREATED_AT => 4, AttributeTemplateTableMap::UPDATED_AT => 5, ),
- self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'CREATED_AT' => 4, 'UPDATED_AT' => 5, ),
- self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'position' => 3, 'created_at' => 4, 'updated_at' => 5, ),
- self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, )
+ self::TYPE_PHPNAME => array('Id' => 0, 'AttributeId' => 1, 'TemplateId' => 2, 'Position' => 3, 'AttributeTemplatecol' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
+ self::TYPE_STUDLYPHPNAME => array('id' => 0, 'attributeId' => 1, 'templateId' => 2, 'position' => 3, 'attributeTemplatecol' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
+ self::TYPE_COLNAME => array(AttributeTemplateTableMap::ID => 0, AttributeTemplateTableMap::ATTRIBUTE_ID => 1, AttributeTemplateTableMap::TEMPLATE_ID => 2, AttributeTemplateTableMap::POSITION => 3, AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL => 4, AttributeTemplateTableMap::CREATED_AT => 5, AttributeTemplateTableMap::UPDATED_AT => 6, ),
+ self::TYPE_RAW_COLNAME => array('ID' => 0, 'ATTRIBUTE_ID' => 1, 'TEMPLATE_ID' => 2, 'POSITION' => 3, 'ATTRIBUTE_TEMPLATECOL' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
+ self::TYPE_FIELDNAME => array('id' => 0, 'attribute_id' => 1, 'template_id' => 2, 'position' => 3, 'attribute_templatecol' => 4, 'created_at' => 5, 'updated_at' => 6, ),
+ self::TYPE_NUM => array(0, 1, 2, 3, 4, 5, 6, )
);
/**
@@ -155,6 +160,7 @@ class AttributeTemplateTableMap extends TableMap
$this->addForeignKey('ATTRIBUTE_ID', 'AttributeId', 'INTEGER', 'attribute', 'ID', true, null, null);
$this->addForeignKey('TEMPLATE_ID', 'TemplateId', 'INTEGER', 'template', 'ID', true, null, null);
$this->addColumn('POSITION', 'Position', 'INTEGER', false, null, null);
+ $this->addColumn('ATTRIBUTE_TEMPLATECOL', 'AttributeTemplatecol', 'VARCHAR', false, 45, null);
$this->addColumn('CREATED_AT', 'CreatedAt', 'TIMESTAMP', false, null, null);
$this->addColumn('UPDATED_AT', 'UpdatedAt', 'TIMESTAMP', false, null, null);
} // initialize()
@@ -323,6 +329,7 @@ class AttributeTemplateTableMap extends TableMap
$criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_ID);
$criteria->addSelectColumn(AttributeTemplateTableMap::TEMPLATE_ID);
$criteria->addSelectColumn(AttributeTemplateTableMap::POSITION);
+ $criteria->addSelectColumn(AttributeTemplateTableMap::ATTRIBUTE_TEMPLATECOL);
$criteria->addSelectColumn(AttributeTemplateTableMap::CREATED_AT);
$criteria->addSelectColumn(AttributeTemplateTableMap::UPDATED_AT);
} else {
@@ -330,6 +337,7 @@ class AttributeTemplateTableMap extends TableMap
$criteria->addSelectColumn($alias . '.ATTRIBUTE_ID');
$criteria->addSelectColumn($alias . '.TEMPLATE_ID');
$criteria->addSelectColumn($alias . '.POSITION');
+ $criteria->addSelectColumn($alias . '.ATTRIBUTE_TEMPLATECOL');
$criteria->addSelectColumn($alias . '.CREATED_AT');
$criteria->addSelectColumn($alias . '.UPDATED_AT');
}
diff --git a/core/lib/Thelia/Model/Product.php b/core/lib/Thelia/Model/Product.php
index cbb6c0051..2348a9c0d 100755
--- a/core/lib/Thelia/Model/Product.php
+++ b/core/lib/Thelia/Model/Product.php
@@ -87,12 +87,46 @@ class Product extends BaseProduct
return $this;
}
+ public function updateDefaultCategory($defaultCategoryId) {
+
+ // Allow uncategorized products (NULL instead of 0, to bypass delete cascade constraint)
+ if ($defaultCategoryId <= 0) $defaultCategoryId = NULL;
+
+ // Update the default category
+ $productCategory = ProductCategoryQuery::create()
+ ->filterByProductId($this->getId())
+ ->filterByDefaultCategory(true)
+ ->findOne()
+ ;
+
+ if ($productCategory == null || $productCategory->getCategoryId() != $defaultCategoryId) {
+ exit;
+ // Delete the old default category
+ if ($productCategory !== null) $productCategory->delete();
+
+ // Add the new default category
+ $productCategory = new ProductCategory();
+
+ $productCategory
+ ->setProduct($this)
+ ->setCategoryId($defaultCategoryId)
+ ->setDefaultCategory(true)
+ ->save()
+ ;
+ }
+ }
+
/**
* Create a new product, along with the default category ID
*
* @param int $defaultCategoryId the default category ID of this product
+ * @param float $basePrice the product base price
+ * @param int $priceCurrencyId the price currency Id
+ * @param int $taxRuleId the product tax rule ID
+ * @param float $baseWeight base weight in Kg
*/
- public function create($defaultCategoryId) {
+
+ public function create($defaultCategoryId, $basePrice, $priceCurrencyId, $taxRuleId, $baseWeight) {
$con = Propel::getWriteConnection(ProductTableMap::DATABASE_NAME);
@@ -105,18 +139,13 @@ class Product extends BaseProduct
$this->save($con);
// Add the default category
- $pc = new ProductCategory();
-
- $pc
- ->setProduct($this)
- ->setCategoryId($defaultCategoryId)
- ->setDefaultCategory(true)
- ->save($con)
- ;
+ $this->updateDefaultCategory($defaultCategoryId);
// Set the position
$this->setPosition($this->getNextPosition())->save($con);
+ $this->setTaxRuleId($taxRuleId);
+
// Create an empty product sale element
$sale_elements = new ProductSaleElements();
@@ -125,7 +154,8 @@ class Product extends BaseProduct
->setRef($this->getRef())
->setPromo(0)
->setNewness(0)
- ->setWeight(0)
+ ->setWeight($baseWeight)
+ ->setIsDefault(true)
->save($con)
;
@@ -134,9 +164,9 @@ class Product extends BaseProduct
$product_price
->setProductSaleElements($sale_elements)
- ->setPromoPrice(0)
- ->setPrice(0)
- ->setCurrency(CurrencyQuery::create()->findOneByByDefault(true))
+ ->setPromoPrice($basePrice)
+ ->setPrice($basePrice)
+ ->setCurrencyId($priceCurrencyId)
->save($con)
;
diff --git a/core/lib/Thelia/Model/ProductAssociatedContent.php b/core/lib/Thelia/Model/ProductAssociatedContent.php
index e07ee2cd6..843d76ba1 100644
--- a/core/lib/Thelia/Model/ProductAssociatedContent.php
+++ b/core/lib/Thelia/Model/ProductAssociatedContent.php
@@ -11,11 +11,22 @@ class ProductAssociatedContent extends BaseProductAssociatedContent {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
+ use \Thelia\Model\Tools\PositionManagementTrait;
+
+ /**
+ * Calculate next position relative to our product
+ */
+ protected function addCriteriaToPositionQuery($query) {
+ $query->filterByProductId($this->getProductId());
+ }
+
/**
* {@inheritDoc}
*/
public function preInsert(ConnectionInterface $con = null)
{
+ $this->setPosition($this->getNextPosition());
+
$this->dispatchEvent(TheliaEvents::BEFORE_CREATEPRODUCT_ASSOCIATED_CONTENT, new ProductAssociatedContentEvent($this));
return true;
diff --git a/core/lib/Thelia/Model/ProductDocument.php b/core/lib/Thelia/Model/ProductDocument.php
index 53515ff3c..b0f8032da 100755
--- a/core/lib/Thelia/Model/ProductDocument.php
+++ b/core/lib/Thelia/Model/ProductDocument.php
@@ -26,4 +26,28 @@ class ProductDocument extends BaseProductDocument
return true;
}
+ /**
+ * Set Document parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setProductId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Document parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getProductId();
+ }
+
}
diff --git a/core/lib/Thelia/Model/ProductImage.php b/core/lib/Thelia/Model/ProductImage.php
index 4bf0c40a6..6cc3ddd8c 100755
--- a/core/lib/Thelia/Model/ProductImage.php
+++ b/core/lib/Thelia/Model/ProductImage.php
@@ -25,4 +25,28 @@ class ProductImage extends BaseProductImage
return true;
}
+
+ /**
+ * Set Image parent id
+ *
+ * @param int $parentId parent id
+ *
+ * @return $this
+ */
+ public function setParentId($parentId)
+ {
+ $this->setProductId($parentId);
+
+ return $this;
+ }
+
+ /**
+ * Get Image parent id
+ *
+ * @return int parent id
+ */
+ public function getParentId()
+ {
+ return $this->getProductId();
+ }
}
diff --git a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
index 70da830ac..642d07402 100644
--- a/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
+++ b/core/lib/Thelia/Model/Tools/PositionManagementTrait.php
@@ -126,7 +126,8 @@ trait PositionManagementTrait {
$result->setDispatcher($this->getDispatcher())->setPosition($my_position)->save();
$cnx->commit();
- } catch (Exception $e) {
+ }
+ catch (Exception $e) {
$cnx->rollback();
}
}
@@ -179,7 +180,10 @@ trait PositionManagementTrait {
try {
foreach ($results as $result) {
- $result->setDispatcher($this->getDispatcher())->setPosition($result->getPosition() + $delta)->save($cnx);
+
+ $objNewPosition = $result->getPosition() + $delta;
+
+ $result->setDispatcher($this->getDispatcher())->setPosition($objNewPosition)->save($cnx);
}
$this
@@ -188,7 +192,8 @@ trait PositionManagementTrait {
;
$cnx->commit();
- } catch (Exception $e) {
+ }
+ catch (Exception $e) {
$cnx->rollback();
}
}
diff --git a/core/lib/Thelia/Tests/Tools/FileManagerTest.php b/core/lib/Thelia/Tests/Tools/FileManagerTest.php
new file mode 100644
index 000000000..8c1c9fe99
--- /dev/null
+++ b/core/lib/Thelia/Tests/Tools/FileManagerTest.php
@@ -0,0 +1,906 @@
+
+ */
+
+namespace Thelia\Tests\Type;
+
+
+use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
+use Thelia\Core\Event\ImageCreateOrUpdateEvent;
+use Thelia\Core\Translation\Translator;
+use Thelia\Exception\ImageException;
+use Thelia\Model\Admin;
+use Thelia\Tools\FileManager;
+
+/**
+ * Class FileManagerTest
+ *
+ * @package Thelia\Tests\Type
+ */
+class FileManagerTest extends \PHPUnit_Framework_TestCase {
+
+
+ /**
+ * @covers Thelia\Tools\FileManager::copyUploadedFile
+ */
+ public function testCopyUploadedFile()
+ {
+ $this->markTestIncomplete(
+ 'Mock issue'
+ );
+
+ $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubTranslator->expects($this->any())
+ ->method('trans')
+ ->will($this->returnValue('translated'));
+
+ $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubSecurity->expects($this->any())
+ ->method('getAdminUser')
+ ->will($this->returnValue(new Admin()));
+
+
+
+ // Create a map of arguments to return values.
+ $map = array(
+ array('thelia.translator', $stubTranslator),
+ array('request', $stubRequest),
+ array('thelia.securityContext', $stubSecurity)
+ );
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubContainer->expects($this->any())
+ ->method('get')
+ ->will($this->returnValueMap($map));
+
+ $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductImage->expects($this->any())
+ ->method('getUploadDir')
+ ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product'));
+ $stubProductImage->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(42));
+ $stubProductImage->expects($this->any())
+ ->method('setFile')
+ ->will($this->returnValue(true));
+ $stubProductImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(0));
+
+ $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalName')
+ ->will($this->returnValue('goodName'));
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalExtension')
+ ->will($this->returnValue('png'));
+ $stubUploadedFile->expects($this->any())
+ ->method('move')
+ ->will($this->returnValue($stubUploadedFile));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $newUploadedFiles = array();
+
+ $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_IMAGES);
+
+ $this->assertCount(1, $actual);
+ }
+
+
+ /**
+ * @covers Thelia\Tools\FileManager::copyUploadedFile
+ * @expectedException \Thelia\Exception\ImageException
+ */
+ public function testCopyUploadedFileExceptionImageException()
+ {
+ $this->markTestIncomplete(
+ 'Mock issue'
+ );
+
+ $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubTranslator->expects($this->any())
+ ->method('trans')
+ ->will($this->returnValue('translated'));
+
+ $stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubSecurity = $this->getMockBuilder('\Thelia\Core\Security\SecurityContext')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubSecurity->expects($this->any())
+ ->method('getAdminUser')
+ ->will($this->returnValue(new Admin()));
+
+
+
+ // Create a map of arguments to return values.
+ $map = array(
+ array('thelia.translator', $stubTranslator),
+ array('request', $stubRequest),
+ array('thelia.securityContext', $stubSecurity)
+ );
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubContainer->expects($this->any())
+ ->method('get')
+ ->will($this->returnValueMap($map));
+
+ $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductImage->expects($this->any())
+ ->method('getUploadDir')
+ ->will($this->returnValue(THELIA_LOCAL_DIR . 'media/images/product'));
+ $stubProductImage->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(42));
+ $stubProductImage->expects($this->any())
+ ->method('setFile')
+ ->will($this->returnValue(true));
+ $stubProductImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(0));
+
+ $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalName')
+ ->will($this->returnValue('goodName'));
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalExtension')
+ ->will($this->returnValue('png'));
+ $stubUploadedFile->expects($this->any())
+ ->method('move')
+ ->will($this->returnValue($stubUploadedFile));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $newUploadedFiles = array();
+
+ $actual = $fileManager->copyUploadedFile(24, FileManager::TYPE_PRODUCT, $stubProductImage, $stubUploadedFile, $newUploadedFiles, FileManager::FILE_TYPE_DOCUMENTS);
+
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ */
+ public function testSaveImageProductImage()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubProductImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveImage($event, $stubProductImage);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ */
+ public function testSaveDocumentProductDocument()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubProductDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveDocument($event, $stubProductDocument);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ */
+ public function testSaveImageCategoryImage()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubCategoryImage = $this->getMockBuilder('\Thelia\Model\CategoryImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubCategoryImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubCategoryImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveImage($event, $stubCategoryImage);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ */
+ public function testSaveDocumentCategoryDocument()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubCategoryDocument = $this->getMockBuilder('\Thelia\Model\CategoryDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubCategoryDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubCategoryDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CATEGORY, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveDocument($event, $stubCategoryDocument);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ */
+ public function testSaveImageFolderImage()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubFolderImage = $this->getMockBuilder('\Thelia\Model\FolderImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubFolderImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubFolderImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveImage($event, $stubFolderImage);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ */
+ public function testSaveDocumentFolderDocument()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubFolderDocument = $this->getMockBuilder('\Thelia\Model\FolderDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubFolderDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubFolderDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_FOLDER, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveDocument($event, $stubFolderDocument);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ */
+ public function testSaveImageContentImage()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubContentImage = $this->getMockBuilder('\Thelia\Model\ContentImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubContentImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubContentImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveImage($event, $stubContentImage);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ */
+ public function testSaveDocumentContentDocument()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubContentDocument = $this->getMockBuilder('\Thelia\Model\ContentDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubContentDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubContentDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $fileManager = new FileManager($stubContainer);
+
+ $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_CONTENT, 24);
+
+ $expected = 10;
+ $actual = $fileManager->saveDocument($event, $stubContentDocument);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ * @expectedException \Thelia\Exception\ImageException
+ */
+ public function testSaveImageExceptionImageException()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileManager = new FileManager($stubContainer);
+
+ $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubProductImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $event = new ImageCreateOrUpdateEvent('bad', 24);
+
+ $fileManager->saveImage($event, $stubProductImage);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ * @expectedException \Thelia\Model\Exception\InvalidArgumentException
+ */
+ public function testSaveDocumentExceptionDocumentException()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileManager = new FileManager($stubContainer);
+
+ $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(10));
+ $stubProductDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $event = new DocumentCreateOrUpdateEvent('bad', 24);
+
+ $fileManager->saveDocument($event, $stubProductDocument);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveImage
+ * @expectedException \Thelia\Exception\ImageException
+ */
+ public function testSaveImageExceptionImageException2()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileManager = new FileManager($stubContainer);
+
+ $stubProductImage = $this->getMockBuilder('\Thelia\Model\ProductImage')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductImage->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(0));
+ $stubProductImage->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $event = new ImageCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24);
+
+ $fileManager->saveImage($event, $stubProductImage);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::saveDocument
+ * @expectedException \Thelia\Model\Exception\InvalidArgumentException
+ */
+ public function testSaveDocumentExceptionDocumentException2()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileManager = new FileManager($stubContainer);
+
+ $stubProductDocument = $this->getMockBuilder('\Thelia\Model\ProductDocument')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubProductDocument->expects($this->any())
+ ->method('save')
+ ->will($this->returnValue(0));
+ $stubProductDocument->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue('file'));
+
+ $event = new DocumentCreateOrUpdateEvent(FileManager::TYPE_PRODUCT, 24);
+
+ $fileManager->saveDocument($event, $stubProductDocument);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::sanitizeFileName
+ */
+ public function testSanitizeFileName()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $badFileName = 'a/ze\érà~çè§^"$*+-_°)(&é<>@#ty2/[\/:*?"<>|]/fi?.fUPPERile.exel../e*';
+
+ $expected = 'azer-_ty2fi.fupperile.exel..e';
+ $actual = $fileManager->sanitizeFileName($badFileName);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getImageModel
+ */
+ public function testGetImageModel()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $actual = $fileManager->getImageModel(FileManager::TYPE_PRODUCT);
+ $this->assertInstanceOf('\Thelia\Model\ProductImage', $actual);
+ $actual = $fileManager->getImageModel(FileManager::TYPE_CATEGORY);
+ $this->assertInstanceOf('\Thelia\Model\CategoryImage', $actual);
+ $actual = $fileManager->getImageModel(FileManager::TYPE_CONTENT);
+ $this->assertInstanceOf('\Thelia\Model\ContentImage', $actual);
+ $actual = $fileManager->getImageModel(FileManager::TYPE_FOLDER);
+ $this->assertInstanceOf('\Thelia\Model\FolderImage', $actual);
+ $actual = $fileManager->getImageModel('bad');
+ $this->assertNull($actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getDocumentModel
+ */
+ public function testGetDocumentModel()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $actual = $fileManager->getDocumentModel(FileManager::TYPE_PRODUCT);
+ $this->assertInstanceOf('\Thelia\Model\ProductDocument', $actual);
+ $actual = $fileManager->getDocumentModel(FileManager::TYPE_CATEGORY);
+ $this->assertInstanceOf('\Thelia\Model\CategoryDocument', $actual);
+ $actual = $fileManager->getDocumentModel(FileManager::TYPE_CONTENT);
+ $this->assertInstanceOf('\Thelia\Model\ContentDocument', $actual);
+ $actual = $fileManager->getDocumentModel(FileManager::TYPE_FOLDER);
+ $this->assertInstanceOf('\Thelia\Model\FolderDocument', $actual);
+ $actual = $fileManager->getDocumentModel('bad');
+ $this->assertNull($actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getImageModelQuery
+ */
+ public function testGetImageModelQuery()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $actual = $fileManager->getImageModelQuery(FileManager::TYPE_PRODUCT);
+ $this->assertInstanceOf('\Thelia\Model\ProductImageQuery', $actual);
+ $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CATEGORY);
+ $this->assertInstanceOf('\Thelia\Model\CategoryImageQuery', $actual);
+ $actual = $fileManager->getImageModelQuery(FileManager::TYPE_CONTENT);
+ $this->assertInstanceOf('\Thelia\Model\ContentImageQuery', $actual);
+ $actual = $fileManager->getImageModelQuery(FileManager::TYPE_FOLDER);
+ $this->assertInstanceOf('\Thelia\Model\FolderImageQuery', $actual);
+ $actual = $fileManager->getImageModelQuery('bad');
+ $this->assertNull($actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getDocumentModelQuery
+ */
+ public function testGetDocumentModelQuery()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_PRODUCT);
+ $this->assertInstanceOf('\Thelia\Model\ProductDocumentQuery', $actual);
+ $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CATEGORY);
+ $this->assertInstanceOf('\Thelia\Model\CategoryDocumentQuery', $actual);
+ $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_CONTENT);
+ $this->assertInstanceOf('\Thelia\Model\ContentDocumentQuery', $actual);
+ $actual = $fileManager->getDocumentModelQuery(FileManager::TYPE_FOLDER);
+ $this->assertInstanceOf('\Thelia\Model\FolderDocumentQuery', $actual);
+ $actual = $fileManager->getDocumentModelQuery('bad');
+ $this->assertNull($actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getParentFileModel
+ */
+ public function testGetParentFileModel()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+ $actual = $fileManager->getParentFileModel(FileManager::TYPE_PRODUCT, 1);
+ $this->assertInstanceOf('\Thelia\Model\Product', $actual);
+ $actual = $fileManager->getParentFileModel(FileManager::TYPE_CATEGORY, 1);
+ $this->assertInstanceOf('\Thelia\Model\Category', $actual);
+ $actual = $fileManager->getParentFileModel(FileManager::TYPE_CONTENT, 1);
+ $this->assertInstanceOf('\Thelia\Model\Content', $actual);
+ $actual = $fileManager->getParentFileModel(FileManager::TYPE_FOLDER, 1);
+ $this->assertInstanceOf('\Thelia\Model\Folder', $actual, 1);
+ $actual = $fileManager->getParentFileModel('bad', 1);
+ $this->assertNull($actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getImageForm
+ */
+ public function testGetImageForm()
+ {
+ // Mock issue
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+ /**
+ * @covers Thelia\Tools\FileManager::getDocumentForm
+ */
+ public function testGetDocumentForm()
+ {
+ // Mock issue
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getUploadDir
+ */
+ public function testGetUploadDir()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/product', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/category', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/content', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/images/folder', $actual);
+ $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(false, $actual);
+
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/product', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/category', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/content', $actual);
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(THELIA_LOCAL_DIR . 'media/documents/folder', $actual);
+ $actual = $fileManager->getUploadDir('bad', FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(false, $actual);
+
+ $actual = $fileManager->getUploadDir(FileManager::TYPE_FOLDER, 'bad');
+ $this->assertEquals(false, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::getRedirectionUrl
+ */
+ public function testGetRedirectionUrl()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('/admin/products/update?product_id=1¤t_tab=images', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=images', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('/admin/content/update/1?current_tab=images', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('/admin/folders/update/1?current_tab=images', $actual);
+ $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(false, $actual);
+
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_PRODUCT, 1, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('/admin/products/update?product_id=1¤t_tab=documents', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CATEGORY, 1, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('/admin/categories/update?category_id=1¤t_tab=documents', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_CONTENT, 1, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('/admin/content/update/1?current_tab=documents', $actual);
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('/admin/folders/update/1?current_tab=documents', $actual);
+ $actual = $fileManager->getRedirectionUrl('bad', 1, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(false, $actual);
+
+ $actual = $fileManager->getRedirectionUrl(FileManager::TYPE_FOLDER, 1, 'bad');
+ $this->assertEquals(false, $actual);
+ }
+
+
+ /**
+ * @covers Thelia\Tools\FileManager::getFormId
+ */
+ public function testGetFormId()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+
+ $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('thelia.admin.product.image.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('thelia.admin.category.image.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('thelia.admin.content.image.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals('thelia.admin.folder.image.modification', $actual);
+ $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_IMAGES);
+ $this->assertEquals(false, $actual);
+
+ $actual = $fileManager->getFormId(FileManager::TYPE_PRODUCT, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('thelia.admin.product.document.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_CATEGORY, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('thelia.admin.category.document.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_CONTENT, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('thelia.admin.content.document.modification', $actual);
+ $actual = $fileManager->getFormId(FileManager::TYPE_FOLDER, FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals('thelia.admin.folder.document.modification', $actual);
+ $actual = $fileManager->getFormId('bad', FileManager::FILE_TYPE_DOCUMENTS);
+ $this->assertEquals(false, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::renameFile
+ */
+ public function testRenameFile()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalExtension')
+ ->will($this->returnValue('yml'));
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalName')
+ ->will($this->returnValue('or1-g_n?al*/&é"filen@me#'));
+
+
+ $fileManager = new FileManager($stubContainer);
+
+ $expected = 'or1-g_nalfilenme-1.yml';
+ $actual = $fileManager->renameFile(1, $stubUploadedFile);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::renameFile
+ */
+ public function testRenameFileWithoutExtension()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $stubUploadedFile = $this->getMockBuilder('\Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalExtension')
+ ->will($this->returnValue(''));
+ $stubUploadedFile->expects($this->any())
+ ->method('getClientOriginalName')
+ ->will($this->returnValue('or1-g_n?al*/&é"filen@me#'));
+
+
+ $fileManager = new FileManager($stubContainer);
+
+ $expected = 'or1-g_nalfilenme-1';
+ $actual = $fileManager->renameFile(1, $stubUploadedFile);
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::isImage
+ */
+ public function testIsImage()
+ {
+ $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $fileManager = new FileManager($stubContainer);
+
+ $actual = $fileManager->isImage('image/jpeg');
+ $this->assertTrue($actual);
+ $actual = $fileManager->isImage('image/png');
+ $this->assertTrue($actual);
+ $actual = $fileManager->isImage('image/gif');
+ $this->assertTrue($actual);
+
+ $actual = $fileManager->isImage('bad');
+ $this->assertFalse($actual);
+ $actual = $fileManager->isImage('image/jpg');
+ $this->assertFalse($actual);
+ $actual = $fileManager->isImage('application/x-msdownload');
+ $this->assertFalse($actual);
+ $actual = $fileManager->isImage('application/x-sh');
+ $this->assertFalse($actual);
+
+ }
+
+
+ /**
+ * @covers Thelia\Tools\FileManager::getAvailableTypes
+ */
+ public function testGetAvailableTypes()
+ {
+ $expected = array(
+ FileManager::TYPE_CATEGORY,
+ FileManager::TYPE_CONTENT,
+ FileManager::TYPE_FOLDER,
+ FileManager::TYPE_PRODUCT,
+ FileManager::TYPE_MODULE,
+ );
+ $actual = FileManager::getAvailableTypes();
+
+ $this->assertEquals($expected, $actual);
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::adminLogAppend
+ */
+ public function testAdminLogAppend()
+ {
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+
+ /**
+ * @covers Thelia\Tools\FileManager::deleteFile
+ */
+ public function testDeleteFile()
+ {
+ // @todo see http://tech.vg.no/2011/03/09/mocking-the-file-system-using-phpunit-and-vfsstream/
+ $this->markTestIncomplete(
+ 'This test has not been implemented yet.'
+ );
+ }
+}
diff --git a/core/lib/Thelia/Tools/FileManager.php b/core/lib/Thelia/Tools/FileManager.php
new file mode 100644
index 000000000..ba5e1d24a
--- /dev/null
+++ b/core/lib/Thelia/Tools/FileManager.php
@@ -0,0 +1,726 @@
+. */
+/* */
+/**********************************************************************************/
+namespace Thelia\Tools;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
+use Thelia\Core\Event\ImageCreateOrUpdateEvent;
+use Thelia\Core\HttpFoundation\Request;
+use Thelia\Core\Translation\Translator;
+use Thelia\Exception\ImageException;
+use Thelia\Form\CategoryDocumentModification;
+use Thelia\Form\CategoryImageModification;
+use Thelia\Form\ContentDocumentModification;
+use Thelia\Form\ContentImageModification;
+use Thelia\Form\FolderDocumentModification;
+use Thelia\Form\FolderImageModification;
+use Thelia\Form\ProductDocumentModification;
+use Thelia\Form\ProductImageModification;
+use Thelia\Model\AdminLog;
+use Thelia\Model\CategoryDocument;
+use Thelia\Model\CategoryDocumentQuery;
+use Thelia\Model\CategoryImage;
+use Thelia\Model\CategoryImageQuery;
+use Thelia\Model\CategoryQuery;
+use Thelia\Model\ContentDocument;
+use Thelia\Model\ContentDocumentQuery;
+use Thelia\Model\ContentImage;
+use Thelia\Model\ContentImageQuery;
+use Thelia\Model\ContentQuery;
+use Thelia\Model\Exception\InvalidArgumentException;
+use Thelia\Model\FolderDocument;
+use Thelia\Model\FolderDocumentQuery;
+use Thelia\Model\FolderImage;
+use Thelia\Model\FolderImageQuery;
+use Thelia\Model\FolderQuery;
+use Thelia\Model\ProductDocument;
+use Thelia\Model\ProductDocumentQuery;
+use Thelia\Model\ProductImage;
+use Thelia\Model\ProductImageQuery;
+use Thelia\Model\ProductQuery;
+
+/**
+ * Created by JetBrains PhpStorm.
+ * Date: 9/19/13
+ * Time: 3:24 PM
+ *
+ * File Manager
+ *
+ * @package File
+ * @author Guillaume MOREL | {intl l='ID'} | + +{intl l='Content title'} | + +{intl l='Position'} | + + {module_include location='product_contents_table_header'} + +{intl l="Actions"} | +
|---|---|---|---|
| {$ID} | + ++ {$TITLE} + | + ++ {admin_position_block + permission="admin.products.edit" + path={url path='/admin/product/update-content-position' product_id=$product_id current_tab="related"} + url_parameter="content_id" + in_place_edit_class="contentPositionChange" + position=$POSITION + id=$ID + } + | + + {module_include location='product_contents_table_row'} + +
+
+ {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.product.content.delete"}
+
+
+
+ {/loop}
+
+ |
+
|
+
+ {intl l="This product contains no contents"}
+
+ |
+ |||
| {intl l='ID'} | + +{intl l='Accessory title'} | + +{intl l='Position'} | + + {module_include location='product_accessories_table_header'} + +{intl l="Actions"} | +
|---|---|---|---|
| {$ID} | + ++ {$TITLE} + | + ++ {admin_position_block + permission="admin.products.edit" + path={url path='/admin/product/update-accessory-position' product_id=$product_id current_tab="related"} + url_parameter="accessory_id" + in_place_edit_class="accessoryPositionChange" + position=$POSITION + id=$ID + } + | + + {module_include location='product_accessories_table_row'} + +
+
+ {loop type="auth" name="can_create" roles="ADMIN" permissions="admin.product.accessory.delete"}
+
+
+
+ {/loop}
+
+ |
+
|
+
+ {intl l="This product contains no accessories"}
+
+ |
+ |||
| {intl l='ID'} | + +{intl l='Category title'} | + + {module_include location='product_categories_table_header'} + +{intl l="Actions"} | +
|---|---|---|
| {$ID} | + ++ {$TITLE} + | + + {module_include location='product_categories_table_row'} + +
+
+ {loop type="auth" name="can_delete" roles="ADMIN" permissions="admin.product.category.delete"}
+
+
+
+ {/loop}
+
+ |
+
|
+
+ {intl l="This product doesn't belong to any additional category."}
+
+ |
+ ||