Skip to content

Commit 4b5aa0a

Browse files
author
Daria Prusova
committed
[orm] fix move & change slug
1 parent d3ee1b0 commit 4b5aa0a

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

library/orm/collection/BaseHierarchicCollection.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ public function move(
215215
IHierarchicObject $previousSibling = null
216216
)
217217
{
218+
if (!$this
219+
->getObjectPersister()
220+
->getIsPersisted()
221+
) {
222+
throw new RuntimeException($this->translate(
223+
'Cannot move object. Not all objects are persisted. Commit transaction first.'
224+
));
225+
}
218226

219227
if (!$this->contains($object)) {
220228
throw new RuntimeException($this->translate(
@@ -294,6 +302,15 @@ public function move(
294302
*/
295303
public function changeSlug(IHierarchicObject $object, $slug)
296304
{
305+
if (!$this
306+
->getObjectPersister()
307+
->getIsPersisted()
308+
) {
309+
throw new RuntimeException($this->translate(
310+
'Cannot change slug for object. Not all objects are persisted. Commit transaction first.'
311+
));
312+
}
313+
297314
$branch = $object->getParent();
298315

299316
$baseUri = $branch ? $branch->getURI() . '/' : '//';

tests/utest/orm/func/collection/commonhierarchy/CommonHierarchyChangeSlugTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ public function testChangeSlugPossibility()
117117
'Ожидается, что невозможно изменить uri объекта, если итоговый uri не уникальный'
118118
);
119119

120+
$post2->setValue('title', '1');
121+
$e = null;
122+
try {
123+
$this->hierarchy->changeSlug($post2, 'new_slug');
124+
} catch (\Exception $e) {
125+
}
126+
$this->assertInstanceOf(
127+
'umi\orm\exception\RuntimeException',
128+
$e,
129+
'Ожидается, что невозможно изменить uri объекта, если есть модифицированные объекты'
130+
);
131+
}
132+
133+
public function testOutOfDateChangeSlug()
134+
{
135+
$post2 = $this->postsCollection->get($this->guid2);
120136
$post2->setVersion(10);
121137
$e = null;
122138
try {

tests/utest/orm/func/collection/commonhierarchy/CommonHierarchyMoveTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ public function testImpossibleMove()
193193
$e,
194194
'Ожидается, что невозможно переместить объект, если его новый итоговый урл совпадает с уже существующим'
195195
);
196+
197+
$this->blog4->setValue('title', 'new_title');
198+
$e = null;
199+
try {
200+
$this->hierarchy->move($this->blog4, $this->blog1);
201+
} catch (\Exception $e) {
202+
}
203+
$this->assertInstanceOf(
204+
'umi\orm\exception\RuntimeException',
205+
$e,
206+
'Ожидается, что невозможно переместить объект и изменить объекты за одну транзакцию'
207+
);
196208
}
197209

198210
public function testMoveFirstWithoutSwitchingTheBranch()

0 commit comments

Comments
 (0)