You are here

function fb_devel_cron in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 fb_devel.module \fb_devel_cron()
  2. 6.2 fb_devel.module \fb_devel_cron()

Implements hook_cron().

Remove obsolete data from {users} table. Not a serious problem, just cruft in the database which should never have been saved. Clean it up.

File

./fb_devel.module, line 796
Makes development with Drupal for Facebook much easier. Keep this module enabled until you're confident your app works perfectly.

Code

function fb_devel_cron() {
  $limit = 10;
  $result = db_query_range('SELECT * FROM {users} WHERE data LIKE :as OR data like :iau OR data like :fbu', 0, $limit, array(
    ':as' => '%\\"app_specific\\"%',
    ':iau' => '%\\"is_app_user\\"%',
    ':fbu' => '%\\"fbu\\"%',
  ));
  foreach ($result as $account) {
    $data = unserialize($account->data);

    // Clean out the bogus data.
    foreach (array(
      'app_specific',
      'username',
      'fbu',
      'info',
    ) as $key) {
      unset($data[$key]);
    }
    db_update('users')
      ->fields(array(
      'data' => serialize($data),
      'uid' => $account->uid,
    ))->execute;

    /*
    db_query("UPDATE {users} SET data=:data WHERE uid=:uid",
             serialize($data), $account->uid);
    */
    if (fb_verbose()) {
      print t('Cleaned up data for user %name (%uid), it is now: !data', array(
        '%name' => $account->name,
        '%uid' => $account->uid,
        '!data' => '<pre>' . print_r($data, 1) . '</pre>',
      ));
    }
  }
}