mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Updated UpgradeSiteTreePermissionSchemaTask to rename obsolete database columns
ENHANCEMENT Calling UpgradeSiteTreePermissionSchemaTask from SiteTree->requireDefaultRecords as a temporary workaround for missing migration infrastructure. This means that upgrading the schema for 2.3 can be done without manual task triggers, just the usual dev/build (see http://open.silverstripe.com/ticket/2847#comment:4) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65495 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
117806756c
commit
4452e9bb5b
@ -887,6 +887,7 @@ class SiteTree extends DataObject {
|
||||
function requireDefaultRecords() {
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
// default pages
|
||||
if($this->class == 'SiteTree') {
|
||||
if(!DataObject::get_one("SiteTree", "URLSegment = 'home'")) {
|
||||
$homepage = new Page();
|
||||
@ -922,6 +923,17 @@ class SiteTree extends DataObject {
|
||||
$contactus->flushCache();
|
||||
}
|
||||
}
|
||||
|
||||
// schema migration
|
||||
// @todo Move to migration task once infrastructure is implemented
|
||||
if($this->class == 'SiteTree') {
|
||||
$conn = DB::getConn();
|
||||
// only execute command if fields haven't been renamed to _obsolete_<fieldname> already by the task
|
||||
if(array_key_exists('Viewers', $conn->fieldList('SiteTree'))) {
|
||||
$task = new UpgradeSiteTreePermissionSchemaTask();
|
||||
$task->run(new HTTPRequest('GET','/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,16 +20,12 @@ class UpgradeSiteTreePermissionSchemaTask extends BuildTask {
|
||||
|
||||
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');
|
||||
foreach(array('SiteTree','SiteTree_Live','SiteTree_versions') as $table) {
|
||||
DB::query("UPDATE `{$table}` SET CanViewType = Viewers;");
|
||||
DB::query("UPDATE `{$table}` SET CanEditType = Editors;");
|
||||
}
|
||||
//Debug::message('Moved SiteTree->Viewers to SiteTree->CanViewType');
|
||||
//Debug::message('Moved SiteTree->Editors to SiteTree->CanEditType');
|
||||
|
||||
// convert has_many to many_many
|
||||
$pageIDs = DB::query("SELECT ID FROM SiteTree")->column('ID');
|
||||
@ -41,8 +37,15 @@ class UpgradeSiteTreePermissionSchemaTask extends BuildTask {
|
||||
$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)');
|
||||
//Debug::message('SiteTree->ViewersGroup to SiteTree->ViewerGroups (has_one to many_many)');
|
||||
//Debug::message('SiteTree->EditorsGroup to SiteTree->EditorGroups (has_one to many_many)');
|
||||
|
||||
// rename legacy columns
|
||||
foreach(array('SiteTree','SiteTree_Live','SiteTree_versions') as $table) {
|
||||
foreach(array('Viewers','Editors','ViewersGroup','EditorsGroup') as $field) {
|
||||
DB::getConn()->dontRequireField($table, $field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user