You are here

function cache_actions_update_7201 in Cache Actions 7.2

Upgrade all old panels rules to the new format.

File

./cache_actions.install, line 19
Installation tasks for cache actions.

Code

function cache_actions_update_7201() {
  $rules = entity_load('rules_config');
  $displays = array();
  foreach ($rules as $rule) {
    if (in_array('cache_actions', $rule
      ->dependencies())) {
      foreach ($rule
        ->actions() as $action) {
        if ($action instanceof RulesAction && $action
          ->getElementName() == 'cache_actions_action_clear_panels_pane_cache') {
          foreach ($action->settings['panes'] as $key) {
            $display = _cache_actions_get_display_from_key($key);
            if (empty($display)) {
              continue;
            }

            // Collect all display that we are manipulating here.
            if (!in_array($display, $displays)) {
              $displays[] = $display;
            }
            $pane = _cache_actions_get_pane_from_key($key);
            $i = 1;
            foreach ($display->content as $pane_id => $panel_pane) {
              if (is_numeric($panel_pane->pid)) {
                $pid = 'new-' . $i;
              }
              else {
                $pid = $panel_pane->pid;
              }
              if ($pid == $pane && !empty($panel_pane->cache['method']) && $panel_pane->cache['method'] == 'rules' && empty($panel_pane->cache['settings']['new'])) {
                $cache_key = uniqid();
                $display->content[$pane_id]->cache['settings']['cache_key'] = $cache_key;
                $display->content[$pane_id]->cache['settings']['new'] = TRUE;
                $action->settings['panes'][$cache_key] = $cache_key;
                unset($action->settings['panes'][$key]);
                $action
                  ->save();
              }
              $i++;
            }
          }
        }
      }
    }
  }
  foreach ($displays as $display) {
    panels_save_display($display);

    // Manually call this hook - we can't be sure that the hook is registered
    // at the time this update runs.
    cache_actions_panels_display_save($display);
  }
}