mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Update CMS for versioned enhancements (#2122)
This commit is contained in:
parent
90723a2f07
commit
354d72165e
@ -56,7 +56,7 @@ class CMSBatchAction_Restore extends CMSBatchAction
|
||||
}
|
||||
|
||||
// Get pages that exist in stage and remove them from the restore-able set
|
||||
$stageIDs = Versioned::get_by_stage($this->managedClass, 'Stage')->column('ID');
|
||||
$stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID');
|
||||
return array_values(array_diff($ids, $stageIDs));
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,8 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
|
||||
}
|
||||
|
||||
while (!empty($parents)) {
|
||||
$q = Versioned::get_including_deleted(SiteTree::class, '"RecordID" in ('.implode(',', array_keys($parents)).')');
|
||||
$q = Versioned::get_including_deleted(SiteTree::class)
|
||||
->byIDs(array_keys($parents));
|
||||
$list = $q->map('ID', 'ParentID');
|
||||
$parents = array();
|
||||
foreach ($list as $id => $parentID) {
|
||||
|
@ -73,20 +73,18 @@ class OldPageRedirector extends Extension
|
||||
'ParentID' => $parent->ID,
|
||||
));
|
||||
}
|
||||
/** @var SiteTree $page */
|
||||
$page = $pages->first();
|
||||
|
||||
if (!$page) {
|
||||
// If we haven't found a candidate, lets resort to finding an old page with this URL segment
|
||||
$pages = $pages
|
||||
->filter(array(
|
||||
'WasPublished' => true,
|
||||
))
|
||||
->filter('WasPublished', 1)
|
||||
->sort('LastEdited', 'DESC')
|
||||
->setDataQueryParam("Versioned.mode", 'all_versions');
|
||||
|
||||
$record = $pages->first();
|
||||
if ($record) {
|
||||
$page = SiteTree::get()->byID($record->RecordID);
|
||||
$page = SiteTree::get()->byID($record->ID);
|
||||
$redirect = true;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class RedirectorPage extends Page
|
||||
);
|
||||
|
||||
private static $has_one = array(
|
||||
"LinkTo" => "SilverStripe\\CMS\\Model\\SiteTree",
|
||||
"LinkTo" => SiteTree::class,
|
||||
);
|
||||
|
||||
private static $table_name = 'RedirectorPage';
|
||||
|
@ -13,7 +13,7 @@ use SilverStripe\CMS\Forms\SiteTreeURLSegmentField;
|
||||
use SilverStripe\Control\ContentNegotiator;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\RequestHandler;
|
||||
use SilverStripe\Core\Cache\MemberCacheFlusher;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Convert;
|
||||
@ -61,13 +61,13 @@ use SilverStripe\Security\PermissionChecker;
|
||||
use SilverStripe\Security\PermissionProvider;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\Versioned\RecursivePublishable;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\HTML;
|
||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
use SilverStripe\View\Parsers\URLSegmentFilter;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use SilverStripe\Core\Cache\MemberCacheFlusher;
|
||||
use Subsite;
|
||||
|
||||
/**
|
||||
@ -99,6 +99,7 @@ use Subsite;
|
||||
*
|
||||
* @mixin Hierarchy
|
||||
* @mixin Versioned
|
||||
* @mixin RecursivePublishable
|
||||
* @mixin SiteTreeLinkTracking
|
||||
* @mixin InheritedPermissionsExtension
|
||||
*/
|
||||
@ -1501,8 +1502,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
$oneChangedFields = array_keys($this->getChangedFields(true, 1));
|
||||
|
||||
if ($oneChangedFields && !array_diff($changedFields, $fieldsIgnoredByVersioning)) {
|
||||
// This will have the affect of preserving the versioning
|
||||
$this->migrateVersion($this->Version);
|
||||
$this->setNextWriteWithoutVersion(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2395,7 +2395,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
/**
|
||||
* Restore the content in the active copy of this SiteTree page to the stage site.
|
||||
*
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
public function doRestoreToStage()
|
||||
{
|
||||
@ -2406,33 +2406,16 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
||||
$this->ParentID = 0;
|
||||
}
|
||||
|
||||
// if no record can be found on draft stage (meaning it has been "deleted from draft" before),
|
||||
// create an empty record
|
||||
if (!DB::prepared_query("SELECT \"ID\" FROM \"SiteTree\" WHERE \"ID\" = ?", array($this->ID))->value()) {
|
||||
$conn = DB::get_conn();
|
||||
if (method_exists($conn, 'allowPrimaryKeyEditing')) {
|
||||
$conn->allowPrimaryKeyEditing(self::class, true);
|
||||
}
|
||||
DB::prepared_query("INSERT INTO \"SiteTree\" (\"ID\") VALUES (?)", array($this->ID));
|
||||
if (method_exists($conn, 'allowPrimaryKeyEditing')) {
|
||||
$conn->allowPrimaryKeyEditing(self::class, false);
|
||||
}
|
||||
}
|
||||
|
||||
$oldReadingMode = Versioned::get_reading_mode();
|
||||
Versioned::set_stage(Versioned::DRAFT);
|
||||
$this->forceChange();
|
||||
$this->write();
|
||||
|
||||
/** @var SiteTree $result */
|
||||
$result = DataObject::get_by_id(self::class, $this->ID);
|
||||
|
||||
Versioned::set_reading_mode($oldReadingMode);
|
||||
// Restore
|
||||
$this->writeToStage(Versioned::DRAFT);
|
||||
|
||||
// Need to update pages linking to this one as no longer broken
|
||||
$this->updateDependentPages();
|
||||
/** @var SiteTree $result */
|
||||
$result = Versioned::get_by_stage(self::class, Versioned::DRAFT)
|
||||
->byID($this->ID);
|
||||
$result->updateDependentPages();
|
||||
|
||||
$this->invokeWithExtensions('onAfterRestoreToStage', $this);
|
||||
$this->invokeWithExtensions('onAfterRestoreToStage', $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ class SiteTreeLinkTracking extends DataExtension
|
||||
{
|
||||
$record = $this->owner;
|
||||
|
||||
$linkedPages = array();
|
||||
$linkedFiles = array();
|
||||
$linkedPages = [];
|
||||
$linkedFiles = [];
|
||||
|
||||
$htmlValue = HTMLValue::create($record->$fieldName);
|
||||
$links = $this->parser->process($htmlValue);
|
||||
@ -125,7 +125,7 @@ class SiteTreeLinkTracking extends DataExtension
|
||||
$domReference = $link['DOMReference'];
|
||||
$classStr = trim($domReference->getAttribute('class'));
|
||||
if (!$classStr) {
|
||||
$classes = array();
|
||||
$classes = [];
|
||||
} else {
|
||||
$classes = explode(' ', $classStr);
|
||||
}
|
||||
@ -174,36 +174,36 @@ class SiteTreeLinkTracking extends DataExtension
|
||||
}
|
||||
|
||||
// Update the "LinkTracking" many_many
|
||||
if ($record->ID
|
||||
&& $record->getSchema()->manyManyComponent(get_class($record), 'LinkTracking')
|
||||
if ($record->getSchema()->manyManyComponent(get_class($record), 'LinkTracking')
|
||||
&& ($tracker = $record->LinkTracking())
|
||||
) {
|
||||
$tracker->removeByFilter(array(
|
||||
sprintf('"FieldName" = ? AND "%s" = ?', $tracker->getForeignKey())
|
||||
// If already saved, clear existing records
|
||||
if ($record->isInDB()) {
|
||||
$tracker->removeByFilter(array(
|
||||
sprintf('"FieldName" = ? AND "%s" = ?', $tracker->getForeignKey())
|
||||
=> array($fieldName, $record->ID)
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
if ($linkedPages) {
|
||||
foreach ($linkedPages as $item) {
|
||||
$tracker->add($item, array('FieldName' => $fieldName));
|
||||
}
|
||||
foreach ($linkedPages as $item) {
|
||||
$tracker->add($item, array('FieldName' => $fieldName));
|
||||
}
|
||||
}
|
||||
|
||||
// Update the "ImageTracking" many_many
|
||||
if ($record->ID
|
||||
&& $record->getSchema()->manyManyComponent(get_class($record), 'ImageTracking')
|
||||
if ($record->getSchema()->manyManyComponent(get_class($record), 'ImageTracking')
|
||||
&& ($tracker = $record->ImageTracking())
|
||||
) {
|
||||
$tracker->removeByFilter(array(
|
||||
sprintf('"FieldName" = ? AND "%s" = ?', $tracker->getForeignKey())
|
||||
// If already saved, clear existing records
|
||||
if ($record->isInDB()) {
|
||||
$tracker->removeByFilter(array(
|
||||
sprintf('"FieldName" = ? AND "%s" = ?', $tracker->getForeignKey())
|
||||
=> array($fieldName, $record->ID)
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
if ($linkedFiles) {
|
||||
foreach ($linkedFiles as $item) {
|
||||
$tracker->add($item, array('FieldName' => $fieldName));
|
||||
}
|
||||
foreach ($linkedFiles as $item) {
|
||||
$tracker->add($item, array('FieldName' => $fieldName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,7 +216,7 @@ class SiteTreeLinkTracking extends DataExtension
|
||||
public function augmentSyncLinkTracking()
|
||||
{
|
||||
// Skip live tracking
|
||||
if (Versioned::get_stage() == Versioned::LIVE) {
|
||||
if (Versioned::get_stage() === Versioned::LIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ class CMSBatchActionsTest extends SapphireTest
|
||||
$archivedyID = $this->idFromFixture(SiteTree::class, 'archivedy');
|
||||
|
||||
// Just restore one child
|
||||
$list = $pages->filter('RecordID', $archivedxID);
|
||||
$list = $pages->filter('ID', $archivedxID);
|
||||
$this->assertEquals(1, $list->count());
|
||||
$this->assertEquals($archivedID, $list->first()->ParentID);
|
||||
|
||||
@ -155,7 +155,7 @@ class CMSBatchActionsTest extends SapphireTest
|
||||
|
||||
// Restore both remaining pages
|
||||
$list = $pages
|
||||
->filter('RecordID', array($archivedID, $archivedyID))
|
||||
->filter('ID', [$archivedID, $archivedyID])
|
||||
->sort('Title');
|
||||
$this->assertEquals(2, $list->count());
|
||||
$this->assertEquals($archivedID, $list->first()->ParentID); // archivedy
|
||||
|
@ -2,16 +2,15 @@
|
||||
|
||||
namespace SilverStripe\CMS\Tests\Controllers;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Forms\FieldGroup;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\HTMLReadonlyField;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use Page;
|
||||
|
||||
class CMSPageHistoryControllerTest extends FunctionalTest
|
||||
{
|
||||
@ -20,6 +19,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
|
||||
protected $versionUnpublishedCheck;
|
||||
protected $versionPublishCheck;
|
||||
protected $versionUnpublishedCheck2;
|
||||
protected $versionPublishCheck2;
|
||||
protected $page;
|
||||
|
||||
public function setUp()
|
||||
@ -33,22 +33,20 @@ class CMSPageHistoryControllerTest extends FunctionalTest
|
||||
$this->page->URLSegment = "test";
|
||||
$this->page->Content = "new content";
|
||||
$this->page->write();
|
||||
$this->versionUnpublishedCheck = $this->page->Version;
|
||||
$this->versionUnpublishedCheck = $this->page->Version; // v1
|
||||
|
||||
$this->page->Content = "some further content";
|
||||
$this->page->write();
|
||||
$this->page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->versionPublishCheck = $this->page->Version;
|
||||
$this->page->publishSingle();
|
||||
$this->versionPublishCheck = $this->page->Version; // v2
|
||||
|
||||
$this->page->Content = "No, more changes please";
|
||||
$this->page->Title = "Changing titles too";
|
||||
$this->page->write();
|
||||
$this->versionUnpublishedCheck2 = $this->page->Version;
|
||||
$this->versionUnpublishedCheck2 = $this->page->Version; // v3
|
||||
|
||||
$this->page->Title = "Final Change";
|
||||
$this->page->write();
|
||||
$this->page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->versionPublishCheck2 = $this->page->Version;
|
||||
$this->page->publishSingle();
|
||||
$this->versionPublishCheck2 = $this->page->Version; // v4
|
||||
}
|
||||
|
||||
public function testGetEditForm()
|
||||
|
@ -197,7 +197,7 @@ class SiteTreeBrokenLinksTest extends SapphireTest
|
||||
// Redirector links are a third
|
||||
$rp = new RedirectorPage();
|
||||
$rp->Title = "redirector";
|
||||
$rp->LinkType = 'Internal';
|
||||
$rp->RedirectionType = 'Internal';
|
||||
$rp->LinkToID = $p->ID;
|
||||
$rp->write();
|
||||
$this->assertTrue($rp->publishRecursive());
|
||||
@ -207,9 +207,8 @@ class SiteTreeBrokenLinksTest extends SapphireTest
|
||||
$this->assertFalse($rp->HasBrokenLink);
|
||||
|
||||
// Unpublishing doesn't affect broken state on live (draft is source of truth)
|
||||
$p->doUnpublish();
|
||||
$p2Live = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $p2->ID);
|
||||
$rpLive = Versioned::get_one_by_stage(SiteTree::class, 'Live', '"SiteTree"."ID" = ' . $rp->ID);
|
||||
$p2Live = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE)->byID($p2->ID);
|
||||
$rpLive = Versioned::get_by_stage(SiteTree::class, Versioned::LIVE)->byID($rp->ID);
|
||||
$this->assertEquals(0, $p2Live->HasBrokenLink);
|
||||
$this->assertEquals(0, $rpLive->HasBrokenLink);
|
||||
|
||||
|
@ -771,13 +771,8 @@ class SiteTreeTest extends SapphireTest
|
||||
public function testAuthorIDAndPublisherIDFilledOutOnPublish()
|
||||
{
|
||||
// Ensure that we have a member ID who is doing all this work
|
||||
$member = security::getCurrentUser();
|
||||
if ($member) {
|
||||
$memberID = $member->ID;
|
||||
} else {
|
||||
$member = $this->objFromFixture(Member::class, "admin");
|
||||
Security::setCurrentUser($member);
|
||||
}
|
||||
$member = $this->objFromFixture(Member::class, "admin");
|
||||
$this->logInAs($member);
|
||||
|
||||
// Write the page
|
||||
$about = $this->objFromFixture('Page', 'about');
|
||||
@ -785,19 +780,25 @@ class SiteTreeTest extends SapphireTest
|
||||
$about->write();
|
||||
|
||||
// Check the version created
|
||||
$savedVersion = DB::query("SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
|
||||
WHERE \"RecordID\" = $about->ID ORDER BY \"Version\" DESC")->first();
|
||||
$this->assertEquals($memberID, $savedVersion['AuthorID']);
|
||||
$savedVersion = DB::prepared_query(
|
||||
"SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
|
||||
WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC",
|
||||
[$about->ID]
|
||||
)->first();
|
||||
$this->assertEquals($member->ID, $savedVersion['AuthorID']);
|
||||
$this->assertEquals(0, $savedVersion['PublisherID']);
|
||||
|
||||
// Publish the page
|
||||
$about->publishRecursive();
|
||||
$publishedVersion = DB::query("SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
|
||||
WHERE \"RecordID\" = $about->ID ORDER BY \"Version\" DESC")->first();
|
||||
$publishedVersion = DB::prepared_query(
|
||||
"SELECT \"AuthorID\", \"PublisherID\" FROM \"SiteTree_Versions\"
|
||||
WHERE \"RecordID\" = ? ORDER BY \"Version\" DESC",
|
||||
[$about->ID]
|
||||
)->first();
|
||||
|
||||
// Check the version created
|
||||
$this->assertEquals($memberID, $publishedVersion['AuthorID']);
|
||||
$this->assertEquals($memberID, $publishedVersion['PublisherID']);
|
||||
$this->assertEquals($member->ID, $publishedVersion['AuthorID']);
|
||||
$this->assertEquals($member->ID, $publishedVersion['PublisherID']);
|
||||
}
|
||||
|
||||
public function testLinkShortcodeHandler()
|
||||
|
@ -235,6 +235,7 @@ class VirtualPageTest extends FunctionalTest
|
||||
/** @var Page $parentPage */
|
||||
$parentPage = $this->objFromFixture('Page', 'master3');
|
||||
$parentPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
/** @var VirtualPage $virtualPage */
|
||||
$virtualPage = $this->objFromFixture(VirtualPage::class, 'vp3');
|
||||
$virtualPage->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user