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. ;)
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 #_#
I use the latest version:
(http://i.imgur.com/v8m5SxX.png)
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.
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:
$input_fields = isset($this->_req->query->fields) ? explode(',', $this->_req->query->fields) : $this->_req->post->fields;
add:
if (isset($context['columns'][$sort]))
$input_fields[] = $sort;
before (or after, it doesn't matter):
$context['old_search_value'] = $search;
add:
$input_fields = array_unique($input_fields);
and finally, replace:
$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:
$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.
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...
Irrelevant. (Like in the other 99.9% of the times.)
Good to know, thanks :)
Probably there is something wrong with my Memberlist.controller.php, but I have:
$input_fields = isset($_GET['fields']) ? explode(',', $_GET['fields']) : $_POST['fields'];
Ouch!!
Sorry, I was looking at the 1.1 files...
The line is the one you posted. All the others should be the same.
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
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.
O_o
Is there any difference between the two fields? (Type mainly.)
they are both dropdown fields, what I wonder if a sorting option is really useful in this case
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).
I keep forgetting that 1.1 is slightly different in many places...
Move this code:
// Set defaults for how the results are sorted
if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']]))
$_REQUEST['sort'] = 'real_name';
just after:
// 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.
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")
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.
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:-)
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 ;)
I'm joking of course, this should be solved in 1.0.7, not later. ;)
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:
foreach ($input_fields as $field)
foreach (array_keys($this->_search_fields) as $field)
and:
$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})');
$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})');
;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:
Would you mind attaching the file?
It looks like it searches in the name and email with it shouldn't.
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)"
Okay, this time seems better, would you try the attached one? O:-)
the search works well now, if I click on "provincia" field no error, but if I click on "Regione" I got this:
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 ;)
Darn was a typos!... (Well, actually not exactly a typo, more a "I forgot to replace a thing" kind of thing.)
the search works, but still errors on both fields:
The database value you're trying to insert does not exist: cfdcust_cust_provin
and
The database value you're trying to insert does not exist: cfdcust_cust_region
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**!!
It works, thank you for your help. Don't forget to include it into last release ;)
YAY! :D
/me feels that the new version 1.0.7 will be released soon ;)
Shhh!! It's a secret!! :-X :P