mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added UpgradeSiteTreePermissionSchemaTask as a manual migration of SiteTree schema upgrades in 2.3 (see #2847)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65153 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ca6d92341e
commit
572f6728fb
48
tasks/UpgradeSiteTreePermissionSchemaTask.php
Normal file
48
tasks/UpgradeSiteTreePermissionSchemaTask.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tasks
|
||||
*/
|
||||
class UpgradeSiteTreePermissionSchemaTask extends BuildTask {
|
||||
static $allowed_actions = array(
|
||||
'*' => 'ADMIN'
|
||||
);
|
||||
|
||||
protected $title = 'Upgrade SiteTree Permissions Schema';
|
||||
|
||||
protected $description = "Move data from legacy columns to new schema introduced in SilverStripe 2.1.<br />
|
||||
SiteTree->Viewers to SiteTree->CanViewType<br />
|
||||
SiteTree->Editors to SiteTree->CanEditType<br />
|
||||
SiteTree->ViewersGroup to SiteTree->ViewerGroups (has_one to many_many)<br />
|
||||
SiteTree->Editorsroup to SiteTree->EditorGroups (has_one to many_many)<br />
|
||||
See http://open.silverstripe.com/ticket/2847
|
||||
";
|
||||
|
||||
function run($request) {
|
||||
// transfer values for changed column name
|
||||
DB::query("UPDATE SiteTree SET CanViewType = Viewers;");
|
||||
DB::query("UPDATE SiteTree_Live SET CanViewType = Viewers;");
|
||||
DB::query("UPDATE SiteTree_versions SET CanViewType = Viewers;");
|
||||
Debug::message('Moved SiteTree->Viewers to SiteTree->CanViewType');
|
||||
|
||||
// transfer values for changed column name
|
||||
DB::query("UPDATE SiteTree SET CanEditType = Editors;");
|
||||
DB::query("UPDATE SiteTree_Live SET CanEditType = Editors;");
|
||||
DB::query("UPDATE SiteTree_versions SET CanEditType = Editors;");
|
||||
Debug::message('Moved SiteTree->Editors to SiteTree->CanEditType');
|
||||
|
||||
// convert has_many to many_many
|
||||
$pageIDs = DB::query("SELECT ID FROM SiteTree")->column('ID');
|
||||
foreach($pageIDs as $pageID) {
|
||||
$page = DataObject::get_by_id('Page', $pageID);
|
||||
if($page->ViewersGroup) $page->ViewerGroups()->add($page->ViewersGroup);
|
||||
if($page->EditorsGroup) $page->EditorGroups()->add($page->EditorsGroup);
|
||||
|
||||
$page->destroy();
|
||||
unset($page);
|
||||
}
|
||||
Debug::message('SiteTree->ViewersGroup to SiteTree->ViewerGroups (has_one to many_many)');
|
||||
Debug::message('SiteTree->EditorsGroup to SiteTree->EditorGroups (has_one to many_many)');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user