Download & Extend

Globally set cache settings for all panel panes

Project:Panels
Version:7.x-3.3
Component:Documentation
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Is there a way to set cache settings for all panes in one hit?

Editors on my site have created a lot of panel nodes without setting cache settings for any of them.

I'd like to update all the panes to use time-based simple caching - is there a better way of doing it than a direct database query?

Comments

#1

nope, there's no facility for a batch action like that. sorry. a direct db query might be a little tough (given that you have to write to a serialized array), but you could probably do it pretty easily with a short script executed via drush scr.

#2

Status:active» fixed

#3

Thanks - that's what I ended up doing - here's the function I called via Drush, in case it's useful to anyone else.

/**
* Set a panel display to use simple caching.
*
* @param int $pid
*   the panel ID
* @param int $did
*   the display ID
* @param int $lifetime
*   the cache lifetime in seconds
*/
function mymodule_panel_cache_change($pid, $did, $lifetime) {
  if (is_numeric($pid) && is_numeric($did)) {
    $display = panels_load_display($did);
    $cache_settings = serialize(array(
      'method' => 'simple',
      'settings' => array('lifetime' => $lifetime, 'granularity' => 'none'),
        ));
    if (db_query("UPDATE {panels_pane} SET cache = '%s' WHERE pid = %d AND did = %d", $cache_settings, $pid, $did)) {
      return TRUE;
    }
  }
}

#4

Status:fixed» closed (fixed)

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

#5

Version:6.x-3.9» 7.x-3.3
Status:closed (fixed)» active

Does anybody know if there is a way to do this under D7 / Panels 3.3 ?

In the meantime, I'll try to adapt the snippet above to it and post it if it's relevant.

#6

If anyone's interested, here's what I came up with. I can't believe this functionality isn't implemented somewhere already, but well.

It's VERY rough. It will enable caching for one week for all panes of all displays on your website, so please use with caution.

<?php
function _panel_cache_change() {
     
$i = 0;
     
$result = db_query("SELECT * FROM {panels_pane}");
      foreach (
$result as $obj) {
       
$cache_settings =array(
         
'method' => 'simple',
         
'settings' => array('lifetime' => 604800, 'granularity' => 'none'), // You may change hese parameters to suit your needs
       
);  
         
$upd = db_update('panels_pane')
            ->
fields(array(
                           
'cache' => serialize($cache_settings)
                            )
                        )
            ->
condition('pid', $obj->pid, '=')
            ->
condition('did', $obj->did, '=')
            ->
execute();
          if (
$upd) {
           
dsm('Cache activated for panel ' . $obj->pid . ' / from display ' . $obj->did );
          } else {
          
dsm('Cache already activated with these parameters for panel ' . $obj->pid . ' / from display ' . $obj->did );
          }
       
$i++;
      }     
      return
"$i panes treated.";
}
?>

#7

Status:active» needs review

If anyone has time to review the snippet, feel free. Or maintainers can close, it's up to them.

nobody click here