mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1973 from open-sausages/pulls/4.0/update-classinfo-usages
Update usages of ClassInfo
This commit is contained in:
commit
fb9ad4453e
@ -159,7 +159,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
{
|
{
|
||||||
// set reading lang
|
// set reading lang
|
||||||
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
|
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
|
||||||
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages('SilverStripe\\CMS\\Model\\SiteTree')));
|
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::init();
|
parent::init();
|
||||||
@ -1734,7 +1734,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var SiteTree $record */
|
/** @var SiteTree $record */
|
||||||
$record = Versioned::get_one_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', array(
|
$record = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, array(
|
||||||
'"SiteTree_Live"."ID"' => $id
|
'"SiteTree_Live"."ID"' => $id
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class CMSPageAddController extends CMSPageEditController
|
|||||||
$parentField = new TreeDropdownField(
|
$parentField = new TreeDropdownField(
|
||||||
"ParentID",
|
"ParentID",
|
||||||
"",
|
"",
|
||||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
SiteTree::class,
|
||||||
'ID',
|
'ID',
|
||||||
'TreeTitle'
|
'TreeTitle'
|
||||||
),
|
),
|
||||||
|
@ -74,7 +74,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
|
|||||||
public static function get_all_filters()
|
public static function get_all_filters()
|
||||||
{
|
{
|
||||||
// get all filter instances
|
// get all filter instances
|
||||||
$filters = ClassInfo::subclassesFor('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter');
|
$filters = ClassInfo::subclassesFor(CMSSiteTreeFilter::class);
|
||||||
|
|
||||||
// remove abstract CMSSiteTreeFilter class
|
// remove abstract CMSSiteTreeFilter class
|
||||||
array_shift($filters);
|
array_shift($filters);
|
||||||
@ -162,7 +162,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!empty($parents)) {
|
while (!empty($parents)) {
|
||||||
$q = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree', '"RecordID" in ('.implode(',', array_keys($parents)).')');
|
$q = Versioned::get_including_deleted(SiteTree::class, '"RecordID" in ('.implode(',', array_keys($parents)).')');
|
||||||
$list = $q->map('ID', 'ParentID');
|
$list = $q->map('ID', 'ParentID');
|
||||||
$parents = array();
|
$parents = array();
|
||||||
foreach ($list as $id => $parentID) {
|
foreach ($list as $id => $parentID) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Controllers;
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,7 +18,7 @@ class CMSSiteTreeFilter_ChangedPages extends CMSSiteTreeFilter
|
|||||||
|
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Stage');
|
$pages = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT);
|
||||||
$pages = $this->applyDefaultFilters($pages)
|
$pages = $this->applyDefaultFilters($pages)
|
||||||
->leftJoin('SiteTree_Live', '"SiteTree_Live"."ID" = "SiteTree"."ID"')
|
->leftJoin('SiteTree_Live', '"SiteTree_Live"."ID" = "SiteTree"."ID"')
|
||||||
->where('"SiteTree"."Version" <> "SiteTree_Live"."Version"');
|
->where('"SiteTree"."Version" <> "SiteTree_Live"."Version"');
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Controllers;
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +30,7 @@ class CMSSiteTreeFilter_DeletedPages extends CMSSiteTreeFilter
|
|||||||
|
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class CMSSiteTreeFilter_PublishedPages extends CMSSiteTreeFilter
|
|||||||
*/
|
*/
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||||
return $page->isPublished();
|
return $page->isPublished();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SilverStripe\CMS\Controllers;
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\ORM\SS_List;
|
use SilverStripe\ORM\SS_List;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ class CMSSiteTreeFilter_Search extends CMSSiteTreeFilter
|
|||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
// Filter default records
|
// Filter default records
|
||||||
$pages = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Stage');
|
$pages = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT);
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
return $pages;
|
return $pages;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter
|
|||||||
*/
|
*/
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
|
|
||||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||||
|
@ -25,7 +25,7 @@ class CMSSiteTreeFilter_StatusDraftPages extends CMSSiteTreeFilter
|
|||||||
*/
|
*/
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Stage');
|
$pages = Versioned::get_by_stage(SiteTree::class, 'Stage');
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||||
// If page exists on stage but not on live
|
// If page exists on stage but not on live
|
||||||
|
@ -24,7 +24,7 @@ class CMSSiteTreeFilter_StatusRemovedFromDraftPages extends CMSSiteTreeFilter
|
|||||||
*/
|
*/
|
||||||
public function getFilteredPages()
|
public function getFilteredPages()
|
||||||
{
|
{
|
||||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||||
$pages = $this->applyDefaultFilters($pages);
|
$pages = $this->applyDefaultFilters($pages);
|
||||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||||
// If page is removed from stage but not live
|
// If page is removed from stage but not live
|
||||||
|
@ -108,7 +108,7 @@ class ContentController extends Controller
|
|||||||
$parent = SiteTree::get_by_link($parentRef);
|
$parent = SiteTree::get_by_link($parentRef);
|
||||||
|
|
||||||
if (!$parent && is_numeric($parentRef)) {
|
if (!$parent && is_numeric($parentRef)) {
|
||||||
$parent = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $parentRef);
|
$parent = DataObject::get_by_id(SiteTree::class, $parentRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Controllers;
|
namespace SilverStripe\CMS\Controllers;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
@ -29,7 +30,7 @@ class LeftAndMainPageIconsExtension extends Extension
|
|||||||
{
|
{
|
||||||
$css = '';
|
$css = '';
|
||||||
|
|
||||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
|
$classes = ClassInfo::subclassesFor(SiteTree::class);
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
$obj = singleton($class);
|
$obj = singleton($class);
|
||||||
$iconSpec = $obj->config()->get('icon');
|
$iconSpec = $obj->config()->get('icon');
|
||||||
|
@ -49,7 +49,7 @@ class ModelAsController extends Controller implements NestedController
|
|||||||
|
|
||||||
protected function init()
|
protected function init()
|
||||||
{
|
{
|
||||||
singleton('SilverStripe\\CMS\\Model\\SiteTree')->extend('modelascontrollerInit', $this);
|
singleton(SiteTree::class)->extend('modelascontrollerInit', $this);
|
||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ class SilverStripeNavigator extends ViewableData
|
|||||||
{
|
{
|
||||||
$items = array();
|
$items = array();
|
||||||
|
|
||||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem');
|
$classes = ClassInfo::subclassesFor(SilverStripeNavigatorItem::class);
|
||||||
unset($classes['SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem']);
|
array_shift($classes);
|
||||||
|
|
||||||
// Sort menu items according to priority
|
// Sort menu items according to priority
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
|
@ -2488,17 +2488,18 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
|
|
||||||
// Parse candidate list
|
// Parse candidate list
|
||||||
$allowedChildren = [];
|
$allowedChildren = [];
|
||||||
foreach ($candidates as $candidate) {
|
foreach ((array)$candidates as $candidate) {
|
||||||
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
|
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
|
||||||
// Otherwise, the class and all its subclasses are allowed.
|
// Otherwise, the class and all its subclasses are allowed.
|
||||||
if (substr($candidate, 0, 1) == '*') {
|
if (substr($candidate, 0, 1) == '*') {
|
||||||
$allowedChildren[] = substr($candidate, 1);
|
$allowedChildren[] = substr($candidate, 1);
|
||||||
} elseif ($subclasses = ClassInfo::subclassesFor($candidate)) {
|
} elseif (($candidate !== 'SiteTree_root')
|
||||||
|
&& ($subclasses = ClassInfo::subclassesFor($candidate))
|
||||||
|
) {
|
||||||
foreach ($subclasses as $subclass) {
|
foreach ($subclasses as $subclass) {
|
||||||
if ($subclass == 'SiteTree_root' || singleton($subclass) instanceof HiddenClass) {
|
if (!is_a($subclass, HiddenClass::class, true)) {
|
||||||
continue;
|
$allowedChildren[] = $subclass;
|
||||||
}
|
}
|
||||||
$allowedChildren[] = $subclass;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static::$_allowedChildren[get_class($this)] = $allowedChildren;
|
static::$_allowedChildren[get_class($this)] = $allowedChildren;
|
||||||
|
@ -3,11 +3,9 @@
|
|||||||
namespace SilverStripe\CMS\Model;
|
namespace SilverStripe\CMS\Model;
|
||||||
|
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\Core\Convert;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\ReadonlyField;
|
use SilverStripe\Forms\ReadonlyField;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
use SilverStripe\ORM\DataObject;
|
|
||||||
use SilverStripe\ORM\ManyManyList;
|
use SilverStripe\ORM\ManyManyList;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\View\SSViewer;
|
use SilverStripe\View\SSViewer;
|
||||||
@ -25,9 +23,8 @@ use Subsite;
|
|||||||
*/
|
*/
|
||||||
class SiteTreeFileExtension extends DataExtension
|
class SiteTreeFileExtension extends DataExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $belongs_many_many = array(
|
private static $belongs_many_many = array(
|
||||||
'BackLinkTracking' => 'SilverStripe\\CMS\\Model\\SiteTree.ImageTracking' // {@see SiteTreeLinkTracking}
|
'BackLinkTracking' => SiteTree::class . '.ImageTracking' // {@see SiteTreeLinkTracking}
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +119,7 @@ class SiteTreeFileExtension extends DataExtension
|
|||||||
$brokenPageIDs = $this->owner->BackLinkTracking()->column("ID");
|
$brokenPageIDs = $this->owner->BackLinkTracking()->column("ID");
|
||||||
if ($brokenPageIDs) {
|
if ($brokenPageIDs) {
|
||||||
// This will syncLinkTracking on the same stage as this file
|
// This will syncLinkTracking on the same stage as this file
|
||||||
$brokenPages = DataObject::get('SilverStripe\\CMS\\Model\\SiteTree')->byIDs($brokenPageIDs);
|
$brokenPages = SiteTree::get()->byIDs($brokenPageIDs);
|
||||||
foreach ($brokenPages as $brokenPage) {
|
foreach ($brokenPages as $brokenPage) {
|
||||||
$brokenPage->write();
|
$brokenPage->write();
|
||||||
}
|
}
|
||||||
|
@ -2,61 +2,73 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Model;
|
namespace SilverStripe\CMS\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Assets\Folder;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\ORM\DataQuery;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
use SilverStripe\ORM\DataList;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Cleanup, refactor, test this class
|
|
||||||
*/
|
|
||||||
class SiteTreeFolderExtension extends DataExtension
|
class SiteTreeFolderExtension extends DataExtension
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks for files used in system and create where clause which contains all ID's of files.
|
* Looks for files used in system and create where clause which contains all ID's of files.
|
||||||
*
|
*
|
||||||
* @returns String where clause which will work as filter.
|
* @returns string where clause which will work as filter.
|
||||||
*/
|
*/
|
||||||
public function getUnusedFilesListFilter()
|
public function getUnusedFilesListFilter()
|
||||||
{
|
{
|
||||||
$result = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"");
|
// Add all records in link tracking
|
||||||
$usedFiles = array();
|
$usedFiles = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"")->column('FileID');
|
||||||
$where = '';
|
|
||||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
|
|
||||||
|
|
||||||
if ($result->numRecords() > 0) {
|
// Get all classes that aren't folder
|
||||||
while ($nextResult = $result->next()) {
|
$fileClasses = array_diff_key(
|
||||||
$where .= $nextResult['FileID'] . ',';
|
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) {
|
foreach ($classes as $className) {
|
||||||
$query = new DataQuery($className);
|
// Build query based on all direct has_ones on this class
|
||||||
$ids = $query->execute()->column();
|
$hasOnes = Config::inst()->get($className, 'has_one', Config::UNINHERITED);
|
||||||
if (!count($ids)) {
|
if (empty($hasOnes)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$where = [];
|
||||||
foreach (singleton($className)->hasOne() as $relName => $joinClass) {
|
$columns = [];
|
||||||
if ($joinClass == 'SilverStripe\\Assets\\Image' || $joinClass == 'SilverStripe\\Assets\\File') {
|
foreach ($hasOnes as $relName => $joinClass) {
|
||||||
$fieldName = $relName .'ID';
|
if (in_array($joinClass, $fileClasses)) {
|
||||||
$query = DataList::create($className)->where("$fieldName > 0");
|
$column = $relName . 'ID';
|
||||||
$query->distinct = true;
|
$columns[] = $column;
|
||||||
$query->select(array($fieldName));
|
$quotedColumn = $schema->sqlColumnForField($className, $column);
|
||||||
$usedFiles = array_merge($usedFiles, $query->execute()->column());
|
$where[] = "{$quotedColumn} > 0";
|
||||||
} elseif ($joinClass == 'SilverStripe\\Assets\\Folder') {
|
|
||||||
// @todo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
if ($usedFiles) {
|
||||||
return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND (\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
|
return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND $classFilter";
|
||||||
} else {
|
} else {
|
||||||
return "(\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
|
return $classFilter;
|
||||||
}
|
}
|
||||||
return $where; // @todo - How?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class SiteTreeLinkTracking_Parser
|
|||||||
// Link to a page on this site.
|
// Link to a page on this site.
|
||||||
$matches = array();
|
$matches = array();
|
||||||
if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href, $matches)) {
|
if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href, $matches)) {
|
||||||
$page = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $matches['id']);
|
$page = DataObject::get_by_id(SiteTree::class, $matches['id']);
|
||||||
$broken = false;
|
$broken = false;
|
||||||
|
|
||||||
if (!$page) {
|
if (!$page) {
|
||||||
|
@ -25,7 +25,6 @@ use Page;
|
|||||||
*/
|
*/
|
||||||
class VirtualPage extends Page
|
class VirtualPage extends Page
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $description = 'Displays the content of another page';
|
private static $description = 'Displays the content of another page';
|
||||||
|
|
||||||
public static $virtualFields;
|
public static $virtualFields;
|
||||||
@ -114,7 +113,7 @@ class VirtualPage extends Page
|
|||||||
public function setCopyContentFromID($val)
|
public function setCopyContentFromID($val)
|
||||||
{
|
{
|
||||||
// Sanity check to prevent pages virtualising other virtual pages
|
// Sanity check to prevent pages virtualising other virtual pages
|
||||||
if ($val && DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $val) instanceof VirtualPage) {
|
if ($val && DataObject::get_by_id(SiteTree::class, $val) instanceof VirtualPage) {
|
||||||
$val = 0;
|
$val = 0;
|
||||||
}
|
}
|
||||||
return $this->setField("CopyContentFromID", $val);
|
return $this->setField("CopyContentFromID", $val);
|
||||||
@ -193,7 +192,7 @@ class VirtualPage extends Page
|
|||||||
|
|
||||||
// Unpublished source
|
// Unpublished source
|
||||||
if (!Versioned::get_versionnumber_by_stage(
|
if (!Versioned::get_versionnumber_by_stage(
|
||||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
SiteTree::class,
|
||||||
'Live',
|
'Live',
|
||||||
$this->CopyContentFromID
|
$this->CopyContentFromID
|
||||||
)) {
|
)) {
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Reports;
|
namespace SilverStripe\CMS\Reports;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\CMS\Model\VirtualPage;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -26,17 +29,17 @@ class BrokenFilesReport extends Report
|
|||||||
{
|
{
|
||||||
// Get class names for page types that are not virtual pages or redirector pages
|
// Get class names for page types that are not virtual pages or redirector pages
|
||||||
$classes = array_diff(
|
$classes = array_diff(
|
||||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree'),
|
ClassInfo::subclassesFor(SiteTree::class),
|
||||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage'),
|
ClassInfo::subclassesFor(VirtualPage::class),
|
||||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage')
|
ClassInfo::subclassesFor(RedirectorPage::class)
|
||||||
);
|
);
|
||||||
$classParams = DB::placeholders($classes);
|
$classParams = DB::placeholders($classes);
|
||||||
$classFilter = array(
|
$classFilter = array(
|
||||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenFile\" = 1" => $classes
|
"\"ClassName\" IN ($classParams) AND \"HasBrokenFile\" = 1" => $classes
|
||||||
);
|
);
|
||||||
|
|
||||||
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
$stage = isset($params['OnLive']) ? Versioned::LIVE : Versioned::DRAFT;
|
||||||
return Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', $stage, $classFilter);
|
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function columns()
|
public function columns()
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
namespace SilverStripe\CMS\Reports;
|
namespace SilverStripe\CMS\Reports;
|
||||||
|
|
||||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||||
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\CMS\Model\VirtualPage;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Forms\DropdownField;
|
use SilverStripe\Forms\DropdownField;
|
||||||
@ -21,7 +23,7 @@ class BrokenLinksReport extends Report
|
|||||||
|
|
||||||
public function title()
|
public function title()
|
||||||
{
|
{
|
||||||
return _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.BROKENLINKS', "Broken links report");
|
return _t(__CLASS__ . '.BROKENLINKS', "Broken links report");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sourceRecords($params, $sort, $limit)
|
public function sourceRecords($params, $sort, $limit)
|
||||||
@ -47,38 +49,37 @@ class BrokenLinksReport extends Report
|
|||||||
);
|
);
|
||||||
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published';
|
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published';
|
||||||
if ($isLive) {
|
if ($isLive) {
|
||||||
$ret = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', $brokenFilter, $sort, $join, $limit);
|
$ret = Versioned::get_by_stage(SiteTree::class, 'Live', $brokenFilter, $sort, $join, $limit);
|
||||||
} else {
|
} else {
|
||||||
$ret = DataObject::get('SilverStripe\\CMS\\Model\\SiteTree', $brokenFilter, $sort, $join, $limit);
|
$ret = DataObject::get(SiteTree::class, $brokenFilter, $sort, $join, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$returnSet = new ArrayList();
|
$returnSet = new ArrayList();
|
||||||
if ($ret) {
|
if ($ret) {
|
||||||
foreach ($ret as $record) {
|
foreach ($ret as $record) {
|
||||||
$reason = false;
|
$reason = false;
|
||||||
$isRedirectorPage = in_array($record->ClassName, ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage'));
|
$isRedirectorPage = $record instanceof RedirectorPage;
|
||||||
$isVirtualPage = in_array($record->ClassName, ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage'));
|
$isVirtualPage = $record instanceof VirtualPage;
|
||||||
|
|
||||||
$reasonCodes = [];
|
$reasonCodes = [];
|
||||||
if ($isVirtualPage) {
|
if ($isVirtualPage) {
|
||||||
if ($record->HasBrokenLink) {
|
if ($record->HasBrokenLink) {
|
||||||
$reason = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.VirtualPageNonExistent', "virtual page pointing to non-existent page");
|
$reason = _t(__CLASS__ . '.VirtualPageNonExistent', "virtual page pointing to non-existent page");
|
||||||
$reasonCodes = array("VPBROKENLINK");
|
$reasonCodes = array("VPBROKENLINK");
|
||||||
}
|
}
|
||||||
} elseif ($isRedirectorPage) {
|
} elseif ($isRedirectorPage) {
|
||||||
if ($record->HasBrokenLink) {
|
if ($record->HasBrokenLink) {
|
||||||
$reason = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.RedirectorNonExistent', "redirector page pointing to non-existent page");
|
$reason = _t(__CLASS__ . '.RedirectorNonExistent', "redirector page pointing to non-existent page");
|
||||||
$reasonCodes = array("RPBROKENLINK");
|
$reasonCodes = array("RPBROKENLINK");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
||||||
$reason = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.HasBrokenLinkAndFile', "has broken link and file");
|
$reason = _t(__CLASS__ . '.HasBrokenLinkAndFile', "has broken link and file");
|
||||||
$reasonCodes = array("BROKENFILE", "BROKENLINK");
|
$reasonCodes = array("BROKENFILE", "BROKENLINK");
|
||||||
} elseif ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
} elseif ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
||||||
$reason = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.HasBrokenLink', "has broken link");
|
$reason = _t(__CLASS__ . '.HasBrokenLink', "has broken link");
|
||||||
$reasonCodes = array("BROKENLINK");
|
$reasonCodes = array("BROKENLINK");
|
||||||
} elseif (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
} elseif (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
||||||
$reason = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.HasBrokenFile', "has broken file");
|
$reason = _t(__CLASS__ . '.HasBrokenFile', "has broken file");
|
||||||
$reasonCodes = array("BROKENFILE");
|
$reasonCodes = array("BROKENFILE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,20 +103,20 @@ class BrokenLinksReport extends Report
|
|||||||
public function columns()
|
public function columns()
|
||||||
{
|
{
|
||||||
if (isset($_REQUEST['filters']['CheckSite']) && $_REQUEST['filters']['CheckSite'] == 'Draft') {
|
if (isset($_REQUEST['filters']['CheckSite']) && $_REQUEST['filters']['CheckSite'] == 'Draft') {
|
||||||
$dateTitle = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnDateLastModified', 'Date last modified');
|
$dateTitle = _t(__CLASS__ . '.ColumnDateLastModified', 'Date last modified');
|
||||||
} else {
|
} else {
|
||||||
$dateTitle = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnDateLastPublished', 'Date last published');
|
$dateTitle = _t(__CLASS__ . '.ColumnDateLastPublished', 'Date last published');
|
||||||
}
|
}
|
||||||
|
|
||||||
$linkBase = CMSPageEditController::singleton()->Link('show');
|
$linkBase = CMSPageEditController::singleton()->Link('show');
|
||||||
$fields = array(
|
$fields = array(
|
||||||
"Title" => array(
|
"Title" => array(
|
||||||
"title" => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.PageName', 'Page name'),
|
"title" => _t(__CLASS__ . '.PageName', 'Page name'),
|
||||||
'formatting' => function ($value, $item) use ($linkBase) {
|
'formatting' => function ($value, $item) use ($linkBase) {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<a href="%s" title="%s">%s</a>',
|
'<a href="%s" title="%s">%s</a>',
|
||||||
Controller::join_links($linkBase, $item->ID),
|
Controller::join_links($linkBase, $item->ID),
|
||||||
_t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.HoverTitleEditPage', 'Edit page'),
|
_t(__CLASS__ . '.HoverTitleEditPage', 'Edit page'),
|
||||||
$value
|
$value
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -125,10 +126,10 @@ class BrokenLinksReport extends Report
|
|||||||
'casting' => 'DBDatetime->Full'
|
'casting' => 'DBDatetime->Full'
|
||||||
),
|
),
|
||||||
"BrokenReason" => array(
|
"BrokenReason" => array(
|
||||||
"title" => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnProblemType', "Problem type")
|
"title" => _t(__CLASS__ . '.ColumnProblemType', "Problem type")
|
||||||
),
|
),
|
||||||
'AbsoluteLink' => array(
|
'AbsoluteLink' => array(
|
||||||
'title' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnURL', 'URL'),
|
'title' => _t(__CLASS__ . '.ColumnURL', 'URL'),
|
||||||
'formatting' => function ($value, $item) {
|
'formatting' => function ($value, $item) {
|
||||||
/** @var SiteTree $item */
|
/** @var SiteTree $item */
|
||||||
$liveLink = $item->AbsoluteLiveLink;
|
$liveLink = $item->AbsoluteLiveLink;
|
||||||
@ -148,19 +149,19 @@ class BrokenLinksReport extends Report
|
|||||||
public function parameterFields()
|
public function parameterFields()
|
||||||
{
|
{
|
||||||
return new FieldList(
|
return new FieldList(
|
||||||
new DropdownField('CheckSite', _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSite', 'Check site'), array(
|
new DropdownField('CheckSite', _t(__CLASS__ . '.CheckSite', 'Check site'), array(
|
||||||
'Published' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSiteDropdownPublished', 'Published Site'),
|
'Published' => _t(__CLASS__ . '.CheckSiteDropdownPublished', 'Published Site'),
|
||||||
'Draft' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSiteDropdownDraft', 'Draft Site')
|
'Draft' => _t(__CLASS__ . '.CheckSiteDropdownDraft', 'Draft Site')
|
||||||
)),
|
)),
|
||||||
new DropdownField(
|
new DropdownField(
|
||||||
'Reason',
|
'Reason',
|
||||||
_t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdown', 'Problem to check'),
|
_t(__CLASS__ . '.ReasonDropdown', 'Problem to check'),
|
||||||
array(
|
array(
|
||||||
'' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.Any', 'Any'),
|
'' => _t(__CLASS__ . '.Any', 'Any'),
|
||||||
'BROKENFILE' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownBROKENFILE', 'Broken file'),
|
'BROKENFILE' => _t(__CLASS__ . '.ReasonDropdownBROKENFILE', 'Broken file'),
|
||||||
'BROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownBROKENLINK', 'Broken link'),
|
'BROKENLINK' => _t(__CLASS__ . '.ReasonDropdownBROKENLINK', 'Broken link'),
|
||||||
'VPBROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
'VPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
||||||
'RPBROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
'RPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Reports;
|
namespace SilverStripe\CMS\Reports;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -24,13 +26,13 @@ class BrokenRedirectorPagesReport extends Report
|
|||||||
|
|
||||||
public function sourceRecords($params = null)
|
public function sourceRecords($params = null)
|
||||||
{
|
{
|
||||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage');
|
$classes = ClassInfo::subclassesFor(RedirectorPage::class);
|
||||||
$classParams = DB::placeholders($classes);
|
$classParams = DB::placeholders($classes);
|
||||||
$classFilter = array(
|
$classFilter = array(
|
||||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
||||||
);
|
);
|
||||||
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
||||||
return Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', $stage, $classFilter);
|
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function columns()
|
public function columns()
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Reports;
|
namespace SilverStripe\CMS\Reports;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\CMS\Model\VirtualPage;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Forms\CheckboxField;
|
use SilverStripe\Forms\CheckboxField;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
@ -24,13 +26,13 @@ class BrokenVirtualPagesReport extends Report
|
|||||||
|
|
||||||
public function sourceRecords($params = null)
|
public function sourceRecords($params = null)
|
||||||
{
|
{
|
||||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage');
|
$classes = ClassInfo::subclassesFor(VirtualPage::class);
|
||||||
$classParams = DB::placeholders($classes);
|
$classParams = DB::placeholders($classes);
|
||||||
$classFilter = array(
|
$classFilter = array(
|
||||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
||||||
);
|
);
|
||||||
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
||||||
return Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', $stage, $classFilter);
|
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function columns()
|
public function columns()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace SilverStripe\CMS\Tasks;
|
namespace SilverStripe\CMS\Tasks;
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Dev\BuildTask;
|
use SilverStripe\Dev\BuildTask;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
@ -24,7 +25,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
|||||||
$pages = 0;
|
$pages = 0;
|
||||||
$links = 0;
|
$links = 0;
|
||||||
|
|
||||||
$linkedPages = new DataList('SilverStripe\\CMS\\Model\\SiteTree');
|
$linkedPages = new DataList(SiteTree::class);
|
||||||
$linkedPages = $linkedPages->innerJoin('SiteTree_LinkTracking', '"SiteTree_LinkTracking"."SiteTreeID" = "SiteTree"."ID"');
|
$linkedPages = $linkedPages->innerJoin('SiteTree_LinkTracking', '"SiteTree_LinkTracking"."SiteTreeID" = "SiteTree"."ID"');
|
||||||
if ($linkedPages) {
|
if ($linkedPages) {
|
||||||
foreach ($linkedPages as $page) {
|
foreach ($linkedPages as $page) {
|
||||||
@ -34,7 +35,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
|||||||
)->map();
|
)->map();
|
||||||
|
|
||||||
foreach ($tracking as $childID => $fieldName) {
|
foreach ($tracking as $childID => $fieldName) {
|
||||||
$linked = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $childID);
|
$linked = DataObject::get_by_id(SiteTree::class, $childID);
|
||||||
|
|
||||||
// TOOD: Replace in all HTMLText fields
|
// TOOD: Replace in all HTMLText fields
|
||||||
$page->Content = preg_replace(
|
$page->Content = preg_replace(
|
||||||
@ -50,8 +51,8 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$page->write();
|
$page->write();
|
||||||
$pages++;
|
$pages++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ in the other stage:<br />
|
|||||||
</p>
|
</p>
|
||||||
";
|
";
|
||||||
|
|
||||||
protected $orphanedSearchClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
protected $orphanedSearchClass = SiteTree::class;
|
||||||
|
|
||||||
protected function init()
|
protected function init()
|
||||||
{
|
{
|
||||||
@ -341,7 +341,7 @@ in the other stage:<br />
|
|||||||
* @param int|array $limit
|
* @param int|array $limit
|
||||||
* @return SS_List
|
* @return SS_List
|
||||||
*/
|
*/
|
||||||
public function getOrphanedPages($class = 'SilverStripe\\CMS\\Model\\SiteTree', $filter = array(), $sort = null, $join = null, $limit = null)
|
public function getOrphanedPages($class = SiteTree::class, $filter = array(), $sort = null, $join = null, $limit = null)
|
||||||
{
|
{
|
||||||
// Alter condition
|
// Alter condition
|
||||||
$table = DataObject::getSchema()->tableName($class);
|
$table = DataObject::getSchema()->tableName($class);
|
||||||
|
62
tests/php/Model/SiteTreeFolderExtensionTest.php
Normal file
62
tests/php/Model/SiteTreeFolderExtensionTest.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Tests\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Assets\Image;
|
||||||
|
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
|
||||||
|
use SilverStripe\CMS\Tests\Model\SiteTreeFolderExtensionTest\PageWithFile;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
|
class SiteTreeFolderExtensionTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected static $extra_dataobjects = [
|
||||||
|
PageWithFile::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
protected static $fixture_file = 'SiteTreeFolderExtensionTest.yml';
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Versioned::set_stage(Versioned::DRAFT);
|
||||||
|
|
||||||
|
TestAssetStore::activate('SiteTreeFolderExtensionTest');
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
|
|
||||||
|
// Since we can't hard-code IDs, manually inject image tracking shortcode
|
||||||
|
$imageID = $this->idFromFixture(Image::class, 'image1');
|
||||||
|
$page = $this->objFromFixture(PageWithFile::class, 'page1');
|
||||||
|
$page->Content = sprintf(
|
||||||
|
'<p>[image id="%d"]</p>',
|
||||||
|
$imageID
|
||||||
|
);
|
||||||
|
$page->write();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
TestAssetStore::reset();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindsFiles()
|
||||||
|
{
|
||||||
|
/** @var PageWithFile $page */
|
||||||
|
$page = $this->objFromFixture(PageWithFile::class, 'page1');
|
||||||
|
$query = $page->getUnusedFilesListFilter();
|
||||||
|
$this->assertContains('"ID" NOT IN', $query);
|
||||||
|
$this->assertContains('"ClassName" IN (', $query);
|
||||||
|
|
||||||
|
$files = File::get()->where($query);
|
||||||
|
$this->assertDOSEquals(
|
||||||
|
[
|
||||||
|
['Name' => 'file2.txt'],
|
||||||
|
['Name' => 'image2.jpg'],
|
||||||
|
],
|
||||||
|
$files
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
28
tests/php/Model/SiteTreeFolderExtensionTest.yml
Normal file
28
tests/php/Model/SiteTreeFolderExtensionTest.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
SilverStripe\Assets\Folder:
|
||||||
|
folder1:
|
||||||
|
Name: myfolder
|
||||||
|
folder2:
|
||||||
|
Name: other
|
||||||
|
SilverStripe\Assets\File:
|
||||||
|
file1:
|
||||||
|
Name: file1.txt
|
||||||
|
FileFilename: myfolder/file1.txt
|
||||||
|
Parent: =>SilverStripe\Assets\Folder.folder1
|
||||||
|
file2:
|
||||||
|
Name: file2.txt
|
||||||
|
FileFilename: myfolder/file2.txt
|
||||||
|
Parent: =>SilverStripe\Assets\Folder.folder1
|
||||||
|
SilverStripe\Assets\Image:
|
||||||
|
image1:
|
||||||
|
Name: image1.jpg
|
||||||
|
FileFilename: other/image1.jpg
|
||||||
|
Parent: =>SilverStripe\Assets\Folder.folder2
|
||||||
|
image2:
|
||||||
|
Name: image2.jpg
|
||||||
|
FileFilename: other/image2.jpg
|
||||||
|
Parent: =>SilverStripe\Assets\Folder.folder2
|
||||||
|
SilverStripe\CMS\Tests\Model\SiteTreeFolderExtensionTest\PageWithFile:
|
||||||
|
page1:
|
||||||
|
Title: mypage
|
||||||
|
URLSegment: mypage
|
||||||
|
LinkedFile: =>SilverStripe\Assets\File.file1
|
24
tests/php/Model/SiteTreeFolderExtensionTest/PageWithFile.php
Normal file
24
tests/php/Model/SiteTreeFolderExtensionTest/PageWithFile.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Tests\Model\SiteTreeFolderExtensionTest;
|
||||||
|
|
||||||
|
use Page;
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\CMS\Model\SiteTreeFolderExtension;
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin SiteTreeFolderExtension
|
||||||
|
*/
|
||||||
|
class PageWithFile extends Page implements TestOnly
|
||||||
|
{
|
||||||
|
private static $table_name = 'SiteTreeFolderExtensionTest_PageWithFile';
|
||||||
|
|
||||||
|
private static $has_one = [
|
||||||
|
'LinkedFile' => File::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $extensions = [
|
||||||
|
SiteTreeFolderExtension::class,
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user