Hi,
Using latest .dev and clearing cache I got:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'taxonomy_weblinks_tid' in 'where clause': SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {field_data_taxonomy_weblinks} t INNER JOIN {node} n ON t.entity_id = n.nid WHERE (taxonomy_weblinks_tid IN (:db_condition_placeholder_0)) AND (n.status = :db_condition_placeholder_1) AND (n.type = :db_condition_placeholder_2) AND (n.language IN (:db_condition_placeholder_3, :db_condition_placeholder_4)) ) subquery; Array ( [:db_condition_placeholder_0] => 3128 [:db_condition_placeholder_1] => 1 [:db_condition_placeholder_2] => weblinks [:db_condition_placeholder_3] => nl [:db_condition_placeholder_4] => und ) in weblinks_term_node_count() (regel 167 van /sites/all/modules/weblinks/weblinks.module).

The problem is the column field in field_data_taxonomy_weblinks
It should be field_weblinks_tid instead of taxonomy_weblinks_tid

See improved code line 159 -167:

$query = db_select('field_data_taxonomy_weblinks', 't');
  $query->condition('field_weblinks_tid', $tids, 'IN');
  $query->join('node', 'n', 't.entity_id = n.nid');
  $query->condition('n.status', 1);
  $query->condition('n.type', 'weblinks');
  // Use 'language' from the node table not field_data_taxonomy_weblinks.
  $query->condition('n.language', $langs, 'IN');

  $count = $query->countQuery()->execute()->fetchField();
  return $count;
}

Greetings, Martijn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Summit’s picture

Issue summary: View changes
GStegemann’s picture

It should be field_weblinks_tid instead of taxonomy_weblinks_tid

Sorry, but at all my D7 test sites the column is named 'taxonomy_weblinks_tid'. And I guess also at Jonathans sites. See attached screen shot.

I assume your Web Links content type was tampered somehow. Due to whatsoever reason your Web Links Taxonomy Reference field became named 'field_weblinks'. And that is wrong.

When I changed the Web Links content type the field name 'taxonomy_weblinks' was automatically proposed by Drupal. Did you modify the content type manually? And what field type did you choose? However, it its important to select 'Add existing field' and not 'Add new field'. But in case you have upgraded your D6 site to D7 the Web Links update function takes care of the creating the correct Taxonomy Reference field.

Summit’s picture

Mmm.. I do not use the weblinks vocabulary, but use two other ones for the weblinks related terms; Region and Category.
May be that is why this happened with me.

Sorry for reporting this then. But may be it shouldn't be hardcoded, becauase may be also others will use other vocabularies instead of the weblinks vocabulary?
greetings, Martijn

GStegemann’s picture

but use two other ones for the weblinks related terms; Region and Category.

Yes, very likely.

But may be it shouldn't be hardcoded

Regarding the Web Links navigation vocabulary expecting this field if fully OK. However, when only other vocabularies are used a check is needed whether the Web Links specific taxonomy reference field really does exist. Thanks for reporting this since we havn't considered this kind of usage.

I will check that with Jonathan.

GStegemann’s picture

jonathan1055’s picture

Title: Column not found: 1054 Unknown column 'taxonomy_weblinks_tid' in 'where clause': SELECT COUNT(*) AS » Unknown column 'taxonomy_weblinks_tid' when using non-weblinks taxonomy

Thanks for discovering this. That column is hard-coded in three functions. You had the problem in weblinks_term_node_count() but it is also in _weblinks_get_query() and weblinks_user_form(). Yes, I will work on replicating the problem and I am sure we can fix it.

GStegemann’s picture

Maybe the information in comment #2210683-42: 6.x to 7.x migration based on Drupal-to-Drupal Migrate is helpful for you.

jonathan1055’s picture

I've done some testing and discovered that Web Links does not work for any vocabs other than our standard weblinks vocabulary. If you select a non-weblinks vocab the main links page is empty. Even if you have added terms to the nodes, they still do not show, we just get empty group fieldsets. This is due to the use of 'taxonomy_weblinks_tid' in _weblinks_get_query()

I think this needs to be fixed before we release 7.x

jonathan1055’s picture

Status: Active » Needs review

I've been working on a solution to find the table name and field name for the vocabulary used for weblinks. Before I code the changes to .module and .user.inc I would like you to test the following function which will be used in the real code.

/**
 * Get field information for the vocabulary used in weblinks, which may not be
 * the default 'taxonomy_weblinks' field.
 *
 * @return array
 *   Array containing values 'table_name' and 'tid'
 */
function _weblinks_vocabulary_field_info() {
  $vocid = _weblinks_get_vocid();
  dd($vocid, '$vocid');
  $vocabulary = taxonomy_vocabulary_load($vocid);
  dd($vocabulary->name, '$vocabulary->name');
  dd($vocabulary->module, '$vocabulary->module');
  dd($vocabulary->machine_name, '$vocabulary->machine_name');
  $fields = field_read_fields(array('bundle' => 'weblinks'));
  $return = array();
  foreach ($fields as $name => $field_info) {
    if ($field_info['type'] == 'taxonomy_term_reference') {
      dd('---');
      dd($field_info['field_name'], '$field_info[field_name]');
      ## dd($field_info,  $name . ' $field_info' );
      dd(isset($field_info['storage']['details']['sql']) ? $field_info['storage']['details']['sql'] : 'not set' , 'storage details - sql');
      dd(isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : 'not set', 'settings - allowed values');
      $vocab_name_match = ($field_info['settings']['allowed_values']['0']['vocabulary'] == $vocabulary->machine_name);
      dd($vocab_name_match, '$vocab_name_match');
      if ($vocab_name_match) {
        $flc = $field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT'];
        ## dd($flc, 'flc');
        $return['table_name'] = array_keys($flc)['0'];
        $return['tid'] = reset($flc)['tid'];
      }
    }
  }
  dd($return, '$return');
  return $return;
}
_weblinks_vocabulary_field_info();

I am assuming you have the devel module so just paste this into the execute textarea, run it then post back the dd() output. Hopefully the returned values will be the ones which we need to use in our code.

GStegemann’s picture

Tried it. But this line fails to execute:

        $return['table_name'] = array_keys($flc)['0'];

Parse error: syntax error, unexpected '[' in /var/www/html/cm7/sites/all/modules/devel/devel.module(1415) : eval()'d code on line 29

I'm still running PHP 5.3.3.

jonathan1055’s picture

I am using php 5.4 so I did not spot this. Thanks for testing! Yes, according to this discussion on stackoverflow array dereferencing (a term I had not heard of, but useful to know it now) is new to php 5.4. Try the following:

function _weblinks_vocabulary_field_info() {
  $vocid = _weblinks_get_vocid();
  dd($vocid, '$vocid');
  $vocabulary = taxonomy_vocabulary_load($vocid);
  dd($vocabulary->name, '$vocabulary->name');
  dd($vocabulary->module, '$vocabulary->module');
  dd($vocabulary->machine_name, '$vocabulary->machine_name');
  $fields = field_read_fields(array('bundle' => 'weblinks'));
  $return = array();
  foreach ($fields as $name => $field_info) {
    if ($field_info['type'] == 'taxonomy_term_reference') {
      dd('---');
      dd($field_info['field_name'], '$field_info[field_name]');
      ## dd($field_info,  $name . ' $field_info' );
      dd(isset($field_info['storage']['details']['sql']) ? $field_info['storage']['details']['sql'] : 'not set' , 'storage details - sql');
      dd(isset($field_info['settings']['allowed_values']) ? $field_info['settings']['allowed_values'] : 'not set', 'settings - allowed values');
      $vocab_name_match = ($field_info['settings']['allowed_values']['0']['vocabulary'] == $vocabulary->machine_name);
      dd($vocab_name_match, '$vocab_name_match');
      if ($vocab_name_match) {
        $flc = $field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT'];
        dd($flc, 'flc');
        $keys = array_keys($flc);
        dd($keys, '$keys');
        $return['table_name'] = $keys['0'];
        $return['tid'] = $flc[$keys['0']]['tid'];
      }
    }
  }
  dd($return, '$return');
  return $return;
}
_weblinks_vocabulary_field_info();

I am surprised how tedious it is to get this info. But maybe not many contrib modules need the table name and field name? If this works, it might be useful to search core code for some of these items to see if there are functions which already do this.

GStegemann’s picture

But maybe not many contrib modules need the table name and field name?

Most probably you are right. Did you already check the code of module Taxonomy Manager? Or all the migration modules?

Here is the dd() output:

$vocid: 9
$vocabulary->name: Web Links
$vocabulary->module: weblinks
$vocabulary->machine_name: vocabulary_9
---
$field_info[field_name]: taxonomy_weblinks
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_taxonomy_weblinks] => Array
                (
                    [tid] => taxonomy_weblinks_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_taxonomy_weblinks] => Array
                (
                    [tid] => taxonomy_weblinks_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => vocabulary_9
            [parent] => 0
        )

)

$vocab_name_match: 1
flc: Array
(
    [field_data_taxonomy_weblinks] => Array
        (
            [tid] => taxonomy_weblinks_tid
        )

)

$keys: Array
(
    [0] => field_data_taxonomy_weblinks
)

$return: Array
(
    [table_name] => field_data_taxonomy_weblinks
    [tid] => taxonomy_weblinks_tid
)

jonathan1055’s picture

Thanks. This is the important bit:

$return: Array
(
    [table_name] => field_data_taxonomy_weblinks
    [tid] => taxonomy_weblinks_tid
)

So, it works for you. I have also tested it on a non-weblinks vocabulary assigned to the weblinks content type and a field added. It would be good if Martijn could also do this test, as he discovered the problem in the first place. I will now implement the use of this function in the .module and .user.inc code and make a proper patch.

Did you already check the code of module Taxonomy Manager? Or all the migration modules?

I will have a look, but really I wanted functions built in core. If core does not provide them I am confident that this function I have written will do the job.

Summit’s picture

Hi Jonathan,
I will do the test with the .dev version when it comes out with this. Just set here that it is implemented and I will test it.
greetings, Martijn

GStegemann’s picture

but really I wanted functions built in core.

No, I don't know of any applicable core functions neither. The core Forum module also assumes that its Navigation vocabulary is assigned with a fixed name.

GStegemann’s picture

Hi Martijn,

regarding #13: Jonathan asked if you could run his test function from comment #11 before he has finished the full implementation. That would be of great help to verify his assumptions about how Taxonomy term reference fields are handled in a module like Web Links. However, to run his test you have to have the Devel module installed.

Gerhard

Summit’s picture

Hi Gerhard, Jonathan, I am ok to do the test.
But I do not know what to do. Do I need to add Devel to the live site, and than add some code? What code please?
Greetings, Martijn

GStegemann’s picture

Hi Martijn,

Do I need to add Devel to the live site

yes.

What code please?

The PHP code posted in comment #11. Every line between the PHP tags. After you have executed the test Jonathan needs the output of the dd() calls which you will find in your sites /tmp folder in the file named drupal_debug.txt.

Summit’s picture

So I take latest weblinks.dev and add this code to weblinks.module?
greetings, Martijn

GStegemann’s picture

No.

You just install and enable the Devel Module from https://www.drupal.org/project/devel (when not already done). Then next you select from your admin menu "Development | Execute PHP code". On that page a window is displayed in which you paste the code from comment #11. To execute the code you click on button Execute. After the function completes you look up the file drupal_debug.txt and post its content. That's all.

Summit’s picture

Hi Gerhard,
I did as you asked. I click on execute...and then drupal_debug.txt should be somewhere....but where?
greetings, Martijn

GStegemann’s picture

In your sites /tmp folder. Check your site settings.

Summit’s picture

Hi, I had to build my tmp again..
There you go:

$vocid: 12
$vocabulary->name: Prijs-indeling
$vocabulary->module: taxonomy
$vocabulary->machine_name: prijs_indeling
---
$field_info[field_name]: field_regio
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_regio] => Array
                (
                    [tid] => field_regio_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_regio] => Array
                (
                    [tid] => field_regio_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => regio
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
---
$field_info[field_name]: field_rubriek
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_rubriek] => Array
                (
                    [tid] => field_rubriek_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_rubriek] => Array
                (
                    [tid] => field_rubriek_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => rubrieken
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
---
$field_info[field_name]: field_snelweg
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_snelweg] => Array
                (
                    [tid] => field_snelweg_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_snelweg] => Array
                (
                    [tid] => field_snelweg_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => snelweg_traject
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
---
$field_info[field_name]: field_beoordelingen
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_beoordelingen] => Array
                (
                    [tid] => field_beoordelingen_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_beoordelingen] => Array
                (
                    [tid] => field_beoordelingen_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => beoordelingen
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
---
$field_info[field_name]: field_prijsindeling
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_prijsindeling] => Array
                (
                    [tid] => field_prijsindeling_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_prijsindeling] => Array
                (
                    [tid] => field_prijsindeling_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => prijs_indeling
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 1
flc: Array
(
    [field_data_field_prijsindeling] => Array
        (
            [tid] => field_prijsindeling_tid
        )

)

$keys: Array
(
    [0] => field_data_field_prijsindeling
)

---
$field_info[field_name]: field_bijzonderheden
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_bijzonderheden] => Array
                (
                    [tid] => field_bijzonderheden_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_bijzonderheden] => Array
                (
                    [tid] => field_bijzonderheden_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => camping_bijzonderheden
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
---
$field_info[field_name]: field_typenacco
storage details - sql: Array
(
    [FIELD_LOAD_CURRENT] => Array
        (
            [field_data_field_typenacco] => Array
                (
                    [tid] => field_typenacco_tid
                )

        )

    [FIELD_LOAD_REVISION] => Array
        (
            [field_revision_field_typenacco] => Array
                (
                    [tid] => field_typenacco_tid
                )

        )

)

settings - allowed values: Array
(
    [0] => Array
        (
            [vocabulary] => typen_accommodaties
            [parent] => 0
            [depth] => 
        )

)

$vocab_name_match: 
$return: Array
(
    [table_name] => field_data_field_prijsindeling
    [tid] => field_prijsindeling_tid
)

Greetings, Martijn

GStegemann’s picture

Many thanks.

But surprising is that the field 'field_weblinks_tid' does not appear. Did you remove the Web Links navigation vocabulary completely?

Summit’s picture

Hi Gerhard, yes I think more than two years ago or so...it had to do with the fact that then a weblinks url would show all connected weblinks, which would break my site...
greetings, Martijn

GStegemann’s picture

I see. But the problem is already fixed a while ago, see #2413339: Taxonomy links for non-weblinks vocabs are altered to weblinks/x .

Summit’s picture

Hi Gerhard, Yes but then I had already hunderds of weblinks in...so didn't go back anymore..
gr, Martijn

jonathan1055’s picture

Status: Needs review » Needs work

Excellent, thank you Martijn. Now you have learned about Devel module and executing php directly. It can be very helpful, and Devel has lots of useful stuff for testers too.

The very top and very end of the debug output tell what we want to see. From:

$vocid: 12
$vocabulary->name: Prijs-indeling
$vocabulary->module: taxonomy
$vocabulary->machine_name: prijs_indeling

... we get

$return: Array
(
    [table_name] => field_data_field_prijsindeling
    [tid] => field_prijsindeling_tid
)

I will now make the full changes and produce a proper patch.

GStegemann’s picture

But why is vocabulary 'Prijs-indeling' the first one and the applicable one? I thought that all other vocabularies Martijn uses are also somehow related to his Web Links.

But anyway, when $vocabulary->module has the value 'weblinks' then that must be the navigation vocabulary, correct?

jonathan1055’s picture

Status: Needs work » Needs review
FileSize
5.41 KB

But why is vocabulary 'Prijs-indeling' the first one and the applicable one?

It is not the 'first' one, as that field appeared half way down the debug. The info right at the top of the output shows that vocab 12 is the one being used for weblinks navigation. This is the only one which gets $vocab_name_match and so it is the one which is stored and returned.

I have added defaults to the return array so that if anything does not match we at least end up with the standard fields (that had been previously hardcoded in .module and .user.inc)

Here's a patch for proper tetsing. Martijn, are you ok with applying a patch? If not, let us know and I will add here the two changed files in the entirety for you to use.

Jonathan

Summit’s picture

I Jonathan,

Yes please place here the two changed files and I will use them thursdayevening. I am not good in patching. And I am this evening not at home.
Greetings, Martijn

GStegemann’s picture

Tested and works for me. I have not marked as RTBC since we should wait for Martijns tests.

@Martijn: do you havel shell access at your site? If yes patching is quite simple. Possibly simpler than sending you the modified files. To send you the files we have to know which version of Web Links you have installed.

jonathan1055’s picture

Based on Martijn's comment from #14 "I will do the test with the .dev version when it comes out with this" here are the two files from the latest dev, with the changes added. I had to add .txt to upload them, and then an extra _ was added to .user.inc, so you need to rename these as they are direct replacements for the original files. I suggest you keep copies of your originals in case these fail for some unexpected reason.

But also, yes respond to Gerhard's question about shell access. It's useful for maintainers to have knowledge of our users systems and background.

Summit’s picture

Hi Jonathan,

nope no shell access. My site is on a hosting machine. If I understand the question correctly.
it is correct I use the latest Weblinks .dev. So tomorrow evening I will test the files, thanks for uploading them!
Greetings, Martijn

jonathan1055’s picture

Hi Martijn,
Yes use the latest .dev then download those two files I posted, and use them to replace the existing .module and .user.inc

To test the .module changes, just visit your Web Links main page. You should no longer get the SQL errors, and the number of links should be shown in the fieldset title (if your theme does this). To check the .user change you need to have authority to view other users account pages and go to /user/x/weblinks to see the links added by that user. However, if you cannot test this, don't worry because if the main page works it proves the new function is returning the correct data for your site.

Jonathan

Summit’s picture

Hi Jonathan,
I will test this tomorrow. I can test it in D7 thanks to the great work of Gerhard with migration Weblinks :)
Greetings, Martijn

Summit’s picture

Hi Jonathan,

I see under /user/x/weblinks now the weblinks per user with adding of this code. I do not know if this is new functionality though..
I also see no SQL error, great!

But when I select another vocabulary as weblinks default. The /weblinks page doesn't give the underneath weblinks.
But may be this is another issue...

Greetings, Martijn

Summit’s picture

FileSize
111.88 KB

Hi Jonathan,

Screenshot of weblinks with choosing of category as weblinks Vocabulary.
The categories are certainly not empty.

Greetings, Martijn

jonathan1055’s picture

I've tested it when switching between two vocabularies and it worked ok for me. First I also had blank groups like you, but then I added the new vocab as a field to the weblinks content type, editted some links to set some of the new categories and then the links showed up.

Could you also set unclassified links to be shown on your page, as they might be in there instead.

Thanks for testing
Jonathan

Summit’s picture

Hi Jonathan,
This will not work for me, because the vocabulary now used as weblinks-vocabulary IS already used within the contenttype Weblinks...but may be add this as another issue for you?

greetings, Martijn

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

I see under /user/x/weblinks now the weblinks per user with adding of this code. I do not know if this is new functionality though.

This is not new functionality, but it would have failed had you tried it before this patch. Your testing has shown that my use of the new vocab function within weblinks_user_form() is working correctly.

I also see no SQL error, great!

This shows that the problem has been solved, and since Gerhard has also tested in #32 I am marking this RTBC and will commit the changes. Then if there are further problems to solve we can work on them, but this main issue is ready.

Can you check your 'unclassified links' fieldset to see if the missing nodes you were expecting are shown there?

  • jonathan1055 committed c30070e on 7.x-1.x
    Issue #2468615 by jonathan1055: Unknown column 'taxonomy_weblinks_tid'...

  • jonathan1055 committed 7d79808 on 7.x-1.x
    Issue #2468615 by jonathan1055: changelog.txt for Unknown column with...
jonathan1055’s picture

Status: Reviewed & tested by the community » Fixed

Marking this as fixed, because the original problem is now corrected.
If you still have difficulties, it is probably best to open a new issue, and list the steps required to reproduce the error, starting with a clean D7 install.

Thank you both for your help on this - good to get it fixed.

Jonathan

Summit’s picture

Hi Jonathan,

I will look into your question soon. it is not part of the original issue, so when I find strange things, I will report this as a separate issue than. Thanks for fixing this!
Gre
Greetings, Martijn

jonathan1055’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Summit’s picture

Hi Jonathan,
About your open question: Can you check your 'unclassified links' fieldset to see if the missing nodes you were expecting are shown there?
Yes the links show now all under "/weblinks". Thanks!
Greetings, Martijn