Skip to content

Commit 3fcb5ce

Browse files
committed
Merge branch 'master' into v2
1 parent 247fed7 commit 3fcb5ce

File tree

4 files changed

+63
-28
lines changed

4 files changed

+63
-28
lines changed

src/Services/Attachments/AttachmentURLGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ public function getInternalViewURL(Attachment $attachment): ?string
112112
/**
113113
* Returns a URL to a thumbnail of the attachment file.
114114
* For external files the original URL is returned.
115-
* @return string|null The URL or null if the attachment file is not existing
115+
* @return string|null The URL or null if the attachment file is not existing or is invalid
116116
*/
117117
public function getThumbnailURL(Attachment $attachment, string $filter_name = 'thumbnail_sm'): ?string
118118
{
119119
if (!$attachment->isPicture()) {
120-
throw new InvalidArgumentException('Thumbnail creation only works for picture attachments!');
120+
return null;
121121
}
122122

123123
if (!$attachment->hasInternal()){

src/Services/ImportExportSystem/EntityImporter.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function __construct(protected SerializerInterface $serializer, protected
5757
/**
5858
* Creates many entries at once, based on a (text) list of name.
5959
* The created entities are not persisted to database yet, so you have to do it yourself.
60+
* It returns all entities in the hierachy chain (even if they are already persisted).
6061
*
6162
* @template T of AbstractNamedDBElement
6263
* @param string $lines The list of names seperated by \n
@@ -132,32 +133,38 @@ public function massCreation(string $lines, string $class_name, ?AbstractStructu
132133
//We can only use the getNewEntityFromPath function, if the repository is a StructuralDBElementRepository
133134
if ($repo instanceof StructuralDBElementRepository) {
134135
$entities = $repo->getNewEntityFromPath($new_path);
135-
$entity = end($entities);
136-
if ($entity === false) {
136+
if ($entities === []) {
137137
throw new InvalidArgumentException('getNewEntityFromPath returned an empty array!');
138138
}
139139
} else { //Otherwise just create a new entity
140140
$entity = new $class_name;
141141
$entity->setName($name);
142+
$entities = [$entity];
142143
}
143144

144145

145146
//Validate entity
146-
$tmp = $this->validator->validate($entity);
147-
//If no error occured, write entry to DB:
148-
if (0 === count($tmp)) {
149-
$valid_entities[] = $entity;
150-
} else { //Otherwise log error
151-
$errors[] = [
152-
'entity' => $entity,
153-
'violations' => $tmp,
154-
];
147+
foreach ($entities as $entity) {
148+
$tmp = $this->validator->validate($entity);
149+
//If no error occured, write entry to DB:
150+
if (0 === count($tmp)) {
151+
$valid_entities[] = $entity;
152+
} else { //Otherwise log error
153+
$errors[] = [
154+
'entity' => $entity,
155+
'violations' => $tmp,
156+
];
157+
}
155158
}
156159

157-
$last_element = $entity;
160+
$last_element = end($entities);
161+
if ($last_element === false) {
162+
$last_element = null;
163+
}
158164
}
159165

160-
return $valid_entities;
166+
//Only return objects once
167+
return array_values(array_unique($valid_entities));
161168
}
162169

163170
/**

tests/Services/ImportExportSystem/EntityImporterTest.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function testMassCreationResults(): void
7575
$em = self::getContainer()->get(EntityManagerInterface::class);
7676
$parent = $em->find(AttachmentType::class, 1);
7777
$results = $this->service->massCreation($lines, AttachmentType::class, $parent, $errors);
78-
$this->assertCount(3, $results);
79-
$this->assertSame($parent, $results[0]->getParent());
78+
$this->assertCount(4, $results);
79+
$this->assertSame("Test 1", $results[1]->getName());
8080

8181
//Test for addition of existing elements
8282
$errors = [];
@@ -113,6 +113,31 @@ public function testNonStructuralClass(): void
113113

114114
}
115115

116+
public function testMassCreationArrow(): void
117+
{
118+
$input = <<<EOT
119+
Test1 -> Test1.1
120+
Test1 -> Test1.2
121+
Test2 -> Test2.1
122+
Test1
123+
Test1.3
124+
EOT;
125+
126+
$errors = [];
127+
$results = $this->service->massCreation($input, AttachmentType::class, null, $errors);
128+
129+
//We have 6 elements, and 0 errors
130+
$this->assertCount(0, $errors);
131+
$this->assertCount(6, $results);
132+
133+
$this->assertEquals('Test1', $results[0]->getName());
134+
$this->assertEquals('Test1.1', $results[1]->getName());
135+
$this->assertEquals('Test1.2', $results[2]->getName());
136+
$this->assertEquals('Test2', $results[3]->getName());
137+
$this->assertEquals('Test2.1', $results[4]->getName());
138+
$this->assertEquals('Test1.3', $results[5]->getName());
139+
}
140+
116141
public function testMassCreationNested(): void
117142
{
118143
$input = <<<EOT
@@ -132,15 +157,15 @@ public function testMassCreationNested(): void
132157

133158
//We have 7 elements, and 0 errors
134159
$this->assertCount(0, $errors);
135-
$this->assertCount(7, $results);
136-
137-
$element1 = $results[0];
138-
$element11 = $results[1];
139-
$element111 = $results[2];
140-
$element112 = $results[3];
141-
$element12 = $results[4];
142-
$element121 = $results[5];
143-
$element2 = $results[6];
160+
$this->assertCount(8, $results);
161+
162+
$element1 = $results[1];
163+
$element11 = $results[2];
164+
$element111 = $results[3];
165+
$element112 = $results[4];
166+
$element12 = $results[5];
167+
$element121 = $results[6];
168+
$element2 = $results[7];
144169

145170
$this->assertSame('Test 1', $element1->getName());
146171
$this->assertSame('Test 1.1', $element11->getName());

translations/messages.en.xlf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7157,12 +7157,15 @@ Exampletown</target>
71577157
</notes>
71587158
<segment state="translated">
71597159
<source>mass_creation.lines.placeholder</source>
7160-
<target>Element 1
7160+
<target><![CDATA[Element 1
71617161
Element 1.1
71627162
Element 1.1.1
71637163
Element 1.2
71647164
Element 2
7165-
Element 3</target>
7165+
Element 3
7166+
7167+
Element 1 -> Element 1.1
7168+
Element 1 -> Element 1.2]]></target>
71667169
</segment>
71677170
</unit>
71687171
<unit id="TWSqPFi" name="entity.mass_creation.btn">

0 commit comments

Comments
 (0)