You are here

function socialmedia_update_7001 in Social media 7

Converts AddThis username to pubid & adds userid to profiles

File

./socialmedia.install, line 72
Install, update and uninstall functions for the widgets module.

Code

function socialmedia_update_7001() {

  // convert addthis username to pubid
  $record = db_select('socialmedia_profile', 'p')
    ->fields('p')
    ->condition('platform', 'addthis')
    ->execute()
    ->fetch();
  $record->data = unserialize($record->data);
  if (isset($record->data['username'])) {
    $record->data['pubid'] = $record->data['username'];
  }
  $record->data = serialize($record->data);
  drupal_write_record('socialmedia_profile', $record, 'smid');

  // create userid in standard profiles
  $pubs = array(
    'facebook',
    'flickr',
    'googleplus',
    'pinterest',
    'linkedin',
    'pinterest',
    'twitter',
    'vimeo',
    'youtube',
  );
  foreach ($pubs as $pub) {
    $result = db_select('socialmedia_profile', 'p')
      ->fields('p')
      ->condition('platform', $pub)
      ->execute();
    while ($record = $result
      ->fetchObject()) {
      $record->data = unserialize($record->data);
      if (isset($record->data['username'])) {
        $record->data['userid'] = $record->data['username'];
        $record->data = serialize($record->data);
        drupal_write_record('socialmedia_profile', $record, 'smid');
      }
    }
  }
}