I am trying to use Rules to set the domain theme based on a taxonomy condition of a domain node. I am getting this error:

Recoverable fatal error: Argument 2 passed to db_query() must be an array, string given, called in /domain_rules/domain_rules.module on line 223 and defined in db_query() (line 2342 of /includes/database/database.inc).

Comments

shushu’s picture

Assigned: Unassigned » shushu
Status: Active » Postponed (maintainer needs more info)

@bmx269, can you please export the rule and show it to me ?
Thanks,
Shushu

bmx269’s picture

{ "rules_domain_node_edited_hot_rod_active_subscription_" : {
    "LABEL" : "Domain Node Edited - Hot Rod (active subscription)",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "Websites" ],
    "REQUIRES" : [ "rules", "domain_rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "website" : "website" } } } },
      { "data_is" : { "data" : [ "node:field-status" ], "value" : "3" } },
      { "data_is" : { "data" : [ "node:field-theme" ], "value" : "7" } }
    ],
    "DO" : [
      { "domain_rules_action_variable_set" : {
          "subdomain" : "[node:field_domain_prefix].example.com",
          "variable" : "site_frontpage",
          "value" : "home"
        }
      },
      { "domain_rules_action_variable_set" : {
          "subdomain" : "[node:field_domain_prefix].example.com",
          "variable" : "site_name",
          "value" : "[node:title]"
        }
      },
      { "domain_rules_action_set_domain_theme" : {
          "subdomain" : "[node:field_domain_prefix].example.com",
          "theme" : "hot_rod"
        }
      }
    ]
  }
}
bmx269’s picture

The full rule with Conditional Rules (https://drupal.org/project/rules_conditional) is

{ "rules_domain_node_edited_active" : {
    "LABEL" : "Domain Node Edited (active subscription)",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "TAGS" : [ "Websites" ],
    "REQUIRES" : [ "rules", "domain_rules", "rules_conditional" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "website" : "website" } } } },
      { "data_is" : { "data" : [ "node:field-status" ], "value" : "3" } }
    ],
    "DO" : [
      { "domain_rules_action_variable_set" : {
          "subdomain" : "[node:field_domain_prefix].example.com",
          "variable" : "site_frontpage",
          "value" : "home"
        }
      },
      { "domain_rules_action_variable_set" : {
          "subdomain" : "[node:field_domain_prefix].example.com",
          "variable" : "site_name",
          "value" : "[node:title]"
        }
      },
      { "CONDITIONAL" : [
          {
            "IF" : { "data_is" : { "data" : [ "node:field-theme" ], "value" : "9" } },
            "DO" : [
              { "domain_rules_action_set_domain_theme" : {
                  "subdomain" : "[node:field_domain_prefix].example.com",
                  "theme" : "bartik"
                }
              }
            ]
          },
          {
            "ELSE IF" : { "data_is" : { "data" : [ "node:field-theme" ], "value" : "10" } },
            "DO" : [
              { "domain_rules_action_set_domain_theme" : {
                  "subdomain" : "[node:field_domain_prefix].example.com",
                  "theme" : "garland"
                }
              }
            ]
          },
          {
            "ELSE IF" : { "data_is" : { "data" : [ "node:field-theme" ], "value" : "7" } },
            "DO" : [
              { "domain_rules_action_set_domain_theme" : {
                  "subdomain" : "[node:field_domain_prefix].example.com",
                  "theme" : "hot_rod"
                }
              }
            ]
          },
          {
            "ELSE IF" : { "data_is" : { "data" : [ "node:field-theme" ], "value" : "8" } },
            "DO" : [
              { "domain_rules_action_set_domain_theme" : {
                  "subdomain" : "[node:field_domain_prefix].example.com",
                  "theme" : "shiny"
                }
              }
            ]
          },
          {
            "ELSE IF" : { "data_is" : { "data" : [ "node:field-theme" ], "value" : "11" } },
            "DO" : [
              { "domain_rules_action_set_domain_theme" : {
                  "subdomain" : "[node:field_domain_prefix].example.com",
                  "theme" : "stark"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

The themes chosen are for testing.

shushu’s picture

Title: Setting domain theme fatal error » Change db_qeury to fit to D7 standard
Version: 7.x-1.5 » 7.x-1.x-dev
Status: Postponed (maintainer needs more info) » Needs review

Thanks.
db_query changed from D6 to D7, and while it worked as is, it seems to stop working (or at least to give angry error messages).
Please try the attached version(can't attach .module files) just to verify it works before I create a new version.
Please edit your domain_rules.module and replace the domain_rules_action_set_domain_theme() function with this code:

/**
 * Custom hook
 * Do on action 'set domain theme'
 * @param string $subdomain
 * @param string $theme
 */
function domain_rules_action_set_domain_theme($subdomain, $theme) {

  $domain = domain_lookup(NULL, $subdomain, TRUE);

  if (isset($domain['domain_id'])) {
    $domain_id = $domain['domain_id'];
    $settings = NULL;
    db_query('UPDATE {domain_theme} SET status = 0 WHERE domain_id = :domain_id', array(':domain_id' => $domain_id));
    $check = domain_theme_lookup($domain_id, $theme);
    if ($check == -1) {
      db_query('INSERT INTO {domain_theme} (domain_id, theme, settings, status) VALUES (:domain_id, \':theme\', :settings, 1)', array(':domain_id' => $domain_id, ':theme' => $theme, ':settings' => $settings));
    }
    else {
      db_query('UPDATE {domain_theme} SET status = 1 WHERE domain_id = :domain_id AND theme = \':theme\'', array(':domain_id' => $domain_id, ':theme' => $theme));
    }
    cache_clear_all();
  }
  else {
    drupal_set_message(t('The domain %domain does not exist.', array('%domain' => $subdomain)), 'error');
  }
}

(I know I should have just put a patch file, but I know some people have hard time patching...)
Regards,
Shushu

bmx269’s picture

With the change as per above, this is the error I am now getting. This and the original error do not allow the rule to change the domain theme. They work fine without the theme part.

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: UPDATE {domain_theme} SET status = 1 WHERE domain_id = :domain_id AND theme = ':theme'; Array ( [:domain_id] => 2 [:theme] => hot_rod ) in domain_rules_action_set_domain_theme() (line 229 of /home/servicebay/public_html/sites/all/modules/contrib/domain_rules/domain_rules.module).

shushu’s picture

Trying again...

/**
 * Custom hook
 * Do on action 'set domain theme'
 * @param string $subdomain
 * @param string $theme
 */
function domain_rules_action_set_domain_theme($subdomain, $theme) {

  $domain = domain_lookup(NULL, $subdomain, TRUE);

  if (isset($domain['domain_id'])) {
    $domain_id = $domain['domain_id'];
    db_query('UPDATE {domain_theme} SET status = 0 WHERE domain_id = :domain_id', array(':domain_id' => $domain_id));
    $check = domain_theme_lookup($domain_id, $theme);
    if ($check == -1) {
      db_query('INSERT INTO {domain_theme} (domain_id, theme, status) VALUES (:domain_id, :theme, 1)', array(':domain_id' => $domain_id, ':theme' => $theme));
    }
    else {
      db_query('UPDATE {domain_theme} SET status = 1 WHERE domain_id = :domain_id AND theme = :theme', array(':domain_id' => $domain_id, ':theme' => $theme));
    }
    cache_clear_all();
  }
  else {
    drupal_set_message(t('The domain %domain does not exist.', array('%domain' => $subdomain)), 'error');
  }

}

bmx269’s picture

We have success. That worked perfectly. Thanks so much. I think it needs to be committed to the release.

shushu’s picture

Status: Needs review » Closed (fixed)