Skip to content

Commit

Permalink
Merge branch '3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Jul 14, 2016
2 parents 6e68f38 + 4c40cf8 commit d19955a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
3 changes: 2 additions & 1 deletion ORM/ArrayList.php
Expand Up @@ -362,7 +362,8 @@ protected function parseSortColumn($column, $direction = null) {
}

// 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'];
if(empty($direction) && !empty($match['direction'])) {
$direction = $match['direction'];
Expand Down
35 changes: 25 additions & 10 deletions ORM/Connect/Database.php
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\ORM\Queries\SQLInsert;
use SilverStripe\ORM\Queries\SQLExpression;
use Config;

/**
* Abstract database connectivity class.
Expand All @@ -27,6 +28,15 @@ abstract class SS_Database {
*/
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.
*
Expand Down Expand Up @@ -713,18 +723,23 @@ public function databaseList() {
* @return boolean Flag indicating success
*/
public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) {
if (!$this->schemaManager->databaseExists($name)) {
// Check DB creation permisson
if (!$create) {
if ($errorLevel !== false) {
user_error("Attempted to connect to non-existing database \"$name\"", $errorLevel);
}
// Unselect database
$this->connector->unloadDatabase();
return false;
// 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
if (!$create) {
if ($errorLevel !== false) {
user_error("Attempted to connect to non-existing database \"$name\"", $errorLevel);
}
$this->schemaManager->createDatabase($name);
// Unselect database
$this->connector->unloadDatabase();
return false;
}
$this->schemaManager->createDatabase($name);
return $this->connector->selectDatabase($name);
}

Expand Down
4 changes: 2 additions & 2 deletions docs/en/02_Developer_Guides/03_Forms/06_Tabbed_Forms.md
Expand Up @@ -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

:::php
$field = $fields->dataFieldByName('Content');
$content = $fields->dataFieldByName('Content');

$fields->removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root.MyContent', $content);
Expand All @@ -52,4 +52,4 @@ display up to two levels of tabs in the interface. If you want to group data fur

## API Documentation

* [api:FormScaffolder]
* [api:FormScaffolder]
24 changes: 24 additions & 0 deletions tests/model/ArrayListTest.php
Expand Up @@ -282,6 +282,30 @@ public function testSortSimpleDefaultIsSortedASC() {
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
$this->assertEquals($list->toArray(), array(
array('Name' => 'Steve'),
Expand Down

0 comments on commit d19955a

Please sign in to comment.