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
This commit is contained in:
Sam Minnee 2009-08-08 04:23:05 +00:00
parent 24e4c7b806
commit 3c47db80d8
5 changed files with 38 additions and 16 deletions

View File

@ -145,7 +145,7 @@ class DatabaseAdmin extends Controller {
DB::quiet(); DB::quiet();
} else { } else {
$conn = DB::getConn(); $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"; if(Director::is_cli()) echo "\n\nBuilding Database $databaseName\n\n";
else echo "<h2>Building Database $databaseName</h2>"; else echo "<h2>Building Database $databaseName</h2>";
@ -233,7 +233,7 @@ class DatabaseAdmin extends Controller {
function clearAllData() { function clearAllData() {
$tables = DB::getConn()->tableList(); $tables = DB::getConn()->tableList();
foreach($tables as $table) { 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\""); else DB::query("TRUNCATE \"$table\"");
} }
} }

View File

@ -211,7 +211,7 @@ class MySQLDatabase extends Database {
public function createTable($table, $fields = null, $indexes = null, $options = null) { public function createTable($table, $fields = null, $indexes = null, $options = null) {
$fieldSchemas = $indexSchemas = ""; $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(!isset($fields['ID'])) $fields['ID'] = "int(11) not null auto_increment";
if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n"; if($fields) foreach($fields as $k => $v) $fieldSchemas .= "\"$k\" $v,\n";
@ -253,10 +253,10 @@ class MySQLDatabase extends Database {
$alterations = implode(",\n", $alterList); $alterations = implode(",\n", $alterList);
$this->query("ALTER TABLE \"$tableName\" $alterations"); $this->query("ALTER TABLE \"$tableName\" $alterations");
if($alteredOptions && isset($alteredOptions[$this->class])) { if($alteredOptions && isset($alteredOptions[get_class($this)])) {
$this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[$this->class])); $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[get_class($this)]));
Database::alteration_message( 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" "changed"
); );
} }

View File

@ -661,7 +661,29 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$results = $this->extend('canView', $member); $results = $this->extend('canView', $member);
if($results && is_array($results)) if(!min($results)) return false; 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. * page can be edited.
*/ */
static function can_edit_multiple($ids, $memberID, $useCached = true) { 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 // Default result: nothing editable
$result = array_fill_keys($ids, false); $result = array_fill_keys($ids, false);
if($ids) { if($ids) {
@ -877,8 +901,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return $result; return $result;
} }
// Sanitise the IDs
$ids = array_filter($ids, 'is_numeric');
$SQL_idList = implode($ids, ", "); $SQL_idList = implode($ids, ", ");
// if page can't be viewed, don't grant edit permissions // 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 // create an empty record
if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $this->ID")->value()) { if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $this->ID")->value()) {
$conn = DB::getConn(); $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)"); 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(); $oldStage = Versioned::current_stage();

View File

@ -454,9 +454,9 @@ class Versioned extends DataObjectDecorator {
Versioned::$reading_stage = $toStage; Versioned::$reading_stage = $toStage;
$conn = DB::getConn(); $conn = DB::getConn();
if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, true); if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, true);
$from->write(); $from->write();
if($conn->hasMethod('allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, false); if(method_exists($conn, 'allowPrimaryKeyEditing')) $conn->allowPrimaryKeyEditing($baseClass, false);
$from->destroy(); $from->destroy();

View File

@ -554,13 +554,13 @@ class DataObjectTest extends SapphireTest {
public function testForceInsert() { public function testForceInsert() {
/* If you set an ID on an object and pass forceInsert = true, then the object should be correctly created */ /* If you set an ID on an object and pass forceInsert = true, then the object should be correctly created */
$conn = DB::getConn(); $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 = new DataObjectTest_SubTeam();
$obj->ID = 1001; $obj->ID = 1001;
$obj->Title = 'asdfasdf'; $obj->Title = 'asdfasdf';
$obj->SubclassDatabaseField = 'asdfasdf'; $obj->SubclassDatabaseField = 'asdfasdf';
$obj->write(false, true); $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()); $this->assertEquals("DataObjectTest_SubTeam", DB::query("SELECT \"ClassName\" FROM \"DataObjectTest_Team\" WHERE \"ID\" = $obj->ID")->value());