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
|
||||
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();
|
||||
@ -1734,7 +1734,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
}
|
||||
|
||||
/** @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
|
||||
));
|
||||
|
||||
|
@ -76,7 +76,7 @@ class CMSPageAddController extends CMSPageEditController
|
||||
$parentField = new TreeDropdownField(
|
||||
"ParentID",
|
||||
"",
|
||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
||||
SiteTree::class,
|
||||
'ID',
|
||||
'TreeTitle'
|
||||
),
|
||||
|
@ -74,7 +74,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
|
||||
public static function get_all_filters()
|
||||
{
|
||||
// get all filter instances
|
||||
$filters = ClassInfo::subclassesFor('SilverStripe\\CMS\\Controllers\\CMSSiteTreeFilter');
|
||||
$filters = ClassInfo::subclassesFor(CMSSiteTreeFilter::class);
|
||||
|
||||
// remove abstract CMSSiteTreeFilter class
|
||||
array_shift($filters);
|
||||
@ -162,7 +162,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
|
||||
}
|
||||
|
||||
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');
|
||||
$parents = array();
|
||||
foreach ($list as $id => $parentID) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ class CMSSiteTreeFilter_ChangedPages extends CMSSiteTreeFilter
|
||||
|
||||
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)
|
||||
->leftJoin('SiteTree_Live', '"SiteTree_Live"."ID" = "SiteTree"."ID"')
|
||||
->where('"SiteTree"."Version" <> "SiteTree_Live"."Version"');
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
@ -29,7 +30,7 @@ class CMSSiteTreeFilter_DeletedPages extends CMSSiteTreeFilter
|
||||
|
||||
public function getFilteredPages()
|
||||
{
|
||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
return $pages;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class CMSSiteTreeFilter_PublishedPages extends CMSSiteTreeFilter
|
||||
*/
|
||||
public function getFilteredPages()
|
||||
{
|
||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
return $page->isPublished();
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
@ -21,7 +22,7 @@ class CMSSiteTreeFilter_Search extends CMSSiteTreeFilter
|
||||
public function getFilteredPages()
|
||||
{
|
||||
// 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);
|
||||
return $pages;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter
|
||||
*/
|
||||
public function getFilteredPages()
|
||||
{
|
||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
|
@ -25,7 +25,7 @@ class CMSSiteTreeFilter_StatusDraftPages extends CMSSiteTreeFilter
|
||||
*/
|
||||
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 = $pages->filterByCallback(function (SiteTree $page) {
|
||||
// If page exists on stage but not on live
|
||||
|
@ -24,7 +24,7 @@ class CMSSiteTreeFilter_StatusRemovedFromDraftPages extends CMSSiteTreeFilter
|
||||
*/
|
||||
public function getFilteredPages()
|
||||
{
|
||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$pages = Versioned::get_including_deleted(SiteTree::class);
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
// If page is removed from stage but not live
|
||||
|
@ -108,7 +108,7 @@ class ContentController extends Controller
|
||||
$parent = SiteTree::get_by_link($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) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\CMS\Controllers;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
@ -29,7 +30,7 @@ class LeftAndMainPageIconsExtension extends Extension
|
||||
{
|
||||
$css = '';
|
||||
|
||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$classes = ClassInfo::subclassesFor(SiteTree::class);
|
||||
foreach ($classes as $class) {
|
||||
$obj = singleton($class);
|
||||
$iconSpec = $obj->config()->get('icon');
|
||||
|
@ -49,7 +49,7 @@ class ModelAsController extends Controller implements NestedController
|
||||
|
||||
protected function init()
|
||||
{
|
||||
singleton('SilverStripe\\CMS\\Model\\SiteTree')->extend('modelascontrollerInit', $this);
|
||||
singleton(SiteTree::class)->extend('modelascontrollerInit', $this);
|
||||
parent::init();
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,8 @@ class SilverStripeNavigator extends ViewableData
|
||||
{
|
||||
$items = array();
|
||||
|
||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem');
|
||||
unset($classes['SilverStripe\\CMS\\Controllers\\SilverStripeNavigatorItem']);
|
||||
$classes = ClassInfo::subclassesFor(SilverStripeNavigatorItem::class);
|
||||
array_shift($classes);
|
||||
|
||||
// Sort menu items according to priority
|
||||
foreach ($classes as $class) {
|
||||
|
@ -2488,17 +2488,18 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
|
||||
// Parse candidate list
|
||||
$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.
|
||||
// Otherwise, the class and all its subclasses are allowed.
|
||||
if (substr($candidate, 0, 1) == '*') {
|
||||
$allowedChildren[] = substr($candidate, 1);
|
||||
} elseif ($subclasses = ClassInfo::subclassesFor($candidate)) {
|
||||
} elseif (($candidate !== 'SiteTree_root')
|
||||
&& ($subclasses = ClassInfo::subclassesFor($candidate))
|
||||
) {
|
||||
foreach ($subclasses as $subclass) {
|
||||
if ($subclass == 'SiteTree_root' || singleton($subclass) instanceof HiddenClass) {
|
||||
continue;
|
||||
if (!is_a($subclass, HiddenClass::class, true)) {
|
||||
$allowedChildren[] = $subclass;
|
||||
}
|
||||
$allowedChildren[] = $subclass;
|
||||
}
|
||||
}
|
||||
static::$_allowedChildren[get_class($this)] = $allowedChildren;
|
||||
|
@ -3,11 +3,9 @@
|
||||
namespace SilverStripe\CMS\Model;
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\ReadonlyField;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\ManyManyList;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\SSViewer;
|
||||
@ -25,9 +23,8 @@ use Subsite;
|
||||
*/
|
||||
class SiteTreeFileExtension extends DataExtension
|
||||
{
|
||||
|
||||
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");
|
||||
if ($brokenPageIDs) {
|
||||
// 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) {
|
||||
$brokenPage->write();
|
||||
}
|
||||
|
@ -2,61 +2,73 @@
|
||||
|
||||
namespace SilverStripe\CMS\Model;
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Folder;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\DataQuery;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
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
|
||||
{
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$result = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"");
|
||||
$usedFiles = array();
|
||||
$where = '';
|
||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
// Add all records in link tracking
|
||||
$usedFiles = DB::query("SELECT DISTINCT \"FileID\" FROM \"SiteTree_ImageTracking\"")->column('FileID');
|
||||
|
||||
if ($result->numRecords() > 0) {
|
||||
while ($nextResult = $result->next()) {
|
||||
$where .= $nextResult['FileID'] . ',';
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
$query = new DataQuery($className);
|
||||
$ids = $query->execute()->column();
|
||||
if (!count($ids)) {
|
||||
// Build query based on all direct has_ones on this class
|
||||
$hasOnes = Config::inst()->get($className, 'has_one', Config::UNINHERITED);
|
||||
if (empty($hasOnes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (singleton($className)->hasOne() as $relName => $joinClass) {
|
||||
if ($joinClass == 'SilverStripe\\Assets\\Image' || $joinClass == 'SilverStripe\\Assets\\File') {
|
||||
$fieldName = $relName .'ID';
|
||||
$query = DataList::create($className)->where("$fieldName > 0");
|
||||
$query->distinct = true;
|
||||
$query->select(array($fieldName));
|
||||
$usedFiles = array_merge($usedFiles, $query->execute()->column());
|
||||
} elseif ($joinClass == 'SilverStripe\\Assets\\Folder') {
|
||||
// @todo
|
||||
$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 (\"ClassName\" = 'File' OR \"ClassName\" = 'Image')";
|
||||
return "\"File\".\"ID\" NOT IN (" . implode(', ', $usedFiles) . ") AND $classFilter";
|
||||
} 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.
|
||||
$matches = array();
|
||||
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;
|
||||
|
||||
if (!$page) {
|
||||
|
@ -25,7 +25,6 @@ use Page;
|
||||
*/
|
||||
class VirtualPage extends Page
|
||||
{
|
||||
|
||||
private static $description = 'Displays the content of another page';
|
||||
|
||||
public static $virtualFields;
|
||||
@ -114,7 +113,7 @@ class VirtualPage extends Page
|
||||
public function setCopyContentFromID($val)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
return $this->setField("CopyContentFromID", $val);
|
||||
@ -193,7 +192,7 @@ class VirtualPage extends Page
|
||||
|
||||
// Unpublished source
|
||||
if (!Versioned::get_versionnumber_by_stage(
|
||||
'SilverStripe\\CMS\\Model\\SiteTree',
|
||||
SiteTree::class,
|
||||
'Live',
|
||||
$this->CopyContentFromID
|
||||
)) {
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
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\Forms\CheckboxField;
|
||||
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
|
||||
$classes = array_diff(
|
||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree'),
|
||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage'),
|
||||
ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage')
|
||||
ClassInfo::subclassesFor(SiteTree::class),
|
||||
ClassInfo::subclassesFor(VirtualPage::class),
|
||||
ClassInfo::subclassesFor(RedirectorPage::class)
|
||||
);
|
||||
$classParams = DB::placeholders($classes);
|
||||
$classFilter = array(
|
||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenFile\" = 1" => $classes
|
||||
);
|
||||
|
||||
$stage = isset($params['OnLive']) ? 'Live' : 'Stage';
|
||||
return Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', $stage, $classFilter);
|
||||
$stage = isset($params['OnLive']) ? Versioned::LIVE : Versioned::DRAFT;
|
||||
return Versioned::get_by_stage(SiteTree::class, $stage, $classFilter);
|
||||
}
|
||||
|
||||
public function columns()
|
||||
|
@ -3,7 +3,9 @@
|
||||
namespace SilverStripe\CMS\Reports;
|
||||
|
||||
use SilverStripe\CMS\Controllers\CMSPageEditController;
|
||||
use SilverStripe\CMS\Model\RedirectorPage;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\CMS\Model\VirtualPage;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
@ -21,7 +23,7 @@ class BrokenLinksReport extends Report
|
||||
|
||||
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)
|
||||
@ -47,38 +49,37 @@ class BrokenLinksReport extends Report
|
||||
);
|
||||
$isLive = !isset($params['CheckSite']) || $params['CheckSite'] == 'Published';
|
||||
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 {
|
||||
$ret = DataObject::get('SilverStripe\\CMS\\Model\\SiteTree', $brokenFilter, $sort, $join, $limit);
|
||||
$ret = DataObject::get(SiteTree::class, $brokenFilter, $sort, $join, $limit);
|
||||
}
|
||||
|
||||
$returnSet = new ArrayList();
|
||||
if ($ret) {
|
||||
foreach ($ret as $record) {
|
||||
$reason = false;
|
||||
$isRedirectorPage = in_array($record->ClassName, ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage'));
|
||||
$isVirtualPage = in_array($record->ClassName, ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage'));
|
||||
|
||||
$isRedirectorPage = $record instanceof RedirectorPage;
|
||||
$isVirtualPage = $record instanceof VirtualPage;
|
||||
$reasonCodes = [];
|
||||
if ($isVirtualPage) {
|
||||
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");
|
||||
}
|
||||
} elseif ($isRedirectorPage) {
|
||||
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");
|
||||
}
|
||||
} else {
|
||||
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");
|
||||
} 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");
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
@ -102,20 +103,20 @@ class BrokenLinksReport extends Report
|
||||
public function columns()
|
||||
{
|
||||
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 {
|
||||
$dateTitle = _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnDateLastPublished', 'Date last published');
|
||||
$dateTitle = _t(__CLASS__ . '.ColumnDateLastPublished', 'Date last published');
|
||||
}
|
||||
|
||||
$linkBase = CMSPageEditController::singleton()->Link('show');
|
||||
$fields = array(
|
||||
"Title" => array(
|
||||
"title" => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.PageName', 'Page name'),
|
||||
"title" => _t(__CLASS__ . '.PageName', 'Page name'),
|
||||
'formatting' => function ($value, $item) use ($linkBase) {
|
||||
return sprintf(
|
||||
'<a href="%s" title="%s">%s</a>',
|
||||
Controller::join_links($linkBase, $item->ID),
|
||||
_t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.HoverTitleEditPage', 'Edit page'),
|
||||
_t(__CLASS__ . '.HoverTitleEditPage', 'Edit page'),
|
||||
$value
|
||||
);
|
||||
}
|
||||
@ -125,10 +126,10 @@ class BrokenLinksReport extends Report
|
||||
'casting' => 'DBDatetime->Full'
|
||||
),
|
||||
"BrokenReason" => array(
|
||||
"title" => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnProblemType', "Problem type")
|
||||
"title" => _t(__CLASS__ . '.ColumnProblemType', "Problem type")
|
||||
),
|
||||
'AbsoluteLink' => array(
|
||||
'title' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ColumnURL', 'URL'),
|
||||
'title' => _t(__CLASS__ . '.ColumnURL', 'URL'),
|
||||
'formatting' => function ($value, $item) {
|
||||
/** @var SiteTree $item */
|
||||
$liveLink = $item->AbsoluteLiveLink;
|
||||
@ -148,19 +149,19 @@ class BrokenLinksReport extends Report
|
||||
public function parameterFields()
|
||||
{
|
||||
return new FieldList(
|
||||
new DropdownField('CheckSite', _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSite', 'Check site'), array(
|
||||
'Published' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSiteDropdownPublished', 'Published Site'),
|
||||
'Draft' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.CheckSiteDropdownDraft', 'Draft Site')
|
||||
new DropdownField('CheckSite', _t(__CLASS__ . '.CheckSite', 'Check site'), array(
|
||||
'Published' => _t(__CLASS__ . '.CheckSiteDropdownPublished', 'Published Site'),
|
||||
'Draft' => _t(__CLASS__ . '.CheckSiteDropdownDraft', 'Draft Site')
|
||||
)),
|
||||
new DropdownField(
|
||||
'Reason',
|
||||
_t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdown', 'Problem to check'),
|
||||
_t(__CLASS__ . '.ReasonDropdown', 'Problem to check'),
|
||||
array(
|
||||
'' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.Any', 'Any'),
|
||||
'BROKENFILE' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownBROKENFILE', 'Broken file'),
|
||||
'BROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownBROKENLINK', 'Broken link'),
|
||||
'VPBROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
||||
'RPBROKENLINK' => _t('SilverStripe\\CMS\\Reports\\BrokenLinksReport.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
||||
'' => _t(__CLASS__ . '.Any', 'Any'),
|
||||
'BROKENFILE' => _t(__CLASS__ . '.ReasonDropdownBROKENFILE', 'Broken file'),
|
||||
'BROKENLINK' => _t(__CLASS__ . '.ReasonDropdownBROKENLINK', 'Broken link'),
|
||||
'VPBROKENLINK' => _t(__CLASS__ . '.ReasonDropdownVPBROKENLINK', 'Virtual 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;
|
||||
|
||||
use SilverStripe\CMS\Model\RedirectorPage;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -24,13 +26,13 @@ class BrokenRedirectorPagesReport extends Report
|
||||
|
||||
public function sourceRecords($params = null)
|
||||
{
|
||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\RedirectorPage');
|
||||
$classes = ClassInfo::subclassesFor(RedirectorPage::class);
|
||||
$classParams = DB::placeholders($classes);
|
||||
$classFilter = array(
|
||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
||||
);
|
||||
$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()
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace SilverStripe\CMS\Reports;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\CMS\Model\VirtualPage;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
@ -24,13 +26,13 @@ class BrokenVirtualPagesReport extends Report
|
||||
|
||||
public function sourceRecords($params = null)
|
||||
{
|
||||
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\VirtualPage');
|
||||
$classes = ClassInfo::subclassesFor(VirtualPage::class);
|
||||
$classParams = DB::placeholders($classes);
|
||||
$classFilter = array(
|
||||
"\"ClassName\" IN ($classParams) AND \"HasBrokenLink\" = 1" => $classes
|
||||
);
|
||||
$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()
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace SilverStripe\CMS\Tasks;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Dev\BuildTask;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
@ -24,7 +25,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
||||
$pages = 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"');
|
||||
if ($linkedPages) {
|
||||
foreach ($linkedPages as $page) {
|
||||
@ -34,7 +35,7 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
||||
)->map();
|
||||
|
||||
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
|
||||
$page->Content = preg_replace(
|
||||
@ -50,8 +51,8 @@ class MigrateSiteTreeLinkingTask extends BuildTask
|
||||
}
|
||||
}
|
||||
|
||||
$page->write();
|
||||
$pages++;
|
||||
$page->write();
|
||||
$pages++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ in the other stage:<br />
|
||||
</p>
|
||||
";
|
||||
|
||||
protected $orphanedSearchClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
||||
protected $orphanedSearchClass = SiteTree::class;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
@ -341,7 +341,7 @@ in the other stage:<br />
|
||||
* @param int|array $limit
|
||||
* @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
|
||||
$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