diff --git a/src/Dev/Tasks/MigrateFileTask.php b/src/Dev/Tasks/MigrateFileTask.php index 2d552be3b..c8a1c9fa3 100644 --- a/src/Dev/Tasks/MigrateFileTask.php +++ b/src/Dev/Tasks/MigrateFileTask.php @@ -104,8 +104,6 @@ class MigrateFileTask extends BuildTask ImageThumbnailHelper::singleton()->run(); $this->extend('postFileMigrationSubtask', $subtask); } - - } $subtask = 'fix-folder-permissions'; @@ -145,6 +143,8 @@ class MigrateFileTask extends BuildTask } $this->extend('postFileMigration'); + + $this->logger->info("Done!"); } public function getDescription() diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php index c0920fa7b..94721475e 100644 --- a/src/Forms/FormField.php +++ b/src/Forms/FormField.php @@ -1621,9 +1621,11 @@ class FormField extends RequestHandler */ public function getSchemaValidation() { + $validationList = []; if ($this->Required()) { - return [ 'required' => true ]; + $validationList['required'] = true; } - return []; + $this->extend('updateSchemaValidation', $validationList); + return $validationList; } } diff --git a/src/Forms/HeaderField.php b/src/Forms/HeaderField.php index d350d41f5..52c260fb4 100644 --- a/src/Forms/HeaderField.php +++ b/src/Forms/HeaderField.php @@ -30,7 +30,7 @@ class HeaderField extends DatalessField * @param string $title * @param int $headingLevel */ - public function __construct($name, $title, $headingLevel = 2) + public function __construct($name, $title = null, $headingLevel = 2) { $this->setHeadingLevel($headingLevel); parent::__construct($name, $title); diff --git a/src/ORM/DataQuery.php b/src/ORM/DataQuery.php index dd21d2bc2..2b4224be7 100644 --- a/src/ORM/DataQuery.php +++ b/src/ORM/DataQuery.php @@ -354,7 +354,6 @@ class DataQuery { if ($orderby = $query->getOrderBy()) { $newOrderby = array(); - $i = 0; foreach ($orderby as $k => $dir) { $newOrderby[$k] = $dir; @@ -372,7 +371,6 @@ class DataQuery if (isset($originalSelect[$col])) { $query->selectField($originalSelect[$col], $col); } - continue; } @@ -402,10 +400,15 @@ class DataQuery if (!in_array($qualCol, $query->getSelect())) { unset($newOrderby[$k]); - $newOrderby["\"_SortColumn$i\""] = $dir; - $query->selectField($qualCol, "_SortColumn$i"); + // Find the first free "_SortColumnX" slot + // and assign it to $key + $i = 0; + while (isset($orderby[$key = "\"_SortColumn$i\""])) { + ++$i; + } - $i++; + $newOrderby[$key] = $dir; + $query->selectField($qualCol, "_SortColumn$i"); } } } diff --git a/tests/php/ORM/DataQueryTest.php b/tests/php/ORM/DataQueryTest.php index ef3a72c96..5a32508f0 100644 --- a/tests/php/ORM/DataQueryTest.php +++ b/tests/php/ORM/DataQueryTest.php @@ -296,6 +296,32 @@ class DataQueryTest extends SapphireTest static::resetDBSchema(true); } + public function testSurrogateFieldSort() + { + $query = new DataQuery(DataQueryTest\ObjectE::class); + $query->sort( + sprintf( + '(case when "Title" = %s then 1 else 0 end)', + DB::get_conn()->quoteString('Second') + ), + 'DESC', + true + ); + $query->sort('SortOrder', 'ASC', false); + $query->sort( + sprintf( + '(case when "Title" = %s then 0 else 1 end)', + DB::get_conn()->quoteString('Fourth') + ), + 'DESC', + false + ); + $this->assertEquals( + $query->execute()->column('Title'), + $query->column('Title') + ); + } + public function testComparisonClauseDateStartsWith() { DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyDate\") VALUES ('1988-03-04 06:30')"); diff --git a/tests/php/ORM/SQLSelectTest.php b/tests/php/ORM/SQLSelectTest.php index 7b36fa335..a97792cfc 100755 --- a/tests/php/ORM/SQLSelectTest.php +++ b/tests/php/ORM/SQLSelectTest.php @@ -854,7 +854,7 @@ class SQLSelectTest extends SapphireTest $sql = $query->sql(); $this->assertSQLEquals( - 'SELECT * FROM "MyTable" AS "MyTableAlias" , '. + 'SELECT * FROM "MyTable" AS "MyTableAlias" , ' . '(SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"', $sql );