Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lib/Spot/Adapter/Mysql.php #13

Closed
wants to merge 1 commit into from
Closed

Update lib/Spot/Adapter/Mysql.php #13

wants to merge 1 commit into from

Conversation

stanislas-m
Copy link

The use of array_merge() in migrateSyntaxFieldCreate() erase the fieldTypeMap pre-sets. That's cool if the new value isn't empty...
With this fix, it's possible to keep the pre-set value if the new one is empty.

The use of array_merge() in migrateSyntaxFieldCreate() erase the fieldTypeMap pre-sets. That's cool if the new value isn't empty...
With this fix, it's possible to keep the pre-sets values if the new one is empty.
@stanislas-m
Copy link
Author

In fact, the first addition return the merge of the two arrays, but the empty keys are deleted. Adding them again allows to re-add that keys. For instance, with two given arrays :

$a = array(
'key1' => 1,
'key2' => '',
'key3' => 2,
'key4' => ''
);
$b = array(
'key1' => '',
'key3' => 10,
'key4' => 4
);
//Then
$a + $b == array(
'key1' => 1,
'key2' => '',
'key3' => 2,
'key4' => ''
);

array_filter($a) + array_filter($b) == array(
'key1' => 1,
'key3' => 2,
'key4' => 4
);

array_filter($a) + array_filter($b) + $a + $b == array(
'key1' => 1,
'key2' => '',
'key3' => 2,
'key4' => 4
);

//Instead of :
array_merge($b, $a) == array(
'key1' => 1,
'key2' => '',
'key3' => 2,
'key4' => ''
);

@stanislas-m
Copy link
Author

By the way, I made a mistake in my commit, the order of the first parameters is reversed :

$fieldInfo = array_filter($fieldInfo) + array_filter($this->_fieldTypeMap[$fieldInfo['type']]) + $this->_fieldTypeMap[$fieldInfo['type']] + $fieldInfo;

instead of :

$fieldInfo = array_filter($this->_fieldTypeMap[$fieldInfo['type']]) + array_filter($fieldInfo) + $this->_fieldTypeMap[$fieldInfo['type']] + $fieldInfo;

@vlucas
Copy link
Owner

vlucas commented Sep 29, 2012

Sorry this hasn't been merged yet - I have not had a chance to test it. Can you give me a scenario that I can test for this bug you found and the code you have? How did you come across this bug and can you provide a little sample code to reproduce it? I want to get this patched in, but to do that I need to write a test for it so this won't regress later.

@stanislas-m
Copy link
Author

If my memory serves me right, it can be reproduced by using an email or a password field when you create the fields list in an entity. Try to get the content of the $fieldInfo var with that kind of field, and you'll find the issue.

By the way, in the Query class: if you try to get any field, you MUST use the following syntax : 'field1,field2...'. Then, if you want to use a space behind the comma (field1, field2...), it won't work anymore. Try to display the generated SQL code to see the issue ;)

@stanislas-m stanislas-m closed this Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants