mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge branch '1.4'
This commit is contained in:
commit
08ccb15bdb
@ -5,9 +5,9 @@ sudo: false
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=4
|
||||
@ -18,7 +18,9 @@ before_script:
|
||||
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
- composer install
|
||||
- composer install --prefer-dist --no-progress --no-suggest
|
||||
- composer require silverstripe/versioned:1.x-dev --prefer-dist --no-progress --no-suggest
|
||||
- composer dump-autoload --optimize
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit gridfieldextensions/tests
|
||||
|
@ -145,7 +145,12 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
$sanitised = array();
|
||||
foreach($result as $class=>$title) {
|
||||
$sanitised[$this->sanitiseClassName($class)] = $title;
|
||||
}
|
||||
|
||||
return $sanitised;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,11 +201,12 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
throw new HTTPResponse_Exception(400);
|
||||
}
|
||||
|
||||
$unsanitisedClass = $this->unsanitiseClassName($class);
|
||||
$handler = Injector::inst()->create(
|
||||
$this->itemRequestClass,
|
||||
$grid,
|
||||
$component,
|
||||
new $class(),
|
||||
new $unsanitisedClass(),
|
||||
$grid->getForm()->getController(),
|
||||
'add-multi-class'
|
||||
);
|
||||
@ -254,4 +260,20 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
$this->itemRequestClass = $class;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitise a model class' name for inclusion in a link
|
||||
* @return string
|
||||
*/
|
||||
protected function sanitiseClassName($class) {
|
||||
return str_replace('\\', '-', $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsanitise a model class' name from a URL param
|
||||
* @return string
|
||||
*/
|
||||
protected function unsanitiseClassName($class) {
|
||||
return str_replace('-', '\\', $class);
|
||||
}
|
||||
}
|
||||
|
@ -476,8 +476,8 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$current = array();
|
||||
foreach ($items->toArray() as $record) {
|
||||
// NOTE: _SortColumn0 is the first ->sort() field
|
||||
// used by SS when functions are detected in a SELECT
|
||||
// or CASE WHEN.
|
||||
// used by SS when functions are detected in a SELECT
|
||||
// or CASE WHEN.
|
||||
if (isset($record->_SortColumn0)) {
|
||||
$current[$record->ID] = $record->_SortColumn0;
|
||||
} else {
|
||||
@ -514,7 +514,16 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
// match to order the objects.
|
||||
if (!$isVersioned) {
|
||||
$sortTable = $this->getSortTable($list);
|
||||
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
|
||||
$additionalSQL = '';
|
||||
$baseTable = $sortTable;
|
||||
if(class_exists($sortTable)) {
|
||||
$baseTable = singleton($sortTable)->baseTable();
|
||||
}
|
||||
$isBaseTable = ($baseTable == $sortTable);
|
||||
if(!$list instanceof ManyManyList && $isBaseTable){
|
||||
$additionalSQL = ', "LastEdited" = NOW()';
|
||||
}
|
||||
|
||||
foreach ($sortedIDs as $sortValue => $id) {
|
||||
if ($map[$id] != $sortValue) {
|
||||
DB::query(sprintf(
|
||||
@ -525,6 +534,14 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$additionalSQL,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
|
||||
if(!$isBaseTable) {
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
|
||||
$baseTable,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -550,7 +567,16 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$field = $this->getSortField();
|
||||
$table = $this->getSortTable($list);
|
||||
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
|
||||
$additionalSQL = (!$list instanceof ManyManyList) ? ', "LastEdited" = NOW()' : '';
|
||||
|
||||
$additionalSQL = '';
|
||||
$baseTable = $table;
|
||||
if(class_exists($table)) {
|
||||
$baseTable = singleton($table)->baseTable();
|
||||
}
|
||||
$isBaseTable = ($baseTable == $table);
|
||||
if(!$list instanceof ManyManyList && $isBaseTable){
|
||||
$additionalSQL = ', "LastEdited" = NOW()';
|
||||
}
|
||||
|
||||
foreach ($list->where($clause)->column('ID') as $id) {
|
||||
$max = DB::query(sprintf('SELECT MAX("%s") + 1 FROM "%s"', $field, $table));
|
||||
@ -564,6 +590,14 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$additionalSQL,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
|
||||
if(!$isBaseTable) {
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
|
||||
$baseTable,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
66
tests/GridFieldAddNewMultiClassWithNamespacesTest.php
Normal file
66
tests/GridFieldAddNewMultiClassWithNamespacesTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Symbiote\Test;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
|
||||
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler;
|
||||
|
||||
class GridFieldAddNewMultiClassWithNamespacesTest extends SapphireTest {
|
||||
|
||||
public function testGetClassesWithNamespaces() {
|
||||
$grid = new GridField('TestGridField');
|
||||
$grid->setModelClass('Symbiote\\Test\\NamespacedClass');
|
||||
|
||||
$component = new GridFieldAddNewMultiClass();
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'Symbiote-Test-NamespacedClass' => 'NamespacedClass'
|
||||
),
|
||||
$component->getClasses($grid),
|
||||
'Namespaced classes are sanitised'
|
||||
);
|
||||
}
|
||||
|
||||
public function testHandleAddWithNamespaces() {
|
||||
$grid = new GridField('TestGridField');
|
||||
$grid->getConfig()->addComponent(new GridFieldDetailForm());
|
||||
$grid->setModelClass('Symbiote\\Test\\NamespacedClass');
|
||||
$grid->setForm(Form::create(Controller::create(), 'test', FieldList::create(), FieldList::create()));
|
||||
|
||||
$request = new HTTPRequest('POST', 'test');
|
||||
$request->setRouteParams(array('ClassName' => 'Symbiote-Test-NamespacedClass'));
|
||||
|
||||
$component = new GridFieldAddNewMultiClass();
|
||||
$response = $component->handleAdd($grid, $request);
|
||||
|
||||
$record = new \ReflectionProperty(GridFieldAddNewMultiClassHandler::class, 'record');
|
||||
$record->setAccessible(true);
|
||||
$this->assertInstanceOf('Symbiote\\Test\\NamespacedClass', $record->getValue($response));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @ignore
|
||||
*/
|
||||
|
||||
class NamespacedClass implements TestOnly {
|
||||
public function i18n_singular_name() {
|
||||
return 'NamespacedClass';
|
||||
}
|
||||
|
||||
public function canCreate() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
Loading…
Reference in New Issue
Block a user