Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metadata] Fix modifying metadata by serializing it early #4670

Merged
merged 2 commits into from
Apr 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions features/legacy/backend/metadata/metadata_customization.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ Feature: Metadata customization
| Description | <empty> |
| Twitter | <empty> |

Scenario: Modifying existing page metadata
Given there is the following metadata "ZBIGNIEW-WODECKI":
| Title | Regular musician |
And I am customizing metadata with identifier "ZBIGNIEW-WODECKI"
When I fill in "Title" with "Expressive virtuoso"
And I press "Save changes"
Then I should be on the page of metadata container with id "ZBIGNIEW-WODECKI"
And I should see the following metadata:
| Title | Expressive virtuoso |

@javascript
Scenario: Managing dynamic Twitter form
Given I am customizing metadata
Expand Down
12 changes: 5 additions & 7 deletions src/Sylius/Bundle/CoreBundle/Behat/MetadataContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ public function iShouldNotSeeTwitterApplicationCardForm()
*/
public function thereIsTheFollowingMetadata($metadataName, TableNode $table)
{
/** @var MetadataContainerInterface $metadata */
$metadata = $this->getFactory('metadata_container')->createNew();

$pageMetadata = new PageMetadata();

$metadata->setId($metadataName);
$metadata->setMetadata($pageMetadata);

foreach ($table->getRowsHash() as $key => $value) {
if ($this->createNewMetadataObjectIfNeeded($pageMetadata, $key, $value)) {
continue;
Expand All @@ -201,6 +194,11 @@ public function thereIsTheFollowingMetadata($metadataName, TableNode $table)
$this->propertyAccessor->setValue($pageMetadata, $key, $value);
}

/** @var MetadataContainerInterface $metadata */
$metadata = $this->getFactory('metadata_container')->createNew();
$metadata->setId($metadataName);
$metadata->setMetadata($pageMetadata);

$em = $this->getEntityManager();
$em->persist($metadata);
$em->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace Sylius\Bundle\MetadataBundle\DependencyInjection;

use Sylius\Bundle\MetadataBundle\Controller\MetadataController;
use Sylius\Bundle\MetadataBundle\Form\Type\MetadataContainerType;
use Sylius\Bundle\MetadataBundle\Model\MetadataContainer;
use Sylius\Bundle\MetadataBundle\Form\Type\MetadataContainerType;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Sylius\Component\Metadata\Factory\MetadataContainerFactory;
use Sylius\Component\Metadata\Model\MetadataContainerInterface;
Expand Down
9 changes: 2 additions & 7 deletions src/Sylius/Bundle/MetadataBundle/Model/MetadataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
namespace Sylius\Bundle\MetadataBundle\Model;

use Sylius\Component\Metadata\Model\MetadataContainer as BaseMetadataContainer;
use Sylius\Component\Metadata\Model\MetadataContainerInterface;
use Sylius\Component\Metadata\Model\MetadataInterface;

/**
* @author Kamil Kokot <kamil.kokot@lakion.com>
*/
class MetadataContainer extends BaseMetadataContainer implements MetadataContainerInterface
class MetadataContainer extends BaseMetadataContainer
{
/**
* @var MetadataInterface
Expand All @@ -43,10 +42,6 @@ public function getMetadata()
public function setMetadata(MetadataInterface $metadata)
{
$this->metadataAsObject = $metadata;
}

public function serializeMetadata()
{
$this->metadata = serialize($this->metadataAsObject);
$this->metadata = serialize($metadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@
-->

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">

<mapped-superclass name="Sylius\Bundle\MetadataBundle\Model\MetadataContainer" table="sylius_metadata">
<id name="id" column="id" type="string" />

<field name="metadata" column="metadata" type="text" />

<lifecycle-callbacks>
<lifecycle-callback type="prePersist" method="serializeMetadata" />
<lifecycle-callback type="preUpdate" method="serializeMetadata" />
</lifecycle-callbacks>
</mapped-superclass>

</doctrine-mapping>