From 0e5428b78beaaa228709b7771a908e094907f922 Mon Sep 17 00:00:00 2001 From: Sabina Talipova <87288324+sabina-talipova@users.noreply.github.com> Date: Thu, 8 Dec 2022 10:44:36 +1300 Subject: [PATCH] API Remove deprecated code (#2800) --- .upgrade.yml | 2 - _legacy/GraphQL/ReadOneResolver.php | 32 ------- code/Controllers/CMSMain.php | 74 +--------------- code/Model/SiteTree.php | 45 +--------- code/Model/SiteTreeFileExtension.php | 35 -------- .../SiteTreeFileFormFactoryExtension.php | 50 ----------- code/Model/SiteTreeFolderExtension.php | 88 ------------------- code/Model/VirtualPage.php | 25 ------ .../SiteTreeFileExtension_description.ss | 27 ------ tests/php/Controllers/CMSMainTest.php | 37 -------- tests/php/Model/SiteTreeTest.php | 17 +--- 11 files changed, 4 insertions(+), 428 deletions(-) delete mode 100644 _legacy/GraphQL/ReadOneResolver.php delete mode 100644 code/Model/SiteTreeFileExtension.php delete mode 100644 code/Model/SiteTreeFileFormFactoryExtension.php delete mode 100644 code/Model/SiteTreeFolderExtension.php delete mode 100644 templates/SilverStripe/CMS/Model/Includes/SiteTreeFileExtension_description.ss diff --git a/.upgrade.yml b/.upgrade.yml index d59203ba..f068e1d0 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -39,8 +39,6 @@ mappings: RedirectorPage_Controller: SilverStripe\CMS\Model\RedirectorPageController SiteTree: SilverStripe\CMS\Model\SiteTree SiteTreeExtension: SilverStripe\CMS\Model\SiteTreeExtension - SiteTreeFileExtension: SilverStripe\CMS\Model\SiteTreeFileExtension - SiteTreeFolderExtension: SilverStripe\CMS\Model\SiteTreeFolderExtension SiteTreeLinkTracking: SilverStripe\CMS\Model\SiteTreeLinkTracking SiteTreeLinkTracking_Parser: SilverStripe\CMS\Model\SiteTreeLinkTracking_Parser VirtualPage: SilverStripe\CMS\Model\VirtualPage diff --git a/_legacy/GraphQL/ReadOneResolver.php b/_legacy/GraphQL/ReadOneResolver.php deleted file mode 100644 index 1acb276a..00000000 --- a/_legacy/GraphQL/ReadOneResolver.php +++ /dev/null @@ -1,32 +0,0 @@ -formatField('ID'); - $id = $args['filter'][$idKey]['eq']; - $readOne = Injector::inst()->createWithArgs(ReadOne::class, ['Page']); - unset($args['filter']); - $args[$idKey] = $id; - return $readOne->resolve($obj, $args, $context, $info); - } -} diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 58b72c8f..155d7e9f 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -2,7 +2,6 @@ namespace SilverStripe\CMS\Controllers; -use SilverStripe\Dev\Deprecation; use InvalidArgumentException; use Psr\SimpleCache\CacheInterface; use SilverStripe\Admin\AdminRootController; @@ -198,7 +197,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr Requirements::css('silverstripe/cms: client/dist/styles/bundle.css'); Requirements::customCSS($this->generatePageIconsCss(), self::PAGE_ICONS_ID); - Requirements::add_i18n_javascript('silverstripe/cms: client/lang', false, true); + Requirements::add_i18n_javascript('silverstripe/cms: client/lang', false); CMSBatchActionHandler::register('restore', CMSBatchAction_Restore::class); CMSBatchActionHandler::register('archive', CMSBatchAction_Archive::class); @@ -2148,77 +2147,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this->batchactions()->batchActionList(); } - /** - * @deprecated 4.12.0 Use custom logic instead - */ - public function publishall(HTTPRequest $request): HTTPResponse - { - Deprecation::notice('4.12.0', 'Use custom logic instead'); - if (!Permission::check('ADMIN')) { - return Security::permissionFailure($this); - } - - Environment::increaseTimeLimitTo(); - Environment::increaseMemoryLimitTo(); - - $response = ""; - - if (isset($this->requestParams['confirm'])) { - // Protect against CSRF on destructive action - if (!SecurityToken::inst()->checkRequest($request)) { - $this->httpError(400); - } - - $start = 0; - $pages = SiteTree::get()->limit("$start,30"); - $count = 0; - while ($pages) { - /** @var SiteTree $page */ - foreach ($pages as $page) { - if ($page && !$page->canPublish()) { - return Security::permissionFailure($this); - } - - $page->publishRecursive(); - $page->destroy(); - unset($page); - $count++; - $response .= "
  • $count
  • "; - } - if ($pages->count() > 29) { - $start += 30; - $pages = SiteTree::get()->limit("$start,30"); - } else { - break; - } - } - $response .= _t(__CLASS__ . '.PUBPAGES', "Done: Published {count} pages", ['count' => $count]); - } else { - $token = SecurityToken::inst(); - $fields = new FieldList(); - $token->updateFieldSet($fields); - $tokenField = $fields->first(); - $tokenHtml = ($tokenField) ? $tokenField->FieldHolder() : ''; - $publishAllDescription = _t( - __CLASS__ . '.PUBALLFUN2', - 'Pressing this button will do the equivalent of going to every page and pressing "publish". ' - . 'It\'s intended to be used after there have been massive edits of the content, such as when ' - . 'the site was first built. ' - . 'For large websites, this task might not be able to run through to completion. ' - . 'In this case, we recommend talking to your developers to create a custom task' - ); - $response .= '

    ' . _t(__CLASS__ . '.PUBALLFUN', '"Publish All" functionality') . '

    -

    ' . $publishAllDescription . '

    -
    - ' - . $tokenHtml . - '
    '; - } - - return HTTPResponse::create()->setBody($response); - } - /** * Restore a completely deleted page from the SiteTree_versions table. */ diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index 2e701f87..1ab94186 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -25,7 +25,6 @@ use SilverStripe\Core\Manifest\ModuleResource; use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Core\Manifest\VersionProvider; use SilverStripe\Core\Resettable; -use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CompositeField; use SilverStripe\Forms\DropdownField; @@ -651,11 +650,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi */ public function PreviewLink($action = null) { - if ($this->hasMethod('alternatePreviewLink')) { - Deprecation::notice('5.0', 'Use updatePreviewLink or override PreviewLink method'); - return $this->alternatePreviewLink($action); - } - $link = $this->AbsoluteLink($action); $this->extend('updatePreviewLink', $link, $action); return $link; @@ -2754,35 +2748,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi return $allowedChildren; } - /** - * @deprecated 4.12.0 Use creatableChildPages() instead - * - * Gets a list of the page types that can be created under this specific page - * - * @return array - */ - public function creatableChildren() - { - Deprecation::notice('4.12.0', 'Use creatableChildPages() instead'); - // Build the list of candidate children - $cache = SiteTree::singleton()->getCreatableChildrenCache(); - $cacheKey = $this->generateChildrenCacheKey(Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0); - $children = $cache->get($cacheKey, []); - if (!$children || !isset($children[$this->ID])) { - $children[$this->ID] = []; - $candidates = static::page_type_classes(); - foreach ($candidates as $childClass) { - $child = singleton($childClass); - if ($child->canCreate(null, ['Parent' => $this])) { - $children[$this->ID][$childClass] = $child->i18n_singular_name(); - } - } - $cache->set($cacheKey, $children); - } - - return $children[$this->ID]; - } - /** * * Gets a list of the page types that can be created under this specific page, including font icons @@ -3031,14 +2996,6 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi // If we have a class of "{$ClassName}Controller" then we found our controller if (class_exists($candidate = sprintf('%sController', $class))) { return $candidate; - } elseif (class_exists($candidate = sprintf('%s_Controller', $class))) { - // Support the legacy underscored filename, but raise a deprecation notice - Deprecation::notice( - '5.0', - 'Underscored controller class names are deprecated. Use "MyController" instead of "My_Controller".', - Deprecation::SCOPE_GLOBAL - ); - return $candidate; } elseif (is_array($namespaceMap)) { foreach ($namespaceMap as $pageNamespace => $controllerNamespace) { if (strpos($class, $pageNamespace) !== 0) { @@ -3302,7 +3259,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi } /** - * Cache key for creatableChildren() method + * Cache key for creatableChildPages() method * * @param int $memberID * @return string diff --git a/code/Model/SiteTreeFileExtension.php b/code/Model/SiteTreeFileExtension.php deleted file mode 100644 index 5cbd7d53..00000000 --- a/code/Model/SiteTreeFileExtension.php +++ /dev/null @@ -1,35 +0,0 @@ - 'HTMLFragment' - ]; - - /** - * Generate an HTML list which provides links to where a file is used. - * - * @return string - */ - public function __construct() - { - Deprecation::notice('4.2.0', 'Use FileLinkTracking instead', Deprecation::SCOPE_CLASS); - } - - public function BackLinkHTMLList() - { - $viewer = SSViewer::create(['type' => 'Includes', self::class . '_description']); - return $viewer->process($this->owner); - } -} diff --git a/code/Model/SiteTreeFileFormFactoryExtension.php b/code/Model/SiteTreeFileFormFactoryExtension.php deleted file mode 100644 index 59773030..00000000 --- a/code/Model/SiteTreeFileFormFactoryExtension.php +++ /dev/null @@ -1,50 +0,0 @@ -fieldByName('Editor'); - if (!$tabset) { - return; - } - - $usedOnField = UsedOnTable::create('UsedOnTableReplacement'); - $usedOnField->setRecord($context['Record']); - - // Add field to new tab - /** @var Tab $tab */ - $tab = Tab::create('Usage', _t(__CLASS__ . '.USAGE', 'Usage'), $usedOnField); - $tabset->push($tab); - } -} diff --git a/code/Model/SiteTreeFolderExtension.php b/code/Model/SiteTreeFolderExtension.php deleted file mode 100644 index 08f53f9e..00000000 --- a/code/Model/SiteTreeFolderExtension.php +++ /dev/null @@ -1,88 +0,0 @@ -column('LinkedID'); - - // Get all classes that aren't folder - $fileClasses = array_diff_key( - ClassInfo::subclassesFor(File::class) ?? [], - ClassInfo::subclassesFor(Folder::class) - ); - - // Search on a class-by-class basis - $classes = ClassInfo::subclassesFor(SiteTree::class); - - $schema = DataObject::getSchema(); - foreach ($classes as $className) { - // Build query based on all direct has_ones on this class - $hasOnes = Config::inst()->get($className, 'has_one', Config::UNINHERITED); - if (empty($hasOnes)) { - continue; - } - $where = []; - $columns = []; - foreach ($hasOnes as $relName => $joinClass) { - if (in_array($joinClass, $fileClasses ?? [])) { - $column = $relName . 'ID'; - $columns[] = $column; - $quotedColumn = $schema->sqlColumnForField($className, $column); - $where[] = "{$quotedColumn} > 0"; - } - } - - // Get all records with any file ID in the searched columns - $recordsArray = DataList::create($className)->whereAny($where)->toArray(); - $records = ArrayList::create($recordsArray); - foreach ($columns as $column) { - $usedFiles = array_unique(array_merge($usedFiles, $records->column($column))); - } - } - - // Create filter based on class and id - $classFilter = sprintf( - "(\"File\".\"ClassName\" IN (%s))", - implode(", ", Convert::raw2sql($fileClasses, true)) - ); - if ($usedFiles) { - return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND $classFilter"; - } else { - return $classFilter; - } - } -} diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index 9d0573c2..991ddb29 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -4,7 +4,6 @@ namespace SilverStripe\CMS\Model; use Page; use SilverStripe\Core\Convert; -use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\ReadonlyTransformation; @@ -360,30 +359,6 @@ class VirtualPage extends Page return $result; } - /** - * @deprecated 4.2.0 Will be removed without equivalent functionality to replace it - */ - public function updateImageTracking() - { - Deprecation::notice('4.2.0', 'Will be removed without equivalent functionality to replace it'); - - // Doesn't work on unsaved records - if (!$this->isInDB()) { - return; - } - - // Remove CopyContentFrom() from the cache - unset($this->components['CopyContentFrom']); - - // Update ImageTracking - $copyContentFrom = $this->CopyContentFrom(); - if (!$copyContentFrom || !$copyContentFrom->isInDB()) { - return; - } - - $this->FileTracking()->setByIDList($copyContentFrom->FileTracking()->column('ID')); - } - public function CMSTreeClasses() { $parentClass = sprintf( diff --git a/templates/SilverStripe/CMS/Model/Includes/SiteTreeFileExtension_description.ss b/templates/SilverStripe/CMS/Model/Includes/SiteTreeFileExtension_description.ss deleted file mode 100644 index 44b5ac86..00000000 --- a/templates/SilverStripe/CMS/Model/Includes/SiteTreeFileExtension_description.ss +++ /dev/null @@ -1,27 +0,0 @@ -<% if $BackLinkTracking %> - - - - - - - - - - <% loop $BackLinkTracking %> - - - - - - <% end_loop %> - -
    <%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_INDEX '#' %><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_USED_ON 'Used on' %><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_TYPE 'Type' %>
    $Pos$MenuTitle - $i18n_singular_name - <% if $isPublished %> - Published - <% else %> - Draft - <% end_if %> -
    -<% end_if %> diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index c2ec4f3e..0722db4e 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -24,7 +24,6 @@ use SilverStripe\Security\Member; use SilverStripe\Security\Security; use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Versioned\Versioned; -use SilverStripe\Dev\Deprecation; class CMSMainTest extends FunctionalTest { @@ -118,42 +117,6 @@ class CMSMainTest extends FunctionalTest ); } - /** - * @todo Test the results of a publication better - */ - public function testPublish() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $page1 = $this->objFromFixture(SiteTree::class, 'page1'); - $page2 = $this->objFromFixture(SiteTree::class, 'page2'); - $this->logInAs('admin'); - - $response = $this->get('admin/pages/publishall?confirm=1'); - $this->assertStringContainsString( - 'Done: Published 30 pages', - $response->getBody() - ); - - // Some modules (e.g., cmsworkflow) will remove this action - $actions = CMSBatchActionHandler::config()->batch_actions; - if (isset($actions['publish'])) { - $response = $this->get( - 'admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID]) - ); - $responseData = json_decode($response->getBody() ?? '', true); - $this->assertArrayHasKey($page1->ID, $responseData['modified']); - $this->assertArrayHasKey($page2->ID, $responseData['modified']); - } - - // Get the latest version of the redirector page - $pageID = $this->idFromFixture(RedirectorPage::class, 'page5'); - $latestID = DB::prepared_query('SELECT MAX("Version") FROM "RedirectorPage_Versions" WHERE "RecordID" = ?', [$pageID])->value(); - $dsCount = DB::prepared_query('SELECT COUNT("Version") FROM "RedirectorPage_Versions" WHERE "RecordID" = ? AND "Version"= ?', [$pageID, $latestID])->value(); - $this->assertEquals(1, $dsCount, "Published page has no duplicate version records: it has " . $dsCount . " for version " . $latestID); - } - /** * Test that getCMSFields works on each page type. * Mostly, this is just checking that the method doesn't return an error diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 90ec6934..7f429b06 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -41,7 +41,6 @@ use Page; use PageController; use const RESOURCES_DIR; -use SilverStripe\Dev\Deprecation; class SiteTreeTest extends SapphireTest { @@ -888,7 +887,7 @@ class SiteTreeTest extends SapphireTest "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", [$about->ID] - )->first(); + )->record(); $this->assertEquals($member->ID, $savedVersion['AuthorID']); $this->assertEquals(0, $savedVersion['PublisherID']); @@ -898,7 +897,7 @@ class SiteTreeTest extends SapphireTest "SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\" WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC", [$about->ID] - )->first(); + )->record(); // Check the version created $this->assertEquals($member->ID, $publishedVersion['AuthorID']); @@ -1731,18 +1730,6 @@ class SiteTreeTest extends SapphireTest $this->assertSame(SiteTreeTest_NamespaceMapTestController::class, $namespacedSiteTree->getControllerName()); } - /** - * Test that underscored class names (legacy) are still supported (deprecation notice is issued though). - */ - public function testGetControllerNameWithUnderscoresIsSupported() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $class = new SiteTreeTest_LegacyControllerName(); - $this->assertEquals(SiteTreeTest_LegacyControllerName_Controller::class, $class->getControllerName()); - } - public function testTreeTitleCache() { $siteTree = new SiteTree();