ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: radu81 on February 28, 2016, 05:09:13 pm

Title: Small bug in search members with dropdown custom fields
Post by: radu81 on February 28, 2016, 05:09:13 pm
At some point in Elkarte was addes the option to search user based on a  custom field wich can be a dropdown field. This is working great but I noticed a couple of errors in my log

(http://i.imgur.com/N4znfFa.png)

In the image above I searched for members based on field "Provincia" which should be province in english. It works, but if I click on "Provincia" or "Regione" fields (see the 2 red arrows) I get a database error:

(http://i.imgur.com/b6N6SLD.png)

Not a big bug, bud would be better if solved. ;)
Title: Re: Small bug in search members with dropdown custom fields
Post by: Flavio93Zena on February 28, 2016, 05:12:04 pm
Did you update Elkarte up to 1.0.6 correctly? I am not sure about the patch notes, but it says your database version is still 1.0.2 #_#
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on February 28, 2016, 05:28:28 pm
I use the latest version:

(http://i.imgur.com/v8m5SxX.png)
Title: Re: Small bug in search members with dropdown custom fields
Post by: Flavio93Zena on February 28, 2016, 05:29:45 pm
It's weird, it says your database version is 1.0.4 and it claims it's updated to the most recent one, however the error says you are still running 1.0.2 database. I think we need one of the big guys here.
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on February 28, 2016, 06:57:26 pm
Yep, indeed something broken.
That's a... I'm not if calling it a fix is right, or maybe workaround sounds better, though it seems to work on few testings (I don't think it's particularly elegant though).

The file is sources/controllers/Memberlist.controller.php.
After:
Code: [Select]
$input_fields = isset($this->_req->query->fields) ? explode(',', $this->_req->query->fields) : $this->_req->post->fields;
add:
Code: [Select]
			if (isset($context['columns'][$sort]))
$input_fields[] = $sort;

before (or after, it doesn't matter):
Code: [Select]
$context['old_search_value'] = $search;
add:
Code: [Select]
			$input_fields = array_unique($input_fields);

and finally, replace:
Code: [Select]
					$customJoin[] = 'LEFT JOIN {db_prefix}custom_fields_data AS cfd' . $curField . ' ON (cfd' . $curField . '.variable = {string:cfd' . $curField . '} AND cfd' . $curField . '.id_member = mem.id_member)';
$query_parameters['cfd' . $curField] = $curField;
$fields += array($customCount++ => 'IFNULL(cfd' . $curField . '.value, {string:blank_string})');
with:
Code: [Select]
					$customJoin[] = 'LEFT JOIN {db_prefix}custom_fields_data AS cfd' . $field . ' ON (cfd' . $field . '.variable = {string:cfd' . $field . '} AND cfd' . $field . '.id_member = mem.id_member)';
$query_parameters['cfd' . $field] = $curField;
$fields += array($customCount++ => 'IFNULL(cfd' . $field . '.value, {string:blank_string})');

that should do.
Title: Re: Small bug in search members with dropdown custom fields
Post by: Flavio93Zena on February 28, 2016, 07:07:42 pm
What about that database version discrepancy? Can it be a problem? Is it known or just a false trigger or else? I remember something similar on smf, can't recall the details...
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on February 28, 2016, 07:24:44 pm
Irrelevant. (Like in the other 99.9% of the times.)
Title: Re: Small bug in search members with dropdown custom fields
Post by: Flavio93Zena on February 28, 2016, 07:58:48 pm
Good to know, thanks :)
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on February 29, 2016, 04:58:09 pm
Quote from: emanuele – The file is sources/controllers/Memberlist.controller.php.
After:
Code: [Select]
$input_fields = isset($this->_req->query->fields) ? explode(',', $this->_req->query->fields) : $this->_req->post->fields;
add:

Probably there is something wrong with my Memberlist.controller.php, but I have:
Code: [Select]
$input_fields = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on February 29, 2016, 05:08:28 pm
Ouch!!
Sorry, I was looking at the 1.1 files...
The line is the one you posted. All the others should be the same.
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on February 29, 2016, 05:41:59 pm
Well that worked for field province, but if I click on the other one "Region" I still get an error. I am wondering if a sort option has really sense in this case

Code: [Select]
Unknown column 'cfdcust_cust_region.value' in 'order clause'
File: /.../sources/subs/Memberlist.subs.php
Riga: 261

Nota: la versione del tuo database è 1.0.2.
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 01, 2016, 02:38:53 am
O_o

Is there any difference between the two fields? (Type mainly.)
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 01, 2016, 03:27:11 am
they are both dropdown fields, what I wonder if a sorting option is really useful in this case
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 01, 2016, 03:32:22 am
I'd say yes.
Not in most of the possible custom fields but for some it would indeed be useful. Regioni e province to me is a good example of potentially useful sorting: that allows you to group them (yeah, okay, you could just search :P).
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 01, 2016, 09:11:37 am
I keep forgetting that 1.1 is slightly different in many places...
Move this code:
Code: [Select]
			// Set defaults for how the results are sorted
if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
$_REQUEST['sort'] = 'real_name';
just after:
Code: [Select]
		// They're searching..
if (isset($_REQUEST['search']) && isset($_REQUEST['fields']))
{

move in the sense that the piece of code is present few lines below, remove it from there and move it up.
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 02, 2016, 06:32:40 pm
I did that edit but I still got an error (I searched for field "RE" into "Provincia", I click on the other dropdown field "Regione")

Code: [Select]
Unknown column 'cfdcust_cust_region.value' in 'order clause'
File: ../sources/subs/Memberlist.subs.php
Riga: 261

Nota: la versione del tuo database è 1.0.2.
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 03, 2016, 02:19:35 am
Stop finding bugs!!!! :P
I imagined something like this may happen, but hoped not... well it seems I really have to find a proper fix... O:-)
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 03, 2016, 03:27:41 am
I can live with this, I only found 2 errors in my log in a few months, if is solved into 1.1 version and require time to fix into 1.0.x there is no problem for me to wait the new release ;)
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 03, 2016, 04:03:00 am
I'm joking of course, this should be solved in 1.0.7, not later. ;)
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 04:49:11 am
I forgot to post it here, the correct fix is https://github.com/emanuele45/Dialogo/commit/c4740db0f32e56483bc948a5320f0aca7a5d97b2

So if you want to test it out, revert the changes I suggested and apply just these two:
Code: (find) [Select]
foreach ($input_fields as $field)
Code: (replace with) [Select]
foreach (array_keys($this->_search_fields) as $field)
and:
Code: (find) [Select]
					$customJoin[] = 'LEFT JOIN {db_prefix}custom_fields_data AS cfd' . $curField . ' ON (cfd' . $curField . '.variable = {string:cfd' . $curField . '} AND cfd' . $curField . '.id_member = mem.id_member)';
$query_parameters['cfd' . $curField] = $curField;
$fields += array($customCount++ => 'IFNULL(cfd' . $curField . '.value, {string:blank_string})');
Code: (replace with) [Select]
					$customJoin[] = 'LEFT JOIN {db_prefix}custom_fields_data AS cfd' . $field . ' ON (cfd' . $field . '.variable = {string:cfd' . $field . '} AND cfd' . $field . '.id_member = mem.id_member)';
$query_parameters['cfd' . $field] = $curField;
$fields += array($customCount++ => 'IFNULL(cfd' . $field . '.value, {string:blank_string})');
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 06, 2016, 07:47:37 am
 ;D yep no more errors when clicking on those fields but the search is broken, I searched for "RE" into "provincia field" and look the results:
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 08:45:35 am
Would you mind attaching the file?
It looks like it searches in the name and email with it shouldn't.
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 06, 2016, 09:07:11 am
I used a clean file memberlist.controller.php from the last version of elkarte and I did the edits you suggest below. I attach the file, I checked the results from my search and I confirm that the search is probably made into all fields, not just username and email. I found some users without "RE" characters into username or email, but into the custom field "Vehicle" or "Region (regione)"
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 09:31:27 am
Okay, this time seems better, would you try the attached one? O:-)
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 06, 2016, 09:59:06 am
the search works well now, if I click on "provincia" field no error, but if I click on "Regione" I got this:
Code: [Select]
Unknown column 'cfdcust_cust_region.value' in 'order clause'
File: /../public/sources/subs/Memberlist.subs.php
Riga: 261

Nota: la versione del tuo database è 1.0.2
probably because there is nothing to sort in that field, "RE" province is in the same region for all users ;)
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 10:10:03 am
Darn was a typos!... (Well, actually not exactly a typo, more a "I forgot to replace a thing" kind of thing.)
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 06, 2016, 10:46:45 am
the search works, but still errors on both fields:
Code: [Select]
The database value you're trying to insert does not exist: cfdcust_cust_provin
and
Code: [Select]
The database value you're trying to insert does not exist: cfdcust_cust_region
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 02:15:30 pm
Well... now I'm pretty sure it's fixed... I hope! xD

Sorry for all the bouncing, but custom fields are a bit of a pain and Spuds is tha Master! :P
See if the attached gives the expected results. **fingers crossed**!!
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 06, 2016, 04:42:38 pm
It works, thank you for your help. Don't forget to include it into last release ;)
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 06, 2016, 05:09:28 pm
YAY! :D
Title: Re: Small bug in search members with dropdown custom fields
Post by: radu81 on March 23, 2016, 02:50:08 pm
/me feels that the new version 1.0.7 will be released soon  ;) 
Title: Re: Small bug in search members with dropdown custom fields
Post by: emanuele on March 23, 2016, 05:44:54 pm
Shhh!! It's a secret!!  :-X  :P