mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
24e4c7b806
commit
3c47db80d8
@ -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 "<h2>Building Database $databaseName</h2>";
|
||||
@ -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\"");
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
);
|
||||
}
|
||||
|
@ -661,9 +661,31 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
$results = $this->extend('canView', $member);
|
||||
if($results && is_array($results)) if(!min($results)) return false;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should return true if the current user can delete this
|
||||
* page. It can be overloaded to customise the security model for an
|
||||
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user