Merge branch '3.4' into 3

This commit is contained in:
Daniel Hensby 2016-09-14 11:40:15 +01:00
commit a9df28c791
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
6 changed files with 64 additions and 22 deletions

3
.gitattributes vendored
View File

@ -1 +1,4 @@
docs/ export-ignore
# Line endings
sake text eol=lf

View File

@ -131,29 +131,48 @@ class FixtureBlueprint {
// Populate all relations
if($data) foreach($data as $fieldName => $fieldVal) {
if($obj->manyManyComponent($fieldName) || $obj->hasManyComponent($fieldName)) {
$isManyMany = $obj->manyManyComponent($fieldName);
$isHasMany = $obj->hasManyComponent($fieldName);
if ($isManyMany && $isHasMany) {
throw new InvalidArgumentException("$fieldName is both many_many and has_many");
}
if($isManyMany || $isHasMany) {
$obj->write();
$parsedItems = array();
if(is_array($fieldVal)) {
// Many many components need a little extra work to extract extrafields
if(is_array($fieldVal) && $isManyMany) {
// handle lists of many_many relations. Each item can
// specify the many_many_extraFields against each
// related item.
foreach($fieldVal as $relVal) {
$item = key($relVal);
// Check for many_many_extrafields
$extrafields = array();
if (is_array($relVal)) {
// Item is either first row, or key in yet another nested array
$item = key($relVal);
if (is_array($relVal[$item]) && count($relVal) === 1) {
// Extra fields from nested array
$extrafields = $relVal[$item];
} else {
// Extra fields from subsequent items
array_shift($relVal);
$extrafields = $relVal;
}
} else {
$item = $relVal;
}
$id = $this->parseValue($item, $fixtures);
$parsedItems[] = $id;
array_shift($relVal);
$obj->getManyManyComponents($fieldName)->add(
$id, $relVal
$id, $extrafields
);
}
} else {
$items = preg_split('/ *, */',trim($fieldVal));
$items = is_array($fieldVal)
? $fieldVal
: preg_split('/ *, */',trim($fieldVal));
$parsedItems = array();
foreach($items as $item) {
// Check for correct format: =><relationname>.<identifier>.
// Ignore if the item has already been replaced with a numeric DB identifier
@ -169,9 +188,9 @@ class FixtureBlueprint {
$parsedItems[] = $this->parseValue($item, $fixtures);
}
if($obj->hasManyComponent($fieldName)) {
if($isHasMany) {
$obj->getComponents($fieldName)->setByIDList($parsedItems);
} elseif($obj->manyManyComponent($fieldName)) {
} elseif($isManyMany) {
$obj->getManyManyComponents($fieldName)->setByIDList($parsedItems);
}
}

View File

@ -11,15 +11,7 @@ We also have separate instructions for [installing modules with Composer](/devel
Before installing Composer you should ensure your system has the version control system, [Git installed](http://git-scm.com/book/en/v2/Getting-Started-Installing-Git). Composer uses Git to check out the code dependancies you need to run your SilverStripe CMS website from the code repositories maintained on GitHub.
Next, to install Composer, run the following commands from your command-line.
# Download composer.phar
curl -s https://getcomposer.org/installer | php
# Move to your path
sudo mv composer.phar /usr/local/bin/composer
Or [download composer.phar](http://getcomposer.org/composer.phar) manually, and rename `composer.phar` as `composer`, and put it in your path. On Windows, you should call the file `composer.bat`.
Next, [install composer](https://getcomposer.org/download/). For our documentation we assume composer is installed globally.
You can then run Composer commands by calling `composer`. For example:

View File

@ -109,6 +109,26 @@ class FixtureBlueprintTest extends SapphireTest {
$this->assertEquals(2, $obj->ManyManyRelation()->Count());
$this->assertNotNull($obj->ManyManyRelation()->find('ID', $relation1->ID));
$this->assertNotNull($obj->ManyManyRelation()->find('ID', $relation2->ID));
$obj2 = $blueprint->createObject(
'two',
array(
// Note; using array format here, not comma separated
'HasManyRelation' => array(
'=>FixtureFactoryTest_DataObjectRelation.relation1',
'=>FixtureFactoryTest_DataObjectRelation.relation2'
)
),
array(
'FixtureFactoryTest_DataObjectRelation' => array(
'relation1' => $relation1->ID,
'relation2' => $relation2->ID
)
)
);
$this->assertEquals(2, $obj2->HasManyRelation()->Count());
$this->assertNotNull($obj2->HasManyRelation()->find('ID', $relation1->ID));
$this->assertNotNull($obj2->HasManyRelation()->find('ID', $relation2->ID));
}
/**

View File

@ -162,6 +162,10 @@ class FixtureFactoryTest_DataObject extends DataObject implements TestOnly {
"Name" => "Varchar"
);
private static $has_many = array(
"HasManyRelation" => "FixtureFactoryTest_DataObjectRelation"
);
private static $many_many = array(
"ManyManyRelation" => "FixtureFactoryTest_DataObjectRelation"
);
@ -186,4 +190,8 @@ class FixtureFactoryTest_DataObjectRelation extends DataObject implements TestOn
private static $belongs_many_many = array(
"TestParent" => "FixtureFactoryTest_DataObject"
);
private static $has_one = array(
'MyParent' => 'FixtureFactoryTest_DataObject'
);
}

View File

@ -426,7 +426,7 @@ class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly
);
private static $belongs_many_many = array(
'People' => 'GridFieldDetailFormTest_Person'
'FavouritePeople' => 'GridFieldDetailFormTest_Person'
);
private static $default_sort = '"Name"';