Merge branch '3'

This commit is contained in:
Daniel Hensby 2016-07-14 14:05:18 +01:00
commit d19955afc8
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 54 additions and 14 deletions

View File

@ -362,7 +362,8 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
} }
// Parse column specification, considering possible ansi sql quoting // Parse column specification, considering possible ansi sql quoting
if(preg_match('/^"?(?<column>[^"\s]+)"?(\s+(?<direction>((asc)|(desc))(ending)?))?$/i', $column, $match)) { // Note that table prefix is allowed, but discarded
if(preg_match('/^("?(?<table>[^"\s]+)"?\\.)?"?(?<column>[^"\s]+)"?(\s+(?<direction>((asc)|(desc))(ending)?))?$/i', $column, $match)) {
$column = $match['column']; $column = $match['column'];
if(empty($direction) && !empty($match['direction'])) { if(empty($direction) && !empty($match['direction'])) {
$direction = $match['direction']; $direction = $match['direction'];

View File

@ -10,6 +10,7 @@ use Deprecation;
use SilverStripe\ORM\Queries\SQLUpdate; use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\ORM\Queries\SQLInsert; use SilverStripe\ORM\Queries\SQLInsert;
use SilverStripe\ORM\Queries\SQLExpression; use SilverStripe\ORM\Queries\SQLExpression;
use Config;
/** /**
* Abstract database connectivity class. * Abstract database connectivity class.
@ -27,6 +28,15 @@ abstract class SS_Database {
*/ */
protected $connector = null; protected $connector = null;
/**
* In cases where your environment does not have 'SHOW DATABASES' permission,
* you can set this to true. Then selectDatabase() will always connect without
* doing databaseExists() check.
*
* @var bool
*/
private static $optimistic_connect = false;
/** /**
* Amount of queries executed, for debugging purposes. * Amount of queries executed, for debugging purposes.
* *
@ -713,7 +723,13 @@ abstract class SS_Database {
* @return boolean Flag indicating success * @return boolean Flag indicating success
*/ */
public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) { public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) {
if (!$this->schemaManager->databaseExists($name)) { // In case our live environment is locked down, we can bypass a SHOW DATABASE check
$canConnect = Config::inst()->get(get_class($this), 'optimistic_connect')
|| $this->schemaManager->databaseExists($name);
if($canConnect) {
return $this->connector->selectDatabase($name);
}
// Check DB creation permisson // Check DB creation permisson
if (!$create) { if (!$create) {
if ($errorLevel !== false) { if ($errorLevel !== false) {
@ -724,7 +740,6 @@ abstract class SS_Database {
return false; return false;
} }
$this->schemaManager->createDatabase($name); $this->schemaManager->createDatabase($name);
}
return $this->connector->selectDatabase($name); return $this->connector->selectDatabase($name);
} }

View File

@ -37,7 +37,7 @@ display up to two levels of tabs in the interface. If you want to group data fur
## Moving a field between tabs ## Moving a field between tabs
:::php :::php
$field = $fields->dataFieldByName('Content'); $content = $fields->dataFieldByName('Content');
$fields->removeFieldFromTab('Root.Main', 'Content'); $fields->removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root.MyContent', $content); $fields->addFieldToTab('Root.MyContent', $content);

View File

@ -282,6 +282,30 @@ class ArrayListTest extends SapphireTest {
array('Name' => 'Steve') array('Name' => 'Steve')
)); ));
// Quoted name name with table
$list4 = $list->sort('"Record"."Name"');
$this->assertEquals($list4->toArray(), array(
(object) array('Name' => 'Bob'),
array('Name' => 'John'),
array('Name' => 'Steve')
));
// Quoted name name with table (desc)
$list5 = $list->sort('"Record"."Name" DESC');
$this->assertEquals($list5->toArray(), array(
array('Name' => 'Steve'),
array('Name' => 'John'),
(object) array('Name' => 'Bob')
));
// Table without quotes
$list6 = $list->sort('Record.Name');
$this->assertEquals($list6->toArray(), array(
(object) array('Name' => 'Bob'),
array('Name' => 'John'),
array('Name' => 'Steve')
));
// Check original list isn't altered // Check original list isn't altered
$this->assertEquals($list->toArray(), array( $this->assertEquals($list->toArray(), array(
array('Name' => 'Steve'), array('Name' => 'Steve'),