From 3c47db80d83bddde21c1191c3870e741f1ff18fe Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Sat, 8 Aug 2009 04:23:05 +0000 Subject: [PATCH] BUGFIX: Fixed other parts of core in response to the changing of MySQLDatabase to not inherit from object. BUGFIX: Restored SiteTree::canView() functionality. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84068 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DatabaseAdmin.php | 4 ++-- core/model/MySQLDatabase.php | 8 ++++---- core/model/SiteTree.php | 34 ++++++++++++++++++++++++++++------ core/model/Versioned.php | 4 ++-- tests/DataObjectTest.php | 4 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index 5c4727aef..a04763883 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -145,7 +145,7 @@ class DatabaseAdmin extends Controller { DB::quiet(); } else { $conn = DB::getConn(); - $databaseName = ($conn->hasMethod('currentDatabase')) ? $conn->currentDatabase() : ""; + $databaseName = (method_exists($conn. 'currentDatabase')) ? $conn->currentDatabase() : ""; if(Director::is_cli()) echo "\n\nBuilding Database $databaseName\n\n"; else echo "

Building Database $databaseName

"; @@ -233,7 +233,7 @@ class DatabaseAdmin extends Controller { function clearAllData() { $tables = DB::getConn()->tableList(); foreach($tables as $table) { - if(DB::getConn()->hasMethod('clearTable')) DB::getConn()->clearTable($table); + if(method_exists(DB::getConn(), 'clearTable')) DB::getConn()->clearTable($table); else DB::query("TRUNCATE \"$table\""); } } diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index 794a28849..cf25f3fa5 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -211,7 +211,7 @@ class MySQLDatabase extends Database { public function createTable($table, $fields = null, $indexes = null, $options = null) { $fieldSchemas = $indexSchemas = ""; - $addOptions = empty($options[$this->class]) ? "ENGINE=MyISAM" : $options[$this->class]; + $addOptions = empty($options[get_class($this)]) ? "ENGINE=MyISAM" : $options[get_class($this)]; if(!isset($fields['ID'])) $fields['ID'] = "int(11) not null auto_increment"; if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n"; @@ -253,10 +253,10 @@ class MySQLDatabase extends Database { $alterations = implode(",\n", $alterList); $this->query("ALTER TABLE \"$tableName\" $alterations"); - if($alteredOptions && isset($alteredOptions[$this->class])) { - $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[$this->class])); + if($alteredOptions && isset($alteredOptions[get_class($this)])) { + $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[get_class($this)])); Database::alteration_message( - sprintf("Table %s options changed: %s", $tableName, $alteredOptions[$this->class]), + sprintf("Table %s options changed: %s", $tableName, $alteredOptions[get_class($this)]), "changed" ); } diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index de0f0f183..a15946738 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -661,7 +661,29 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $results = $this->extend('canView', $member); if($results && is_array($results)) if(!min($results)) return false; - return true; + // check for empty spec + if(!$this->CanViewType || $this->CanViewType == 'Anyone') return true; + + // check for inherit + if($this->CanViewType == 'Inherit') { + if($this->ParentID) return $this->Parent()->canView($member); + else return true; + } + + // check for any logged-in users + if($this->CanViewType == 'LoggedInUsers' && $member) { + return true; + } + + // check for specific groups + if($member && is_numeric($member)) $member = DataObject::get_by_id('Member', $member); + if( + $this->CanViewType == 'OnlyTheseUsers' + && $member + && $member->inGroups($this->ViewerGroups()) + ) return true; + + return false; } /** @@ -854,7 +876,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * page can be edited. */ static function can_edit_multiple($ids, $memberID, $useCached = true) { - set_time_limit(0); + // Sanitise the IDs + $ids = array_filter($ids, 'is_numeric'); + // Default result: nothing editable $result = array_fill_keys($ids, false); if($ids) { @@ -877,8 +901,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid return $result; } - // Sanitise the IDs - $ids = array_filter($ids, 'is_numeric'); $SQL_idList = implode($ids, ", "); // if page can't be viewed, don't grant edit permissions @@ -1726,9 +1748,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // create an empty record if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $this->ID")->value()) { $conn = DB::getConn(); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SiteTree', true); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SiteTree', true); DB::query("INSERT INTO \"SiteTree\" (\"ID\") VALUES ($this->ID)"); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SiteTree', false); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('SiteTree', false); } $oldStage = Versioned::current_stage(); diff --git a/core/model/Versioned.php b/core/model/Versioned.php index b1354e8a5..8aa40813c 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -454,9 +454,9 @@ class Versioned extends DataObjectDecorator { Versioned::$reading_stage = $toStage; $conn = DB::getConn(); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, true); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, true); $from->write(); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, false); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, false); $from->destroy(); diff --git a/tests/DataObjectTest.php b/tests/DataObjectTest.php index 1edb4833f..c7bb8cc46 100644 --- a/tests/DataObjectTest.php +++ b/tests/DataObjectTest.php @@ -554,13 +554,13 @@ class DataObjectTest extends SapphireTest { public function testForceInsert() { /* If you set an ID on an object and pass forceInsert = true, then the object should be correctly created */ $conn = DB::getConn(); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('DataObjectTest_Team', true); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('DataObjectTest_Team', true); $obj = new DataObjectTest_SubTeam(); $obj->ID = 1001; $obj->Title = 'asdfasdf'; $obj->SubclassDatabaseField = 'asdfasdf'; $obj->write(false, true); - if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('DataObjectTest_Team', false); + if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing('DataObjectTest_Team', false); $this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT \"ClassName\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $obj->ID")->value());