Hi,
i use themekey module and i am very happy of it :)
I just came across of a little bug when trying to use a rule based on a taxonomy tid to switch the theme.
it happens in themekey_taxonomy_nid2tid where the $result->rowCount()) is always 0 even if the query does returns results.
Actually, the documentation (http://php.net/manual/en/pdostatement.rowcount.php) states "For most databases, PDOStatement::rowCount() does not return the number of rows affected by a SELECT statement." and suggests a way to make it work.
I will upload the patch that i tried locally thet follows the documentation advice.

EDIT, i made a mistake writing fetchColumn() instead of rowCount() above, fixed it now

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

izus’s picture

FileSize
997 bytes
mkalkbrenner’s picture

Category: Bug report » Support request

Which version of ThemeKey are you using?
Neither 2.x nor 3.x are using that code (anymore). The current code is

function themekey_taxonomy_nid2tid($nid) {
  $tids = array();

  $query = db_select('taxonomy_index', 't');
  $query->addField('t', 'tid');
  $query->condition('t.nid', $nid);
  $result = $query->execute();

  if ($result->rowCount()) {
    foreach ($result as $item) {
      $tids[] = $item->tid;
    }
  }

  return count($tids) ? $tids : NULL;
}

izus’s picture

the patch is against the 2.5 version. (tried also on 2.3)
you're right about the current code that is used http://drupalcode.org/project/themekey.git/blob/refs/tags/7.x-2.5:/modul...

the issue is about the if ($result->rowCount()) {

the patch in #1 is trying to avoid it by using a $result->fetchColumn() and db_query

izus’s picture

Issue summary: View changes
izus’s picture

i understand the misunderstanding mkalkbrenner, i made a mistake in the issue description, i just fixed it with EDIT explication.
sorry about that !

izus’s picture

Status: Active » Needs review
mkalkbrenner’s picture

Title: Do not relay on rowCount() for SELECT statement » Do not rely on rowCount() for SELECT statement
Version: 7.x-2.x-dev » 7.x-3.x-dev
Category: Support request » Bug report
Status: Needs review » Needs work

OK, you're right.

rowCount() is used four times that way. We need to fix all all of them.

mkalkbrenner’s picture

Status: Needs work » Needs review
FileSize
4.13 KB

I think the patch is easier than proposed because the real count is not needed.
The error has been introduced by the port from D6 to D7. In D6 the result had to be checked before you iterate over it. In D7 such a check is not required at all and could therefor be skipped completely.

The other occurrences could be fixed by using db_merge().

Can you test this patch?

izus’s picture

i saw this was already merged in 3.x, tests in this branch are workin for me.
i tries to apply this in 2.x branch, it fails because we do not have modules/themekey.workbench_access.inc in 2.x branch

i will upload the working patch for 2.x (i greped and there is no rowCount left :))

izus’s picture

izus’s picture

Version: 7.x-3.x-dev » 7.x-2.x-dev
mkalkbrenner’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Fixed

I committed it to 7.x-2.x now. Thanks for your help.

Status: Fixed » Closed (fixed)

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