You are here

function fb_app_update_7301 in Drupal for Facebook 7.3

Change app labels to all lower case.

File

./fb_app.install, line 97
Installs database tables and settings required by fb_app module.

Code

function fb_app_update_7301() {

  // This include some code specific to fb_connect.module (because easier to do here than fb_connect.install).
  $ret = array();
  $query = db_query("SELECT fba_id, label FROM {fb_app} ORDER BY fba_id");
  while ($app = $query
    ->fetchObject()) {

    //change label names to lowercase
    $label_old = $app->label;
    $label_new = strtolower($label_old);
    if ($label_old != $label_new) {

      // Change app name to lowercase.
      $ret[] = db_update('fb_app')
        ->fields(array(
        'label' => $label_new,
      ))
        ->condition('fba_id', $app->fba_id)
        ->execute();
      drupal_set_message(t("Changed fb application name from %label_old to %label_new. Please adjust any custom code or settings which rely on app's label.", array(
        '%label_old' => $label_old,
        '%label_new' => $label_new,
      )), 'warning');

      // begin fb_connect.module settings which use label.
      if (variable_get('fb_connect_primary_label', NULL) == $label_old) {

        // Primary label has changed.
        variable_set('fb_connect_primary_label', $label_new);
      }

      // fb_connect.module blocks.
      $variable_name_old = 'fb_connect_block_login_' . $label_old;
      $variable_name_new = 'fb_connect_block_login_' . $label_new;
      $variable_content = variable_get($variable_name_old, NULL);
      variable_del($variable_name_old);
      if ($variable_content) {
        variable_set($variable_name_new, $variable_content);
      }

      // change deltas of blocks
      $old_delta = 'login_' . $label_old;
      $new_delta = 'login_' . $label_new;
      $ret[] = db_update('blocks')
        ->fields(array(
        'delta' => $new_delta,
      ))
        ->condition('module', 'fb_module')
        ->condition('delta', $old_delta)
        ->execute();

      // end fb_connect.module settings.
    }
  }
  return $ret;
}