You are here

function photos_update_7000 in Album Photos 7.3

Upgrade from D6 to D7.

File

./photos.install, line 344
Install, update, and uninstall functions for the Album Photos module.

Code

function photos_update_7000() {

  // @todo check existing variable sizes and create image styles with image_style_save()?
  // Set default styles.
  $size = array(
    array(
      'style' => 'thumbnail',
      'name' => 'Thumb',
    ),
    array(
      'style' => 'medium',
      'name' => 'Medium',
    ),
    array(
      'style' => 'large',
      'name' => 'Large',
    ),
  );

  // Update varialbes to use new sizes.
  variable_set('photos_size', $size);
  variable_set('photos_pager_imagesize', $size[0]['style']);
  variable_set('photos_thumb_imagesize', $size[0]['style']);
  variable_set('photos_display_teaser_imagesize', $size[0]['style']);
  variable_set('photos_display_list_imagesize', $size[1]['style']);
  variable_set('photos_display_full_imagesize', $size[1]['style']);
  variable_set('photos_display_view_imagesize', $size[2]['style']);
  variable_set('photos_name_0', $size[0]['name']);
  variable_set('photos_name_1', $size[1]['name']);
  variable_set('photos_name_2', $size[2]['name']);
  variable_set('photos_size_0', $size[0]['style']);
  variable_set('photos_size_1', $size[1]['style']);
  variable_set('photos_size_2', $size[2]['style']);
  variable_set('photos_slide_show_thumb', $size[0]['style']);
  variable_set('photos_slide_show_view', $size[2]['style']);

  // Delete unused varialbes.
  variable_del('photos_display_page_imagesize');
  variable_del('photos_display_page_viewnum');
  variable_del('photos_title_0');
  variable_del('photos_title_1');
  variable_del('photos_title_2');
  variable_del('photos_title_3');
  variable_del('photos_title_4');
  variable_del('photos_title_5');
  variable_del('photos_res_0');
  variable_del('photos_res_1');
  variable_del('photos_res_2');
  variable_del('photos_res_3');
  variable_del('photos_res_4');
  variable_del('photos_res_5');
  variable_del('photos_size_3');
  variable_del('photos_size_4');
  variable_del('photos_size_5');
  variable_del('photos_thumb_create_time');
  if (db_table_exists('x_album')) {

    // Drop all new empty tables.
    db_drop_table('photos_album');
    db_drop_table('photos_count');
    db_drop_table('photos_image');
    db_drop_table('photos_node');
    db_drop_table('photos_vote');

    // Rename existing tables.
    db_rename_table('x_album', 'photos_album');
    db_rename_table('x_count', 'photos_count');
    db_rename_table('x_image', 'photos_image');
    db_rename_table('x_node', 'photos_node');
    db_rename_table('x_vote', 'photos_vote');
  }

  // Move all image files to file_managed and add to file_usage.
  $query = db_select('photos_image', 'p');
  $query
    ->join('files', 'f', 'f.fid = p.fid');
  $query
    ->fields('p')
    ->fields('f');
  $result = $query
    ->execute();
  $basename = variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');
  $scheme = file_default_scheme() . '://';
  foreach ($result as $file) {
    if (isset($file->fid)) {
      $file->uri = $scheme . preg_replace('!^' . preg_quote($basename) . '!', '', $file->filepath);
      $file->uri = file_stream_wrapper_uri_normalize($file->uri);
      unset($file->filepath);
      db_merge('file_managed')
        ->key(array(
        'fid' => $file->fid,
      ))
        ->fields(array(
        'uid' => $file->uid,
        'filename' => $file->filename,
        'uri' => $file->uri,
        'filemime' => $file->filemime,
        'filesize' => $file->filesize,
        'status' => $file->status,
        'timestamp' => $file->timestamp,
      ))
        ->execute();
      file_usage_add($file, 'photos', 'node', $file->pid);

      // Delete from old files table.
      db_delete('files')
        ->condition('fid', $file->fid)
        ->execute();
    }
  }

  // @todo db_drop_table('files') if empty?
}