mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Revert some changes to ManyManyList
BUG Fix incompatibility in Member_GroupList Fix regressions in merges from 3.1 BUG Fix Security failing on test classes BUG Fix postgresql compatibility Clarify sql encoding of table names
This commit is contained in:
parent
2a76be490d
commit
0433ba1642
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request processer that delegates pre and post request handling to nested request filters
|
* Represents a request processer that delegates pre and post request handling to nested request filters
|
||||||
*
|
*
|
||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage control
|
* @subpackage control
|
||||||
*/
|
*/
|
||||||
@ -21,7 +21,7 @@ class RequestProcessor implements RequestFilter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assign a list of request filters
|
* Assign a list of request filters
|
||||||
*
|
*
|
||||||
* @param array $filters
|
* @param array $filters
|
||||||
*/
|
*/
|
||||||
public function setFilters($filters) {
|
public function setFilters($filters) {
|
||||||
|
@ -91,9 +91,9 @@ class FixtureFactory {
|
|||||||
public function createRaw($table, $identifier, $data) {
|
public function createRaw($table, $identifier, $data) {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach($data as $fieldName => $fieldVal) {
|
foreach($data as $fieldName => $fieldVal) {
|
||||||
$fields["\"$fieldName\""] = $this->parseValue($fieldVal);
|
$fields["\"{$fieldName}\""] = $this->parseValue($fieldVal);
|
||||||
}
|
}
|
||||||
$insert = new SQLInsert($table, $fields);
|
$insert = new SQLInsert("\"{$table}\"", $fields);
|
||||||
$insert->execute();
|
$insert->execute();
|
||||||
$id = DB::get_generated_id($table);
|
$id = DB::get_generated_id($table);
|
||||||
$this->fixtures[$table][$identifier] = $id;
|
$this->fixtures[$table][$identifier] = $id;
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
* UploadField "Select from files" shows files in all folders by default
|
* UploadField "Select from files" shows files in all folders by default
|
||||||
* UploadField won't display an overwrite warning unless Upload:replaceFile is true
|
* UploadField won't display an overwrite warning unless Upload:replaceFile is true
|
||||||
* HtmlEditorField no longer substitutes `<blockquote />` for indented text
|
* HtmlEditorField no longer substitutes `<blockquote />` for indented text
|
||||||
|
* ClassInfo::dataClassesFor now returns classes which should have tables, regardless of whether those
|
||||||
|
tables actually exist.
|
||||||
|
|
||||||
### CMS
|
### CMS
|
||||||
|
|
||||||
|
@ -59,10 +59,16 @@ class ManyManyList extends RelationList {
|
|||||||
$this->foreignKey = $foreignKey;
|
$this->foreignKey = $foreignKey;
|
||||||
$this->extraFields = $extraFields;
|
$this->extraFields = $extraFields;
|
||||||
|
|
||||||
$baseClass = ClassInfo::baseDataClass($dataClass);
|
$this->linkJoinTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the join between this dataobject and the necessary mapping table
|
||||||
|
*/
|
||||||
|
protected function linkJoinTable() {
|
||||||
// Join to the many-many join table
|
// Join to the many-many join table
|
||||||
$this->dataQuery->innerJoin($joinTable, "\"$joinTable\".\"$this->localKey\" = \"$baseClass\".\"ID\"");
|
$baseClass = ClassInfo::baseDataClass($this->dataClass);
|
||||||
|
$this->dataQuery->innerJoin($this->joinTable, "\"{$this->joinTable}\".\"{$this->localKey}\" = \"{$baseClass}\".\"ID\"");
|
||||||
|
|
||||||
// Add the extra fields to the query
|
// Add the extra fields to the query
|
||||||
if($this->extraFields) {
|
if($this->extraFields) {
|
||||||
@ -86,12 +92,12 @@ class ManyManyList extends RelationList {
|
|||||||
$this->_compositeExtraFields[$field] = array();
|
$this->_compositeExtraFields[$field] = array();
|
||||||
|
|
||||||
// append the composite field names to the select
|
// append the composite field names to the select
|
||||||
foreach($obj->compositeDatabaseFields() as $k => $f) {
|
foreach($obj->compositeDatabaseFields() as $subField => $subSpec) {
|
||||||
$col = $field . $k;
|
$col = $field . $subField;
|
||||||
$finalized[] = $col;
|
$finalized[] = $col;
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
$this->_compositeExtraFields[$field][] = $k;
|
$this->_compositeExtraFields[$field][] = $subField;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$finalized[] = $field;
|
$finalized[] = $field;
|
||||||
@ -113,16 +119,15 @@ class ManyManyList extends RelationList {
|
|||||||
|
|
||||||
if($this->_compositeExtraFields) {
|
if($this->_compositeExtraFields) {
|
||||||
foreach($this->_compositeExtraFields as $fieldName => $composed) {
|
foreach($this->_compositeExtraFields as $fieldName => $composed) {
|
||||||
// convert joined extra fields into their composite field
|
// convert joined extra fields into their composite field types.
|
||||||
// types.
|
|
||||||
$value = array();
|
$value = array();
|
||||||
|
|
||||||
foreach($composed as $i => $k) {
|
foreach($composed as $subField => $subSpec) {
|
||||||
if(isset($row[$fieldName . $k])) {
|
if(isset($row[$fieldName . $subSpec])) {
|
||||||
$value[$k] = $row[$fieldName . $k];
|
$value[$subSpec] = $row[$fieldName . $subSpec];
|
||||||
|
|
||||||
// don't duplicate data in the record
|
// don't duplicate data in the record
|
||||||
unset($row[$fieldName . $k]);
|
unset($row[$fieldName . $subSpec]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +161,7 @@ class ManyManyList extends RelationList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply relation filter
|
// Apply relation filter
|
||||||
$key = "\"$this->joinTable\".\"$this->foreignKey\"";
|
$key = "\"{$this->joinTable}\".\"{$this->foreignKey}\"";
|
||||||
if(is_array($id)) {
|
if(is_array($id)) {
|
||||||
return array("$key IN (".DB::placeholders($id).")" => $id);
|
return array("$key IN (".DB::placeholders($id).")" => $id);
|
||||||
} else if($id !== null){
|
} else if($id !== null){
|
||||||
@ -184,7 +189,8 @@ class ManyManyList extends RelationList {
|
|||||||
* Does so by adding an entry to the joinTable.
|
* Does so by adding an entry to the joinTable.
|
||||||
*
|
*
|
||||||
* @param mixed $item
|
* @param mixed $item
|
||||||
* @param $extraFields A map of additional columns to insert into the joinTable
|
* @param array $extraFields A map of additional columns to insert into the joinTable.
|
||||||
|
* Column names should be ANSI quoted.
|
||||||
*/
|
*/
|
||||||
public function add($item, $extraFields = array()) {
|
public function add($item, $extraFields = array()) {
|
||||||
// Ensure nulls or empty strings are correctly treated as empty arrays
|
// Ensure nulls or empty strings are correctly treated as empty arrays
|
||||||
@ -208,43 +214,61 @@ class ManyManyList extends RelationList {
|
|||||||
|
|
||||||
// Apply this item to each given foreign ID record
|
// Apply this item to each given foreign ID record
|
||||||
if(!is_array($foreignIDs)) $foreignIDs = array($foreignIDs);
|
if(!is_array($foreignIDs)) $foreignIDs = array($foreignIDs);
|
||||||
$baseClass = ClassInfo::baseDataClass($this->dataClass);
|
|
||||||
foreach($foreignIDs as $foreignID) {
|
foreach($foreignIDs as $foreignID) {
|
||||||
|
|
||||||
// Check for existing records for this item
|
// Check for existing records for this item
|
||||||
if($foreignFilter = $this->foreignIDFilter($foreignID)) {
|
if($foreignFilter = $this->foreignIDWriteFilter($foreignID)) {
|
||||||
// With the current query, simply add the foreign and local conditions
|
// With the current query, simply add the foreign and local conditions
|
||||||
// The query can be a bit odd, especially if custom relation classes
|
// The query can be a bit odd, especially if custom relation classes
|
||||||
// don't join expected tables (@see Member_GroupSet for example).
|
// don't join expected tables (@see Member_GroupSet for example).
|
||||||
$query = $this->dataQuery->query()->toSelect();
|
$query = new SQLSelect("*", "\"{$this->joinTable}\"");
|
||||||
$query->addWhere($foreignFilter);
|
$query->addWhere($foreignFilter);
|
||||||
$query->addWhere(array(
|
$query->addWhere(array(
|
||||||
"\"$baseClass\".\"ID\"" => $itemID
|
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
|
||||||
));
|
));
|
||||||
$hasExisting = ($query->count() > 0);
|
$hasExisting = ($query->count() > 0);
|
||||||
} else {
|
} else {
|
||||||
$hasExisting = false;
|
$hasExisting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine entry type
|
$manipulation = array();
|
||||||
if(!$hasExisting) {
|
if($hasExisting) {
|
||||||
// Field values for new record
|
$manipulation[$this->joinTable]['command'] = 'update';
|
||||||
$fieldValues = array_merge($extraFields, array(
|
$manipulation[$this->joinTable]['where'] = array(
|
||||||
"\"{$this->foreignKey}\"" => $foreignID,
|
"\"{$this->joinTable}\".\"{$this->foreignKey}\"" => $foreignID,
|
||||||
"\"{$this->localKey}\"" => $itemID
|
|
||||||
));
|
|
||||||
// Create new record
|
|
||||||
$insert = new SQLInsert("\"{$this->joinTable}\"", $fieldValues);
|
|
||||||
$insert->execute();
|
|
||||||
} elseif(!empty($extraFields)) {
|
|
||||||
// For existing records, simply update any extra data supplied
|
|
||||||
$foreignWriteFilter = $this->foreignIDWriteFilter($foreignID);
|
|
||||||
$update = new SQLUpdate("\"{$this->joinTable}\"", $extraFields, $foreignWriteFilter);
|
|
||||||
$update->addWhere(array(
|
|
||||||
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
|
"\"{$this->joinTable}\".\"{$this->localKey}\"" => $itemID
|
||||||
));
|
);
|
||||||
$update->execute();
|
} else {
|
||||||
|
$manipulation[$this->joinTable]['command'] = 'insert';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($extraFields) {
|
||||||
|
foreach($extraFields as $fieldName => $fieldValue) {
|
||||||
|
if(is_null($fieldValue)) {
|
||||||
|
$manipulation[$this->joinTable]['fields'][$fieldName] = null;
|
||||||
|
} elseif($fieldValue instanceof DBField) {
|
||||||
|
// rely on writeToManipulation to manage the changes
|
||||||
|
// required for this field.
|
||||||
|
$working = array('fields' => array());
|
||||||
|
|
||||||
|
// create a new instance of the field so we can
|
||||||
|
// modify the field name to the correct version.
|
||||||
|
$field = DBField::create_field(get_class($fieldValue), $fieldValue);
|
||||||
|
$field->setName($fieldName);
|
||||||
|
$field->writeToManipulation($working);
|
||||||
|
|
||||||
|
foreach($working['fields'] as $extraName => $extraValue) {
|
||||||
|
$manipulation[$this->joinTable]['fields'][$extraName] = $extraValue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$manipulation[$this->joinTable]['fields'][$fieldName] = $fieldValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$manipulation[$this->joinTable]['fields'][$this->localKey] = $itemID;
|
||||||
|
$manipulation[$this->joinTable]['fields'][$this->foreignKey] = $foreignID;
|
||||||
|
|
||||||
|
DB::manipulate($manipulation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +299,7 @@ class ManyManyList extends RelationList {
|
|||||||
public function removeByID($itemID) {
|
public function removeByID($itemID) {
|
||||||
if(!is_numeric($itemID)) throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
|
if(!is_numeric($itemID)) throw new InvalidArgumentException("ManyManyList::removeById() expecting an ID");
|
||||||
|
|
||||||
$query = new SQLDelete("\"$this->joinTable\"");
|
$query = new SQLDelete("\"{$this->joinTable}\"");
|
||||||
|
|
||||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||||
$query->setWhere($filter);
|
$query->setWhere($filter);
|
||||||
@ -283,7 +307,7 @@ class ManyManyList extends RelationList {
|
|||||||
user_error("Can't call ManyManyList::remove() until a foreign ID is set", E_USER_WARNING);
|
user_error("Can't call ManyManyList::remove() until a foreign ID is set", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->addWhere(array("\"$this->localKey\"" => $itemID));
|
$query->addWhere(array("\"{$this->localKey}\"" => $itemID));
|
||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +326,7 @@ class ManyManyList extends RelationList {
|
|||||||
$query->removeFilterOn($foreignFilter);
|
$query->removeFilterOn($foreignFilter);
|
||||||
|
|
||||||
$selectQuery = $query->query();
|
$selectQuery = $query->query();
|
||||||
$selectQuery->setSelect("\"$base\".\"ID\"");
|
$selectQuery->setSelect("\"{$base}\".\"ID\"");
|
||||||
|
|
||||||
$from = $selectQuery->getFrom();
|
$from = $selectQuery->getFrom();
|
||||||
unset($from[$this->joinTable]);
|
unset($from[$this->joinTable]);
|
||||||
@ -313,11 +337,11 @@ class ManyManyList extends RelationList {
|
|||||||
// Use a sub-query as SQLite does not support setting delete targets in
|
// Use a sub-query as SQLite does not support setting delete targets in
|
||||||
// joined queries.
|
// joined queries.
|
||||||
$delete = new SQLDelete();
|
$delete = new SQLDelete();
|
||||||
$delete->setFrom("\"$this->joinTable\"");
|
$delete->setFrom("\"{$this->joinTable}\"");
|
||||||
$delete->addWhere($this->foreignIDFilter());
|
$delete->addWhere($this->foreignIDFilter());
|
||||||
$subSelect = $selectQuery->sql($parameters);
|
$subSelect = $selectQuery->sql($parameters);
|
||||||
$delete->addWhere(array(
|
$delete->addWhere(array(
|
||||||
"\"$this->joinTable\".\"$this->localKey\" IN ($subSelect)" => $parameters
|
"\"{$this->joinTable}\".\"{$this->localKey}\" IN ($subSelect)" => $parameters
|
||||||
));
|
));
|
||||||
$delete->execute();
|
$delete->execute();
|
||||||
}
|
}
|
||||||
@ -341,13 +365,13 @@ class ManyManyList extends RelationList {
|
|||||||
// @todo Optimize into a single query instead of one per extra field
|
// @todo Optimize into a single query instead of one per extra field
|
||||||
if($this->extraFields) {
|
if($this->extraFields) {
|
||||||
foreach($this->extraFields as $fieldName => $dbFieldSpec) {
|
foreach($this->extraFields as $fieldName => $dbFieldSpec) {
|
||||||
$query = new SQLSelect("\"$fieldName\"", "\"$this->joinTable\"");
|
$query = new SQLSelect("\"{$fieldName}\"", "\"{$this->joinTable}\"");
|
||||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||||
$query->setWhere($filter);
|
$query->setWhere($filter);
|
||||||
} else {
|
} else {
|
||||||
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
|
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
$query->addWhere("\"$this->localKey\" = {$itemID}");
|
$query->addWhere("\"{$this->localKey}\" = {$itemID}");
|
||||||
$result[$fieldName] = $query->execute()->value();
|
$result[$fieldName] = $query->execute()->value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,16 +130,17 @@ abstract class DBSchemaManager {
|
|||||||
|
|
||||||
// End schema update
|
// End schema update
|
||||||
foreach ($this->schemaUpdateTransaction as $tableName => $changes) {
|
foreach ($this->schemaUpdateTransaction as $tableName => $changes) {
|
||||||
|
$advancedOptions = isset($changes['advancedOptions']) ? $changes['advancedOptions'] : null;
|
||||||
switch ($changes['command']) {
|
switch ($changes['command']) {
|
||||||
case 'create':
|
case 'create':
|
||||||
$this->createTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
$this->createTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
||||||
$changes['options'], @$changes['advancedOptions']);
|
$changes['options'], $advancedOptions);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'alter':
|
case 'alter':
|
||||||
$this->alterTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
$this->alterTable($tableName, $changes['newFields'], $changes['newIndexes'],
|
||||||
$changes['alteredFields'], $changes['alteredIndexes'],
|
$changes['alteredFields'], $changes['alteredIndexes'],
|
||||||
$changes['alteredOptions'], @$changes['advancedOptions']);
|
$changes['alteredOptions'], $advancedOptions);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,10 +54,10 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Sets the list of tables to query from or update
|
* Sets the list of tables to query from or update
|
||||||
*
|
*
|
||||||
* @example $query->setFrom("MyTable"); // SELECT * FROM MyTable
|
* @example $query->setFrom('"MyTable"'); // SELECT * FROM "MyTable"
|
||||||
*
|
*
|
||||||
* @param string|array $from Escaped SQL statement, usually an unquoted table name
|
* @param string|array $from Single, or list of, ANSI quoted table names
|
||||||
* @return SQLSelect
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setFrom($from) {
|
public function setFrom($from) {
|
||||||
$this->from = array();
|
$this->from = array();
|
||||||
@ -75,9 +75,9 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Add a table to include in the query or update
|
* Add a table to include in the query or update
|
||||||
*
|
*
|
||||||
* @example $query->addFrom("MyTable"); // UPDATE MyTable
|
* @example $query->addFrom('"MyTable"'); // SELECT * FROM "MyTable"
|
||||||
*
|
*
|
||||||
* @param string|array $from Escaped SQL statement, usually an unquoted table name
|
* @param string|array $from Single, or list of, ANSI quoted table names
|
||||||
* @return self Self reference
|
* @return self Self reference
|
||||||
*/
|
*/
|
||||||
public function addFrom($from) {
|
public function addFrom($from) {
|
||||||
@ -189,7 +189,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Add an additional filter (part of the ON clause) on a join.
|
* Add an additional filter (part of the ON clause) on a join.
|
||||||
*
|
*
|
||||||
* @param string $table Table to join on from the original join
|
* @param string $table Table to join on from the original join (unquoted)
|
||||||
* @param string $filter The "ON" SQL fragment (escaped)
|
* @param string $filter The "ON" SQL fragment (escaped)
|
||||||
* @return self Self reference
|
* @return self Self reference
|
||||||
*/
|
*/
|
||||||
@ -201,7 +201,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Set the filter (part of the ON clause) on a join.
|
* Set the filter (part of the ON clause) on a join.
|
||||||
*
|
*
|
||||||
* @param string $table Table to join on from the original join
|
* @param string $table Table to join on from the original join (unquoted)
|
||||||
* @param string $filter The "ON" SQL fragment (escaped)
|
* @param string $filter The "ON" SQL fragment (escaped)
|
||||||
* @return self Self reference
|
* @return self Self reference
|
||||||
*/
|
*/
|
||||||
@ -213,6 +213,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
|||||||
/**
|
/**
|
||||||
* Returns true if we are already joining to the given table alias
|
* Returns true if we are already joining to the given table alias
|
||||||
*
|
*
|
||||||
|
* @param string $tableAlias Table name
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isJoinedTo($tableAlias) {
|
public function isJoinedTo($tableAlias) {
|
||||||
|
@ -23,6 +23,7 @@ class SQLDelete extends SQLConditionalExpression {
|
|||||||
* Construct a new SQLDelete.
|
* Construct a new SQLDelete.
|
||||||
*
|
*
|
||||||
* @param array|string $from An array of Tables (FROM clauses). The first one should be just the table name.
|
* @param array|string $from An array of Tables (FROM clauses). The first one should be just the table name.
|
||||||
|
* Each should be ANSI quoted.
|
||||||
* @param array $where An array of WHERE clauses.
|
* @param array $where An array of WHERE clauses.
|
||||||
* @param array|string $delete The table(s) to delete, if multiple tables are queried from
|
* @param array|string $delete The table(s) to delete, if multiple tables are queried from
|
||||||
* @return self Self reference
|
* @return self Self reference
|
||||||
@ -35,6 +36,7 @@ class SQLDelete extends SQLConditionalExpression {
|
|||||||
* Construct a new SQLDelete.
|
* Construct a new SQLDelete.
|
||||||
*
|
*
|
||||||
* @param array|string $from An array of Tables (FROM clauses). The first one should be just the table name.
|
* @param array|string $from An array of Tables (FROM clauses). The first one should be just the table name.
|
||||||
|
* Each should be ANSI quoted.
|
||||||
* @param array $where An array of WHERE clauses.
|
* @param array $where An array of WHERE clauses.
|
||||||
* @param array|string $delete The table(s) to delete, if multiple tables are queried from
|
* @param array|string $delete The table(s) to delete, if multiple tables are queried from
|
||||||
*/
|
*/
|
||||||
|
@ -26,7 +26,7 @@ class SQLInsert extends SQLExpression implements SQLWriteExpression {
|
|||||||
/**
|
/**
|
||||||
* Construct a new SQLInsert object
|
* Construct a new SQLInsert object
|
||||||
*
|
*
|
||||||
* @param string $into Table name to insert into
|
* @param string $into Table name to insert into (ANSI quoted)
|
||||||
* @param array $assignments List of column assignments
|
* @param array $assignments List of column assignments
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
@ -37,7 +37,7 @@ class SQLInsert extends SQLExpression implements SQLWriteExpression {
|
|||||||
/**
|
/**
|
||||||
* Construct a new SQLInsert object
|
* Construct a new SQLInsert object
|
||||||
*
|
*
|
||||||
* @param string $into Table name to insert into
|
* @param string $into Table name to insert into (ANSI quoted)
|
||||||
* @param array $assignments List of column assignments
|
* @param array $assignments List of column assignments
|
||||||
*/
|
*/
|
||||||
function __construct($into = null, $assignments = array()) {
|
function __construct($into = null, $assignments = array()) {
|
||||||
@ -50,7 +50,7 @@ class SQLInsert extends SQLExpression implements SQLWriteExpression {
|
|||||||
/**
|
/**
|
||||||
* Sets the table name to insert into
|
* Sets the table name to insert into
|
||||||
*
|
*
|
||||||
* @param string $into Single table name
|
* @param string $into Single table name (ANSI quoted)
|
||||||
* @return self The self reference to this query
|
* @return self The self reference to this query
|
||||||
*/
|
*/
|
||||||
public function setInto($into) {
|
public function setInto($into) {
|
||||||
|
@ -63,6 +63,7 @@ class SQLSelect extends SQLConditionalExpression {
|
|||||||
*
|
*
|
||||||
* @param array $select An array of SELECT fields.
|
* @param array $select An array of SELECT fields.
|
||||||
* @param array|string $from An array of FROM clauses. The first one should be just the table name.
|
* @param array|string $from An array of FROM clauses. The first one should be just the table name.
|
||||||
|
* Each should be ANSI quoted.
|
||||||
* @param array $where An array of WHERE clauses.
|
* @param array $where An array of WHERE clauses.
|
||||||
* @param array $orderby An array ORDER BY clause.
|
* @param array $orderby An array ORDER BY clause.
|
||||||
* @param array $groupby An array of GROUP BY clauses.
|
* @param array $groupby An array of GROUP BY clauses.
|
||||||
@ -80,6 +81,7 @@ class SQLSelect extends SQLConditionalExpression {
|
|||||||
*
|
*
|
||||||
* @param array $select An array of SELECT fields.
|
* @param array $select An array of SELECT fields.
|
||||||
* @param array|string $from An array of FROM clauses. The first one should be just the table name.
|
* @param array|string $from An array of FROM clauses. The first one should be just the table name.
|
||||||
|
* Each should be ANSI quoted.
|
||||||
* @param array $where An array of WHERE clauses.
|
* @param array $where An array of WHERE clauses.
|
||||||
* @param array $orderby An array ORDER BY clause.
|
* @param array $orderby An array ORDER BY clause.
|
||||||
* @param array $groupby An array of GROUP BY clauses.
|
* @param array $groupby An array of GROUP BY clauses.
|
||||||
|
@ -19,7 +19,7 @@ class SQLUpdate extends SQLConditionalExpression implements SQLWriteExpression {
|
|||||||
/**
|
/**
|
||||||
* Construct a new SQLUpdate object
|
* Construct a new SQLUpdate object
|
||||||
*
|
*
|
||||||
* @param string $table Table name to update
|
* @param string $table Table name to update (ANSI quoted)
|
||||||
* @param array $assignment List of column assignments
|
* @param array $assignment List of column assignments
|
||||||
* @param array $where List of where clauses
|
* @param array $where List of where clauses
|
||||||
* @return static
|
* @return static
|
||||||
@ -31,7 +31,7 @@ class SQLUpdate extends SQLConditionalExpression implements SQLWriteExpression {
|
|||||||
/**
|
/**
|
||||||
* Construct a new SQLUpdate object
|
* Construct a new SQLUpdate object
|
||||||
*
|
*
|
||||||
* @param string $table Table name to update
|
* @param string $table Table name to update (ANSI quoted)
|
||||||
* @param array $assignment List of column assignments
|
* @param array $assignment List of column assignments
|
||||||
* @param array $where List of where clauses
|
* @param array $where List of where clauses
|
||||||
*/
|
*/
|
||||||
|
@ -1497,15 +1497,11 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
*/
|
*/
|
||||||
class Member_GroupSet extends ManyManyList {
|
class Member_GroupSet extends ManyManyList {
|
||||||
|
|
||||||
public function __construct($dataClass, $joinTable, $localKey, $foreignKey, $extraFields = array()) {
|
protected function linkJoinTable() {
|
||||||
|
// Do not join the table directly
|
||||||
// Bypass the many-many constructor
|
if($this->extraFields) {
|
||||||
DataList::__construct($dataClass);
|
user_error('Member_GroupSet does not support many_many_extraFields', E_USER_ERROR);
|
||||||
|
}
|
||||||
$this->joinTable = $joinTable;
|
|
||||||
$this->localKey = $localKey;
|
|
||||||
$this->foreignKey = $foreignKey;
|
|
||||||
$this->extraFields = $extraFields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -937,6 +937,9 @@ class Security extends Controller implements TemplateGlobalProvider {
|
|||||||
$requiredTables[] = 'Permission';
|
$requiredTables[] = 'Permission';
|
||||||
|
|
||||||
foreach($requiredTables as $table) {
|
foreach($requiredTables as $table) {
|
||||||
|
// Skip test classes, as not all test classes are scaffolded at once
|
||||||
|
if(is_subclass_of($table, 'TestOnly')) continue;
|
||||||
|
|
||||||
// if any of the tables aren't created in the database
|
// if any of the tables aren't created in the database
|
||||||
if(!ClassInfo::hasTable($table)) return false;
|
if(!ClassInfo::hasTable($table)) return false;
|
||||||
|
|
||||||
|
@ -253,8 +253,8 @@ class ManyManyListTest extends SapphireTest {
|
|||||||
$db = DB::getConn();
|
$db = DB::getConn();
|
||||||
$expected = 'SELECT DISTINCT "ManyManyListTest_ExtraFields_Clients"."WorthCurrency",'
|
$expected = 'SELECT DISTINCT "ManyManyListTest_ExtraFields_Clients"."WorthCurrency",'
|
||||||
.' "ManyManyListTest_ExtraFields_Clients"."WorthAmount", "ManyManyListTest_ExtraFields_Clients"."Reference",'
|
.' "ManyManyListTest_ExtraFields_Clients"."WorthAmount", "ManyManyListTest_ExtraFields_Clients"."Reference",'
|
||||||
.' "ManyManyListTest_ExtraFields"."ClassName", "ManyManyListTest_ExtraFields"."Created",'
|
.' "ManyManyListTest_ExtraFields"."ClassName", "ManyManyListTest_ExtraFields"."LastEdited",'
|
||||||
.' "ManyManyListTest_ExtraFields"."LastEdited", "ManyManyListTest_ExtraFields"."ID",'
|
.' "ManyManyListTest_ExtraFields"."Created", "ManyManyListTest_ExtraFields"."ID",'
|
||||||
.' CASE WHEN "ManyManyListTest_ExtraFields"."ClassName" IS NOT NULL THEN'
|
.' CASE WHEN "ManyManyListTest_ExtraFields"."ClassName" IS NOT NULL THEN'
|
||||||
.' "ManyManyListTest_ExtraFields"."ClassName" ELSE '. $db->prepStringForDB('ManyManyListTest_ExtraFields')
|
.' "ManyManyListTest_ExtraFields"."ClassName" ELSE '. $db->prepStringForDB('ManyManyListTest_ExtraFields')
|
||||||
.' END AS "RecordClassName" FROM "ManyManyListTest_ExtraFields" INNER JOIN'
|
.' END AS "RecordClassName" FROM "ManyManyListTest_ExtraFields" INNER JOIN'
|
||||||
@ -262,7 +262,7 @@ class ManyManyListTest extends SapphireTest {
|
|||||||
.' "ManyManyListTest_ExtraFields_Clients"."ManyManyListTest_ExtraFieldsID" ='
|
.' "ManyManyListTest_ExtraFields_Clients"."ManyManyListTest_ExtraFieldsID" ='
|
||||||
.' "ManyManyListTest_ExtraFields"."ID"';
|
.' "ManyManyListTest_ExtraFields"."ID"';
|
||||||
|
|
||||||
$this->assertEquals($expected, $list->sql());
|
$this->assertSQLEquals($expected, $list->sql($parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user