You are here

function imagefield_crop_update_7001 in Imagefield Crop 7

Same name and namespace in other branches
  1. 7.3 imagefield_crop.install \imagefield_crop_update_7001()
  2. 7.2 imagefield_crop.install \imagefield_crop_update_7001()

Install imagefield_crop table and migrate settings away from variables table.

File

./imagefield_crop.install, line 43

Code

function imagefield_crop_update_7001() {
  if (!db_table_exists('imagefield_crop')) {
    drupal_install_schema('imagefield_crop');
  }

  // Migrate the data out of the variables table.
  $crop_info = variable_get('imagefield_crop_info', array());
  if (!empty($crop_info)) {
    $txn = db_transaction();

    // Chunk the field inserts into rows of 100 to stay within any database
    // multi-insert limit.
    $chunks = array_chunk($crop_info, 100, TRUE);
    foreach ($chunks as $insert_data) {
      $insert = db_insert('imagefield_crop')
        ->fields(array(
        'fid',
        'x',
        'y',
        'width',
        'height',
      ));
      foreach ($insert_data as $fid => $values) {
        $values['fid'] = $fid;
        $insert
          ->values($values);
      }
      $insert
        ->execute();
    }
  }

  // Remove the imagefield_crop variable as its no longer needed.
  variable_del('imagefield_crop_info');
}