diff --git a/_legacy/AddElementToAreaMutation.php b/_legacy/AddElementToAreaMutation.php deleted file mode 100644 index 09b6132c..00000000 --- a/_legacy/AddElementToAreaMutation.php +++ /dev/null @@ -1,100 +0,0 @@ - 'addElementToArea', - 'description' => 'Adds an Element to an ElementalArea, optionally after another Element' - ]; - } - - public function type() - { - return $this->manager->getType(StaticSchema::inst()->typeNameForDataObject(BaseElement::class)); - } - - public function args() - { - return [ - 'className' => ['type' => Type::nonNull(Type::string())], - 'elementalAreaID' => ['type' => Type::nonNull(Type::id())], - 'afterElementID' => ['type' => Type::id()], - ]; - } - - public function resolve($object, array $args, $context, ResolveInfo $info) - { - $elementClass = $args['className']; - $elementalAreaID = $args['elementalAreaID']; - $afterElementID = isset($args['afterElementID']) ? $args['afterElementID'] : null; - - if (!is_subclass_of($elementClass, BaseElement::class)) { - throw new InvalidArgumentException("$elementClass is not a subclass of " . BaseElement::class); - } - - $elementalArea = ElementalArea::get()->byID($elementalAreaID); - - if (!$elementalArea) { - throw new InvalidArgumentException("Invalid ElementalAreaID: $elementalAreaID"); - } - - if (!$elementalArea->canEdit($context['currentUser'])) { - throw new InvalidArgumentException("The current user has insufficient permission to edit ElementalAreas"); - } - - /** @var BaseElement $newElement */ - $newElement = Injector::inst()->create($elementClass); - - if (!$newElement->canEdit($context['currentUser'])) { - throw new InvalidArgumentException( - 'The current user has insufficient permission to edit Elements' - ); - } - - // Assign the parent ID directly rather than via HasManyList to prevent multiple writes. - // See BaseElement::$has_one for the "Parent" naming. - $newElement->ParentID = $elementalArea->ID; - // Ensure that a sort order is assigned - see BaseElement::onBeforeWrite() - $newElement->onBeforeWrite(); - - if ($afterElementID !== null) { - /** @var ReorderElements $reorderer */ - $reorderer = Injector::inst()->create(ReorderElements::class, $newElement); - $reorderer->reorder($afterElementID); // also writes the element - } else { - $newElement->write(); - } - - return $newElement; - } -} diff --git a/_legacy/DeleteBlocksMutation.php b/_legacy/DeleteBlocksMutation.php deleted file mode 100644 index 80998e56..00000000 --- a/_legacy/DeleteBlocksMutation.php +++ /dev/null @@ -1,52 +0,0 @@ - 'deleteBlocks', - ]; - } - - public function type() - { - return Type::listOf(Type::id()); - } - - public function args() - { - return [ - 'ids' => Type::nonNull(Type::listOf(Type::id())), - ]; - } - - public function getResolver() - { - $delete = new Delete(BaseElement::class); - return [$delete, 'resolve']; - } -} diff --git a/_legacy/DuplicateElementMutation.php b/_legacy/DuplicateElementMutation.php deleted file mode 100644 index d57c6d04..00000000 --- a/_legacy/DuplicateElementMutation.php +++ /dev/null @@ -1,120 +0,0 @@ - 'duplicateBlock', - 'description' => 'Duplicate an Element in this ElementalArea' - ]; - } - - public function type() - { - return $this->manager->getType(StaticSchema::inst()->typeNameForDataObject(BaseElement::class)); - } - - public function args() - { - return [ - 'id' => ['type' => Type::nonNull(Type::id())], - ]; - } - - public function resolve($object, array $args, $context, ResolveInfo $info) - { - // load element to clone - $elementID = $args['id']; - $element = BaseElement::get_by_id($elementID); - if (!$element) { - throw new InvalidArgumentException("Invalid BaseElementID: $elementID"); - } - - // check can edit the elemental area - $areaID = $element->ParentID; - $area = ElementalArea::get_by_id($areaID); - if (!$area) { - throw new InvalidArgumentException("Invalid ParentID on BaseElement: $elementID"); - } - if (!$area->canEdit($context['currentUser'])) { - throw new InvalidArgumentException( - "The current user has insufficient permission to edit ElementalArea: $areaID" - ); - } - if (!$element->canCreate($context['currentUser'])) { - throw new InvalidArgumentException( - "The current user has insufficient permission to create or duplicate BaseElement: $elementID" - ); - } - - try { - // clone element - $clone = $element->duplicate(false); - $clone->Title = $this->newTitle($clone->Title); - $clone->Sort = 0; // must be zeroed for reorder to work - $area->Elements()->add($clone); - - // reorder - $reorderer = Injector::inst()->create(ReorderElements::class, $clone); - $reorderer->reorder($elementID); - - return $clone; - } catch (Exception $e) { - throw new Exception("Something went wrong when duplicating element: $elementID"); - } - } - - - public function newTitle($title) - { - $hasCopyPattern = '/^.*(\scopy($|\s[0-9]+$))/'; - $hasNumPattern = '/^.*(\s[0-9]+$)/'; - $parts = []; - - // does $title end with 'copy' (ignoring numbers for now)? - if (preg_match($hasCopyPattern, $title, $parts)) { - $copy = $parts[1]; - // does $title end with numbers? - if (preg_match($hasNumPattern, $copy, $parts)) { - $num = trim($parts[1]); - $len = strlen($num); - $inc = (int)$num + 1; - return substr($title, 0, -$len) . "$inc"; - } else { - return $title . ' 2'; - } - } else { - return $title . ' copy'; - } - } -} diff --git a/_legacy/ElementsResolver.php b/_legacy/ElementsResolver.php deleted file mode 100644 index af436d43..00000000 --- a/_legacy/ElementsResolver.php +++ /dev/null @@ -1,42 +0,0 @@ -canView($context['currentUser'])) { - throw new \Exception('Current user cannot view elements'); - } - - /** @var DataList $elements */ - $elements = $object->Elements(); - return $elements; - } -} diff --git a/_legacy/ReadOneAreaResolver.php b/_legacy/ReadOneAreaResolver.php deleted file mode 100644 index 1fa543ce..00000000 --- a/_legacy/ReadOneAreaResolver.php +++ /dev/null @@ -1,43 +0,0 @@ -formatField('ID'); - $id = $args['filter'][$idKey]['eq']; - $area = ElementalArea::get()->byID($id); - - if (!$area) { - throw new InvalidArgumentException('Could not find elemental area matching ID ' . $id); - } - - if (!$area->canView($context['currentUser'])) { - throw new Exception('Current user cannot view element areas'); - } - - return $area; - } -} diff --git a/_legacy/ReadOneBlockResolver.php b/_legacy/ReadOneBlockResolver.php deleted file mode 100644 index c5b3b1a2..00000000 --- a/_legacy/ReadOneBlockResolver.php +++ /dev/null @@ -1,36 +0,0 @@ -formatField('ID'); - $id = $args['filter'][$idKey]['eq']; - $readOne = Injector::inst()->createWithArgs(ReadOne::class, [BaseElement::class]); - unset($args['filter']); - $args[$idKey] = $id; - return $readOne->resolve($obj, $args, $context, $info); - } -} diff --git a/_legacy/SortBlockMutationCreator.php b/_legacy/SortBlockMutationCreator.php deleted file mode 100644 index c32497df..00000000 --- a/_legacy/SortBlockMutationCreator.php +++ /dev/null @@ -1,77 +0,0 @@ - 'sortBlock', - 'description' => 'Changes the sort position of an element' - ]; - } - - public function type() - { - return $this->manager->getType(StaticSchema::inst()->typeNameForDataObject(BaseElement::class)); - } - - public function args() - { - return [ - 'id' => ['type' => Type::nonNull(Type::id())], - 'afterBlockID' => ['type' => Type::nonNull(Type::id())], - ]; - } - - public function resolve($object, array $args, $context, ResolveInfo $info) - { - $element = BaseElement::get()->byID($args['id']); - - if (!$element) { - throw new InvalidArgumentException(sprintf( - '%s#%s not found', - BaseElement::class, - $args['id'] - )); - } - - if (!$element->canEdit($context['currentUser'])) { - throw new InvalidArgumentException( - 'Changing the sort order of blocks is not allowed for the current user' - ); - } - - $reorderingService = Injector::inst()->create(ReorderElements::class, $element); - return $reorderingService->reorder($args['afterBlockID']); - } -} diff --git a/_legacy/Types/ObjectType.php b/_legacy/Types/ObjectType.php deleted file mode 100644 index 0193b90e..00000000 --- a/_legacy/Types/ObjectType.php +++ /dev/null @@ -1,39 +0,0 @@ - 'ObjectType', - 'serialize' => function ($value) { - return (object) $value; - }, - 'parseValue' => function ($value) { - return (array) $value; - }, - 'parseLiteral' => function ($ast) { - return $ast->value; - }, - ]); - } -} diff --git a/src/Extensions/ElementalAreaUsedOnTableExtension.php b/src/Extensions/ElementalAreaUsedOnTableExtension.php index 59f5793b..93ed86c8 100644 --- a/src/Extensions/ElementalAreaUsedOnTableExtension.php +++ b/src/Extensions/ElementalAreaUsedOnTableExtension.php @@ -2,11 +2,8 @@ namespace DNADesign\Elemental\Extensions; -use SilverStripe\Dev\Deprecation; -use SilverStripe\Admin\Forms\UsedOnTable; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\ORM\DataExtension; -use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\ValidationException; use DNADesign\Elemental\Models\ElementalArea; @@ -25,23 +22,6 @@ public function updateUsageExcludedClasses(array &$excludedClasses) $excludedClasses[] = ElementalArea::class; } - /** - * Legacy function kept for semver, replaced with updateUsageExcludedClasses above - * - * @return void - * @var ArrayList $usage - * @var DataObject $record - * @see UsedOnTable::updateUsage - * @deprecated 4.5.0 Use updateUsageExcludedClasses() instead - */ - public function updateUsage(ArrayList &$usage, DataObject &$record) - { - Deprecation::withNoReplacement(function () { - Deprecation::notice('4.5.0', 'Use updateUsageExcludedClasses() instead'); - }); - // noop - } - /** * Exclude content blocks that aren't linked to a page * diff --git a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php b/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php deleted file mode 100644 index 3cc12dea..00000000 --- a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.php +++ /dev/null @@ -1,97 +0,0 @@ -markTestSkipped('Skipped GraphQL 3 test ' . __CLASS__); - } - } - - public function testAddingBlocksInOrder() - { - $className = TestElement::class; - $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; - - $one = $this->runMutation($className, $areaID)->ID; - $this->assertIdsInOrder([$one], 'The first element is added'); - - $two = $this->runMutation($className, $areaID, $one)->ID; - $this->assertIdsInOrder([$one, $two], 'The second element is added after the first'); - - $three = $this->runMutation($className, $areaID, $one)->ID; - $this->assertIdsInOrder([$one, $three, $two], 'The third element is added after the first'); - - $four = $this->runMutation($className, $areaID)->ID; - $this->assertIdsInOrder( - [$one, $three, $two, $four], - 'The fourth element is added last, when no after ID parameter is given' - ); - - $five = $this->runMutation($className, $areaID, 0)->ID; - $this->assertIdsInOrder([$five, $one, $three, $two, $four], 'The fifth element is added first, after ID 0'); - } - - public function testBadElementalArea() - { - $this->expectException(InvalidArgumentException::class); - $areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID; - $this->runMutation(TestElement::class, $areaID + 1); - } - - public function testOrderingByWrongElementalArea() - { - $this->expectException(InvalidArgumentException::class); - $firstArea = ElementalArea::get()->first(); - $elementInFirstArea = TestElement::create(); - $firstArea->Elements()->add($elementInFirstArea); - - ElementalArea::create()->write(); - $this->runMutation(TestElement::class, 2, $elementInFirstArea->ID); - } - - protected function assertIdsInOrder($ids, $message = null) - { - $actualIDs = TestElement::get()->sort('Sort')->map()->keys(); - // Ideally this should be assertSame, but sometimes the database - // returns IDs as strings instead of integers (e.g. "1" instead of 1). - $this->assertEquals($ids, $actualIDs, $message); - } - - protected function runMutation($className, $elementalAreaID, $afterElementId = null) - { - $mutation = new AddElementToAreaMutation(); - $context = ['currentUser' => Security::getCurrentUser()]; - $resolveInfo = new FakeResolveInfo([]); - - $args = [ - 'className' => $className, - 'elementalAreaID' => $elementalAreaID, - ]; - - if (!is_null($afterElementId)) { - $args['afterElementID'] = $afterElementId; - } - - return $mutation->resolve(null, $args, $context, $resolveInfo); - } -} diff --git a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.yml b/tests/GraphQL/Legacy/AddElementToAreaMutationTest.yml deleted file mode 100644 index 4f099556..00000000 --- a/tests/GraphQL/Legacy/AddElementToAreaMutationTest.yml +++ /dev/null @@ -1,2 +0,0 @@ -DNADesign\Elemental\Models\ElementalArea: - one: \ No newline at end of file diff --git a/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.php b/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.php deleted file mode 100644 index 15a62b31..00000000 --- a/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.php +++ /dev/null @@ -1,66 +0,0 @@ -markTestSkipped('Skipped GraphQL 3 test ' . __CLASS__); - } - } - - /** - * Reorders blocks by compounding each result into the next test (rather than isolated sorting tests) - */ - public function testSortBlock() - { - $this->runMutation(1, 3); - $this->assertIdsInOrder([2, 3, 1, 4]); - - $this->runMutation(4, 2); - $this->assertIdsInOrder([2, 4, 3, 1]); - - $this->runMutation(1, 0); - $this->assertIdsInOrder([1, 2, 4, 3]); - - $this->runMutation(3, 2); - $this->assertIdsInOrder([1, 2, 3, 4]); - } - - protected function assertIdsInOrder($ids) - { - $actualIDs = TestElement::get()->sort('Sort')->map()->keys(); - - $this->assertSame($ids, $actualIDs); - } - - protected function runMutation($id, $afterBlockId) - { - $member = Security::getCurrentUser(); - - $mutation = new SortBlockMutationCreator(); - $context = ['currentUser' => $member]; - $resolveInfo = new FakeResolveInfo([]); - - $mutation->resolve(null, [ - 'id' => $id, - 'afterBlockID' => $afterBlockId, - ], $context, $resolveInfo); - } -} diff --git a/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.yml b/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.yml deleted file mode 100644 index d54cb617..00000000 --- a/tests/GraphQL/Legacy/SortBlockMutationCreatorTest.yml +++ /dev/null @@ -1,13 +0,0 @@ -DNADesign\Elemental\Tests\Src\TestElement: - element1: - ID: 1 - Sort: 1 - element2: - ID: 2 - Sort: 2 - element3: - ID: 3 - Sort: 3 - element4: - ID: 4 - Sort: 4 diff --git a/tests/TopPage/TopPageTest.php b/tests/TopPage/TopPageTest.php index f625f777..1026883c 100644 --- a/tests/TopPage/TopPageTest.php +++ b/tests/TopPage/TopPageTest.php @@ -8,7 +8,6 @@ use DNADesign\Elemental\Models\ElementalArea; use DNADesign\Elemental\TopPage; use Page; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataObject; @@ -151,78 +150,6 @@ public function testNewBlock(bool $populateTopPage): void $this->assertEquals((int) $page->ID, (int) $content->TopPageID); } - /** - * This test is checking for page duplication in two cases - * Case 1: standard duplication - * Case 2: duplication with a fixed page setting - * The seconds case shows that it's possible to use the withFixedTopPage to set the top page to arbitrary value - * and completely bypass page determination logic - * This is needed in some edge cases were automatic determination is not possible due to the object not being - * assigned to the parent object at the time of duplication but rather later - * - * @param int $fixedPageID - * @dataProvider fixedPagesProvider - */ - public function testPageDuplication(int $fixedPageID): void - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - /** @var TopPage\DataExtension $extension */ - $extension = singleton(TopPage\DataExtension::class); - $extension->withFixedTopPage($fixedPageID, function () use ($fixedPageID) { - $this->populateTopPageForAllObjects(); - - /** @var TestBlockPage $page */ - $page = $this->objFromFixture(TestBlockPage::class, 'block-page1'); - - /** @var TestChildPage $childPage */ - $childPage = $this->objFromFixture(TestChildPage::class, 'child-page1'); - - $page->duplicate(); - $pages = TestBlockPage::get()->filter(['Title' => 'BlockPage1'])->sort('ID', 'DESC'); - - $this->assertCount(2, $pages); - - $pageClone = $pages->first(); - $childPages = TestChildPage::get()->filter(['Title' => 'ChildPage1'])->sort('ID', 'DESC'); - - $this->assertCount(2, $childPages); - - $childClone = $childPages->first(); - - $this->assertNotEquals((int) $childPage->ID, (int) $childClone->ID); - - $objects = [ - [TestList::class, 'List1', $pageClone], - [TestContent::class, 'Content1', $pageClone], - [TestList::class, 'List2', $childClone], - [TestContent::class, 'Content2', $childClone], - ]; - - foreach ($objects as $objectData) { - $class = array_shift($objectData); - $title = array_shift($objectData); - $page = array_shift($objectData); - - $items = DataObject::get($class)->filter(['Title' => $title])->sort('ID', 'DESC'); - - $this->assertCount(2, $items); - - /** @var DataObject|TopPage\DataExtension $objectClone */ - $objectClone = $items->first(); - - $expected = $fixedPageID ?: (int) $page->ID; - $this->assertEquals($expected, (int) $objectClone->TopPageID); - - /** @var ElementalArea|TopPage\DataExtension $area */ - $area = $objectClone->Parent(); - - $this->assertEquals($expected, (int) $area->TopPageID); - } - }); - } - public function objectsProvider(): array { return [