You are here

function migrate in Taxonomy Image 5

1 call to migrate()
update_term_images.php in contributed/update_term_images.php

File

contributed/update_term_images.php, line 55

Code

function migrate() {
  global $term_dir;
  $completed = array();
  $names = $_POST['edit']['migrate'];
  foreach ($names as $name => $status) {
    $files = file_scan_directory($term_dir, $name);
    if (count($files) != 1) {
      print count($files) . " files match the name: {$name}";
      exit;
    }
    $image = array_pop($files);
    $image->filename_orig = $image->filename;
    if ($status == 1) {
      $image->tid = migrate_term_image_get_tid($image->name);
      if (!taxonomy_get_term($image->tid)) {
        print "cant find the tid: {$tid}";
        exit;
      }
      $t_i_image = db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid = %d', $image->tid));
      if ($t_i_image) {
        $term->has_image = true;
      }
      if ($term->has_image) {
        taxonomy_image_delete($image->tid);
      }
      if (file_copy($image->filename) != 1) {
        print "couldnt copy file: {$image->filename} to new location";
        exit;
      }
      db_query("INSERT INTO {term_image} (tid, path) VALUES (%d, '%s')", $image->tid, $image->filename);
      $completed[] = $image;
    }
    if ($_POST['edit']['delete'][$name] == 1) {
      file_delete($image->filename_orig);
      $deleted[] = $image;
    }
  }
  if ($c = count($completed)) {
    print "Updated {$c} terms";
  }
  else {
    print "No terms updated";
  }
  if ($c = count($deleted)) {
    print "Deleted {$c} node_image(s)";
  }
  else {
    print "No images deleted";
  }
}