Skip to content

Commit

Permalink
Added "code" parameter to selections
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Dec 30, 2020
1 parent a60e474 commit 66f328b
Show file tree
Hide file tree
Showing 30 changed files with 480 additions and 234 deletions.
21 changes: 11 additions & 10 deletions Action/SelectionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function updateSeo(
UpdateSeoEvent $event,
/** @noinspection PhpUnusedParameterInspection */
$eventName,
EventDispatcherInterface $dispatcher)
{
EventDispatcherInterface $dispatcher
) {
return $this->genericUpdateSeo(SelectionQuery::create(), $event, $dispatcher);
}

Expand All @@ -84,7 +84,6 @@ public function delete(SelectionEvent $event)
->update(array(
"View" => ConfigQuery::getObsoleteRewrittenUrlView()
));

}

protected function getSelection(SelectionEvent $event)
Expand Down Expand Up @@ -118,6 +117,10 @@ protected function createOrUpdate(SelectionEvent $event, Selection $model)
$model->setId($id);
}

if (null !== $code = $event->getCode()) {
$model->setCode($code);
}

if (null !== $title = $event->getTitle()) {
$model->setTitle($title);
}
Expand Down Expand Up @@ -157,14 +160,14 @@ protected function updateContainerAssociatedToSelection(SelectionEvent $event, C
$associationQuery = SelectionContainerAssociatedSelectionQuery::create();
$association = $associationQuery->findOneBySelectionId($event->getId());
$containerId = $event->getContainerId();
if (empty($association)) {
if ($association === null) {
if (empty($containerId)) {
return;
}
$association = new SelectionContainerAssociatedSelection();
$association->setSelectionId($event->getId());
} else if ($association->getSelectionContainerId() === $containerId) {
return;
return;
} else if (empty($containerId)) {
$association->delete($con);
return;
Expand Down Expand Up @@ -202,8 +205,7 @@ public function updateProductPosition(
$eventName,
/** @noinspection PhpUnusedParameterInspection */
EventDispatcherInterface $dispatcher
)
{
) {
$this->genericUpdateDelegatePosition(
SelectionProductQuery::create()
->filterByProductId($event->getObjectId())
Expand All @@ -222,8 +224,7 @@ public function updatePosition(
/** @noinspection PhpUnusedParameterInspection */
$eventName,
EventDispatcherInterface $dispatcher
)
{
) {
$modelCriteria = SelectionQuery::create()->filterById($event->getObjectId());
$this->genericUpdateDelegatePosition(
$modelCriteria,
Expand Down Expand Up @@ -271,4 +272,4 @@ public static function getSubscribedEvents()
SelectionEvents::RELATED_PRODUCT_UPDATE_POSITION => array("updateProductPosition", 128),
);
}
}
}
30 changes: 18 additions & 12 deletions Action/SelectionContainerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Selection\Action;


use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Propel;
use Selection\Event\SelectionContainerEvent;
Expand Down Expand Up @@ -58,8 +57,8 @@ public function updateSeo(
UpdateSeoEvent $event,
/** @noinspection PhpUnusedParameterInspection */
$eventName,
EventDispatcherInterface $dispatcher)
{
EventDispatcherInterface $dispatcher
) {
return $this->genericUpdateSeo(SelectionContainerQuery::create(), $event, $dispatcher);
}

Expand Down Expand Up @@ -102,6 +101,10 @@ protected function createOrUpdate(SelectionContainerEvent $event, SelectionConta
$model->setId($id);
}

if (null !== $code = $event->getCode()) {
$model->setCode($code);
}

if (null !== $title = $event->getTitle()) {
$model->setTitle($title);
}
Expand Down Expand Up @@ -156,8 +159,7 @@ public function updatePosition(
/** @noinspection PhpUnusedParameterInspection */
$eventName,
EventDispatcherInterface $dispatcher
)
{
) {
$modelCriteria = SelectionContainerQuery::create()->filterById($event->getObjectId());
$this->genericUpdateDelegatePosition(
$modelCriteria,
Expand All @@ -166,12 +168,16 @@ public function updatePosition(
);
}

/**
* @param ModelCriteria $query
* @param UpdatePositionEvent $event
* @param EventDispatcherInterface|null $dispatcher
*/
protected function genericUpdateDelegatePosition(
ModelCriteria $query,
UpdatePositionEvent $event,
EventDispatcherInterface $dispatcher = null)
{

EventDispatcherInterface $dispatcher = null
) {
if (null !== $object = $query->findOne()) {
if (!isset(class_uses($object)['Thelia\Model\Tools\PositionManagementTrait'])) {
throw new \InvalidArgumentException("Your model does not implement the PositionManagementTrait trait");
Expand All @@ -183,11 +189,11 @@ protected function genericUpdateDelegatePosition(

$mode = $event->getMode();

if ($mode == UpdatePositionEvent::POSITION_ABSOLUTE) {
if ($mode === UpdatePositionEvent::POSITION_ABSOLUTE) {
$object->changeAbsolutePosition($event->getPosition());
} elseif ($mode == UpdatePositionEvent::POSITION_UP) {
} elseif ($mode === UpdatePositionEvent::POSITION_UP) {
$object->movePositionUp();
} elseif ($mode == UpdatePositionEvent::POSITION_DOWN) {
} elseif ($mode === UpdatePositionEvent::POSITION_DOWN) {
$object->movePositionDown();
}
}
Expand All @@ -208,4 +214,4 @@ public static function getSubscribedEvents()
SelectionEvents::SELECTION_CONTAINER_TOGGLE_VISIBILITY => array("toggleVisibility", 128),
);
}
}
}
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.12</version>
<version>1.1.13</version>
<authors>
<author>
<name>Maxime BRUCHET</name>
Expand Down
1 change: 1 addition & 0 deletions Config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<!-- ******************************* Root link to selection list ******************************* -->

<route id="selection.list" path="/admin/selection">
<default key="_controller">Selection\Controller\SelectionController::viewAction</default>
</route>
Expand Down
4 changes: 3 additions & 1 deletion Config/schema.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../core/vendor/propel/propel/resources/xsd/database.xsd" >
xsi:noNamespaceSchemaLocation="../../../../core/vendor/thelia/propel/resources/xsd/database.xsd" >

<table name="selection" namespace="Selection\Model">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER"/>
<column name="visible" required="true" type="TINYINT"/>
<column name="code" type="VARCHAR" size="255" />
<column name="title" type="VARCHAR" size="255" />
<column name="description" type="LONGVARCHAR" />
<column name="chapo" type="LONGVARCHAR" />
Expand Down Expand Up @@ -72,6 +73,7 @@
<table name="selection_container" namespace="Selection\Model" allowPkInsert="true">
<column autoIncrement="true" name="id" primaryKey="true" required="true" type="INTEGER"/>
<column name="visible" required="true" type="TINYINT"/>
<column name="code" type="VARCHAR" size="255" />
<column name="title" type="VARCHAR" size="255" />
<column name="description" type="LONGVARCHAR" />
<column name="chapo" type="LONGVARCHAR" />
Expand Down
2 changes: 0 additions & 2 deletions Config/sqldb.map

This file was deleted.

18 changes: 10 additions & 8 deletions Config/thelia.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE `selection`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`visible` TINYINT NOT NULL,
`code` VARCHAR(255),
`position` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
Expand All @@ -33,7 +34,7 @@ CREATE TABLE `selection_product`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`selection_id`,`product_id`),
INDEX `FI_selection_product_product_id` (`product_id`),
INDEX `fi_selection_product_product_id` (`product_id`),
CONSTRAINT `fk_selection_product_product_id`
FOREIGN KEY (`product_id`)
REFERENCES `product` (`id`)
Expand All @@ -60,7 +61,7 @@ CREATE TABLE `selection_content`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`selection_id`,`content_id`),
INDEX `FI_selection_content_content_id` (`content_id`),
INDEX `fi_selection_content_content_id` (`content_id`),
CONSTRAINT `fk_selection_content_content_id`
FOREIGN KEY (`content_id`)
REFERENCES `content` (`id`)
Expand Down Expand Up @@ -89,7 +90,7 @@ CREATE TABLE `selection_image`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `FI_selection_image_selection_id` (`selection_id`),
INDEX `fi_selection_image_selection_id` (`selection_id`),
CONSTRAINT `fk_selection_image_selection_id`
FOREIGN KEY (`selection_id`)
REFERENCES `selection` (`id`)
Expand All @@ -107,6 +108,7 @@ CREATE TABLE `selection_container`
(
`id` INTEGER NOT NULL AUTO_INCREMENT,
`visible` TINYINT NOT NULL,
`code` VARCHAR(255),
`position` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
Expand Down Expand Up @@ -157,7 +159,7 @@ CREATE TABLE `selection_container_image`
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
INDEX `FI_selection_container_image_selection_id` (`selection_container_id`),
INDEX `fi_selection_container_image_selection_id` (`selection_container_id`),
CONSTRAINT `fk_selection_container_image_selection_id`
FOREIGN KEY (`selection_container_id`)
REFERENCES `selection_container` (`id`)
Expand All @@ -183,7 +185,7 @@ CREATE TABLE `selection_i18n`
`meta_description` TEXT,
`meta_keywords` TEXT,
PRIMARY KEY (`id`,`locale`),
CONSTRAINT `selection_i18n_FK_1`
CONSTRAINT `selection_i18n_fk_765b89`
FOREIGN KEY (`id`)
REFERENCES `selection` (`id`)
ON DELETE CASCADE
Expand All @@ -204,7 +206,7 @@ CREATE TABLE `selection_image_i18n`
`chapo` TEXT,
`postscriptum` TEXT,
PRIMARY KEY (`id`,`locale`),
CONSTRAINT `selection_image_i18n_FK_1`
CONSTRAINT `selection_image_i18n_fk_d501a8`
FOREIGN KEY (`id`)
REFERENCES `selection_image` (`id`)
ON DELETE CASCADE
Expand All @@ -228,7 +230,7 @@ CREATE TABLE `selection_container_i18n`
`meta_description` TEXT,
`meta_keywords` TEXT,
PRIMARY KEY (`id`,`locale`),
CONSTRAINT `selection_container_i18n_FK_1`
CONSTRAINT `selection_container_i18n_fk_25b287`
FOREIGN KEY (`id`)
REFERENCES `selection_container` (`id`)
ON DELETE CASCADE
Expand All @@ -249,7 +251,7 @@ CREATE TABLE `selection_container_image_i18n`
`chapo` TEXT,
`postscriptum` TEXT,
PRIMARY KEY (`id`,`locale`),
CONSTRAINT `selection_container_image_i18n_FK_1`
CONSTRAINT `selection_container_image_i18n_fk_eed190`
FOREIGN KEY (`id`)
REFERENCES `selection_container_image` (`id`)
ON DELETE CASCADE
Expand Down
11 changes: 11 additions & 0 deletions Config/update/1.1.13.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SET FOREIGN_KEY_CHECKS = 0;

-- Add the 'code' column to the selection tables.
ALTER TABLE `selection` ADD `code` varchar(255) NOT NULL AFTER `visible`;
ALTER TABLE `selection_container` ADD `code` varchar(255) NOT NULL AFTER `visible`;

-- Generate a pseudo-code for each existing selection
UPDATE `selection` set `code` = CONCAT('selection_', id);
UPDATE `selection_container` set `code` = CONCAT('container_', id);

SET FOREIGN_KEY_CHECKS = 1;
Loading

0 comments on commit 66f328b

Please sign in to comment.