sifr_render_css_screen() prints all rules, without checking to make sure it's a sIFR rule. Not an issue now, but it will be if someone adds a new rendering plugin.

Comments

q0rban’s picture

On further study, it appears that the real issue occurs in render_get_rules() of the render.module.

  static $rules = array();
  
  if (!empty($rules)) {
    return $rules;
  }

  if (isset($plugin)) {
    $result = db_query("SELECT * FROM {render} WHERE plugin = '%s' ORDER BY weight", check_plain($plugin));
  }
  else {
    $result = db_query('SELECT * FROM {render} ORDER BY weight');
  }

I'm guessing that it's returning the $rules without running the query that selects only rules by $plugin. Maybe this would be a better solution? :

  static $rules = array();
  
  if (isset($plugin)) {
    $result = db_query("SELECT * FROM {render} WHERE plugin = '%s' ORDER BY weight", check_plain($plugin));
  }
  else if (empty($rules)) {
    $result = db_query('SELECT * FROM {render} ORDER BY weight');
  }
  else {
    return $rules;
  }
q0rban’s picture

Status: Needs review » Postponed (maintainer needs more info)
q0rban’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new656 bytes

So I've figured out the problem, but am not sure about the solution. Declaring $rules as static inside render_get_rules() essentially sends all the rules to each plugin.

That would seem simple enough to fix, but the real problem is that render_get_rules() also sets the sitewide 'render_plugins' variable by recursing through each rule and creating an array of each plugin name, which I'm assuming is why you've set the rules static in the first place.

So, the only solution I came up with would be to declare $active_plugins static instead. Let me know what you think.

q0rban’s picture

Title: sifr_render_css_screen should only write sIFR rules » render_get_rules() doesn't send plugin specific rules
sun’s picture

Status: Needs review » Needs work

Sounds reasonable. However, you have removed the rule cache by removing those lines:

if (!empty($rules)) {
  return $rules;
}

$rules should be $active_plugins[$plugin] then.

q0rban’s picture

I'm not sure I understand. If by rule cache you mean the names of each plugin, then that is being stored in the static $active_plugins. If you mean something else, then it's probably beyond the scope of what I understand is happening in the function.

By my understanding the function is performing 3 separate tasks:

  • if $plugin is set, return only the rules for that specific plugin.
  • if $plugin isn't set, return all rules.
  • use set_variable to store all the plugin types.

In my testing, all the above tasks are being accomplished with the patch. Let me know what I'm missing.

sun’s picture

$rules has been a static variable before. This means that its content cached locally for this function; see http://de2.php.net/manual/en/language.variables.scope.php for further information. Once the current rules are fetched from the database, we can early-return the rules from the already filled $rules array. Since this patch changes $rules to $active_plugins[$plugin], the code in #5 needs to be re-inserted with the changed variable name.

q0rban’s picture

StatusFileSize
new1.89 KB

Ahh, ok, I think I understand. You are setting $rules static so that there will be minimal database calls, correct? If that's the case, then yes I can understand why the above patch would be a bad idea.

I've attached a new patch that puts each plugin's rules in $rules['plugin_name'], and also stores all rules in $rules['all']. It will return $rules['all'] unless a specific plugin's rules are requested. Let me know what you think.

sun’s picture

errr... yes and no ;)

I think the patch in #3 was great so far. The only thing missing was the early-return I outlined in #5. If you implement it the same way as it was before, we don't need extra indentation. Furthermore, we don't need an additional 'all' array containing all rules from all plugins, because we can iterate over the whole array where needed.

btw: Please read http://drupal.org/patch/create (at least use -up arguments, please).

q0rban’s picture

The only thing missing was the early-return I outlined in #5. If you implement it the same way as it was before, we don't need extra indentation.

Well, I see that, but the problem I noticed with that method is that it's not actually storing all the rules from the initial database call, so the early return is kind of useless since the static $active_plugins variable is only storing the plugins' name, not the parameters of the each rule.

Encapsulating the database call within if (isset($rules)) means we only need one instance of this:

  if ($plugin == NULL) {
    return $rules['all'];
  }
  return $rules[$plugin];

otherwise we'd need it up at the top with the if (!isset($rules)) { and at the bottom after the database call. So that's why everything's getting the extra indentation.

Furthermore, we don't need an additional 'all' array containing all rules from all plugins, because we can iterate over the whole array where needed.

I agree that we can iterate elsewhere, but I was trying to come up with a solution that only modified the code within the render_get_rules() function.

btw: Please read http://drupal.org/patch/create (at least use -up arguments, please).

I'm sorry, I was being lazy just viewing the unsaved changes within my IDE.

Let me know how you want to proceed.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB

I thought of doing it this way. Let me know what you think.

sun’s picture

@q0rban: Any updates?

q0rban’s picture

Sorry, I don't know why I wasn't sent an e-mail on #11: I didn't realize you had responded with a new patch. I don't have time to patch and test this week, but from just reading the patch, I think it looks like a good idea.

I'll test next week and get back to you..

thanks!

q0rban’s picture

Status: Needs review » Needs work
StatusFileSize
new2.02 KB

That patch (#11) gave me all sorts of problems. None of my rules were coming up, when I cleared the cache only one file was created, named _rules.js, there were some foreach errors as if some arrays weren't getting populated, and another error saying that the plugins had no javascript creation function.

I really think #8 is the way to go, I've been using it on a site since I first posted it and it's been working with no problems. I've re-rolled and attached it.

q0rban’s picture

Thoughts?

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new2.15 KB
new2.14 KB

So, after a recent change that added the $reset parameter to render_get_rules() - does attached patch work for you?

q0rban’s picture

Hi sun,

I'm sorry I haven't replied sooner. I don't have time right now to test this patch.

Thanks..