You are here

function linkit_update_7202 in Linkit 7.2

Update settings name as of the new plugin system using ctools and entity support.

File

./linkit.install, line 138
Install, update and uninstall functions for the Linkit module.

Code

function linkit_update_7202() {

  // Get old profiles.
  $old_profiles = db_query("SELECT * FROM {linkit_profiles}");
  foreach ($old_profiles as $profile) {
    $data = unserialize($profile->data);

    // Rename the plugins
    $data['plugins']['entity:node'] = $data['plugins']['node'];
    $data['plugins']['entity:user'] = $data['plugins']['user'];
    $data['plugins']['entity:file'] = $data['plugins']['file'];
    $data['plugins']['entity:taxonomy_term'] = $data['plugins']['taxonomy'];

    // Remove the old plugins.
    unset($data['plugins']['node']);
    unset($data['plugins']['file']);
    unset($data['plugins']['taxonomy']);
    unset($data['plugins']['user']);

    // Update the node settings.
    $data['entity:node'] = $data['node'];
    $data['entity:node']['bundles'] = $data['node']['content_types'];
    $data['entity:node']['group_by_bundle'] = $data['node']['group_by_content_type'];
    unset($data['entity:node']['content_types']);
    unset($data['entity:node']['group_by_content_type']);

    // Remove the old node settings.
    unset($data['node']);

    // Update the term settings.
    $data['entity:taxonomy_term'] = $data['taxonomy'];
    $data['entity:taxonomy_term']['group_by_bundle'] = $data['taxonomy']['group_by_vocabulary'];
    unset($data['entity:taxonomy_term']['group_by_vocabulary']);

    // Remove the old taxonomy settings.
    unset($data['taxonomy']);

    // Update the user settings.
    $data['entity:user'] = $data['user'];

    // Remove the old user settings.
    unset($data['user']);

    // Update the file settings.
    $data['entity:file'] = $data['file'];

    // Remove the old file settings.
    unset($data['file']);

    // New values, add them by default if they are not set.
    $deafult = array(
      'bundles' => array(),
      'group_by_bundle' => 0,
    );
    if (isset($data['entity:node'])) {
      $data['entity:node'] += $deafult;
    }
    if (isset($data['entity:taxonomy_term'])) {
      $data['entity:taxonomy_term'] += $deafult;
    }
    if (isset($data['entity:file'])) {
      $data['entity:file'] += $deafult;
    }
    if (isset($data['entity:user'])) {
      $data['entity:user'] += $deafult;
    }
    $profile->data = serialize($data);

    // Do the update.
    db_update('linkit_profiles')
      ->fields(array(
      'data' => $profile->data,
    ))
      ->condition('pid', $profile->pid)
      ->execute();
  }
}