Skip to content
Snippets Groups Projects
Commit 81bafb2f authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] type names must be unique

parent ebf9db97
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,9 @@ use Doctrine\ORM\Mapping as ORM;
* Attribute
*
* @ORM\Table(uniqueConstraints={
* @ORM\UniqueConstraint(name="property_in_type_unique", columns={"name", "is_type", "parent_id"}),
* @ORM\UniqueConstraint(name="type_url_name_unique", columns={"url_name", "is_type", "parent_id"})
* @ORM\UniqueConstraint(name="property_in_type_unique", columns={"name", "parent_id", "is_property_of"}),
* @ORM\UniqueConstraint(name="type_unique", columns={"name", "is_type", "typo3_group", "is_property_of"}),
* @ORM\UniqueConstraint(name="url_name_unique", columns={"url_name", "is_type", "typo3_group", "is_property_of"})
* })
* @ORM\Entity(repositoryClass="SGalinski\TypoScriptBackendBundle\Entity\AttributeRepository")
*/
......@@ -60,6 +61,13 @@ class Attribute {
*/
private $description;
/**
* @var int
*
* @ORM\Column(name="is_property_of", type="smallint", options={"default" = 0})
*/
private $isPropertyOf = 0;
/**
* @var string The TYPO3 version in which the attribute was introduced
* Example: "4.5" "6.1" "6.2"), NULL is default and NULL is interpreted as most early version.
......@@ -250,6 +258,21 @@ class Attribute {
return $this;
}
/**
* @param int $isPropertyOf
* @return void
*/
public function setIsPropertyOf($isPropertyOf) {
$this->isPropertyOf = (int) $isPropertyOf;
}
/**
* @return int
*/
public function getIsPropertyOf() {
return $this->isPropertyOf;
}
/**
* Set typo3Group
*
......@@ -280,6 +303,10 @@ class Attribute {
public function setParent($parent) {
$this->parent = $parent;
// I know... would be better to split the table into type and attribute
// reason - unique constraints are not really working well with NULL values (parent_id instead of this)
$this->isPropertyOf = (int) $parent->getId();
return $this;
}
......@@ -413,4 +440,4 @@ class Attribute {
$this->category = $category;
return $this;
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
namespace SGalinski\TypoScriptBackendBundle\Service;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\Query\ResultSetMapping;
use SGalinski\TypoScriptBackendBundle\Entity\Attribute;
/**
......@@ -38,23 +39,30 @@ class TypoScriptReferenceImportService {
/** @var \SimpleXMLElement $tsrefXml */
$tsrefXml = simplexml_load_file($fileAddress);
$typeAttributes = $this->tsrefXmlToPhp($tsrefXml, $typo3MinVersion, $typo3MaxVersion, $typo3Group);
$em = $this->doctrine->getManager();
// Persist all Attributes
/** @var Attribute $typeAttribute */
foreach ($typeAttributes as $typeAttribute) {
if (!$typeAttribute->getChildren()) {
$this->doctrine->getManager()->persist($typeAttribute);
$em->persist($typeAttribute);
continue;
}
/** @var Attribute $attribute */
foreach ($typeAttribute->getChildren() as $attribute) {
if (!$attribute->getIsType()) {
$this->doctrine->getManager()->persist($attribute);
$em->persist($attribute);
}
}
$this->doctrine->getManager()->persist($typeAttribute);
$em->persist($typeAttribute);
}
$this->doctrine->getManager()->flush();
$em->flush();
// fix property relations
$em->getConnection()->exec(
'UPDATE attribute SET is_property_of = parent_id WHERE is_property_of != 0'
);
}
/**
......@@ -131,10 +139,11 @@ class TypoScriptReferenceImportService {
* @param Attribute $parentAttribute
* @param array $typeAttributes
* @param int $typo3Group - Attribute::NORMAL_GROUP | Attribute::PAGE_GROUP | Attribute::USER_GROUP
* @param int $fakeParentOfIndex
*/
protected function parseTypeChildTags(
$typeTagChildren, $typo3MinVersion = NULL, $typo3MaxVersion = NULL, Attribute $parentAttribute, array $typeAttributes,
$typo3Group = Attribute::NORMAL_GROUP
$typo3Group = Attribute::NORMAL_GROUP, &$fakeParentOfIndex
) {
/**
* @var string $key
......@@ -188,6 +197,7 @@ class TypoScriptReferenceImportService {
// Connecting parent with child
$propertyAttribute->setParent($parentAttribute);
$propertyAttribute->setIsPropertyOf($fakeParentOfIndex++);
$parentAttribute->addChild($propertyAttribute);
// Setting minVersion
......@@ -229,6 +239,8 @@ class TypoScriptReferenceImportService {
\SimpleXMLElement $tsrefXml, $typo3MinVersion = NULL, $typo3MaxVersion = NULL, array $typeAttributes,
$typo3Group = Attribute::NORMAL_GROUP
) {
$fakeParentOfIndex = 1000;
/** @var \SimpleXMLElement $typeTag */
foreach ($tsrefXml as $key => $typeTag) {
// Getting Attribute by name
......@@ -262,7 +274,7 @@ class TypoScriptReferenceImportService {
if ($typeTag->children()->count() > 0) {
$this->parseTypeChildTags(
$typeTag->children(), $typo3MinVersion, $typo3MaxVersion, $typeAttribute, $typeAttributes,
$typo3Group
$typo3Group, $fakeParentOfIndex
);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment