I got that message during upgrade.
Maybe we have to just change line 16 of taxonomy_image.install from:

  $query = db_select('term_image')

to:

  $query = db_select('term_image', 't')
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mandreato’s picture

After that, I get other errors:

The update process was aborted prematurely while running update #7000 in taxonomy_image.module.

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: .../update.php?op=selection&token=...-uHA&id=219&op=do StatusText: OK ResponseText: Fatal error: Cannot use object of type DatabaseConnection_mysql as array in ...\sites\all\modules\taxonomy_image\taxonomy_image.install on line 43

Strict warning: Only variables should be passed by reference in update_results_page() (line 171 of ...\update.php).

apratt’s picture

I'm getting the same types of errors. I guess this really is dev stuff - not even beta. What I'm wondering is how the field gets associated with the content type. It appears to me that it needs to be intantiated. I'll try and dig into this whole fields in core thing today since I'm not eager to manually recreate 3,000 taxonomy images. Maybe Joachcim's field convert is the way to go. It looks really comprehensive and it worked well for my image migration.

Niklas Fiekas’s picture

Status: Active » Needs review

I want to give this another blind stab before I go look at it more closely: http://drupalcode.org/project/taxonomy_image.git/commitdiff/725d975.

Thanks a lot @mandreato for testing and the excellent error reports. Sorry for the delay. I wasn't subscribed to all issues.

@apratt: Field convert would probably be a good alternative. Help on this is appreciated :)

mandreato’s picture

I've retried a full D6 --> D7 upgrade and I get a different message now:

Update #7000
Failed: FieldException: Attempt to create an instance of field taxonomy_image without a bundle. in field_create_instance() (line 464 of ...\modules\field\field.crud.inc).

mandreato’s picture

$term->vocabulary_machinename

is the cause of missing bundle and it should be corrected into the following:

$term->vocabulary_machine_name

Niklas Fiekas’s picture

Good catch, thanks mandreato! Committed and pushed http://drupalcode.org/project/taxonomy_image.git/commitdiff/c6b68a1. Does this fix the upgrade path or are there more issues?

mandreato’s picture

We're getting closer, step by step, but there is another problem: after applying fixes and upgrading, the taxonomy terms have empty images and I get an error if I try to delete/replace them:

File ... could not be deleted because it is not a valid URI. This may be caused by improper use of file_delete() or a missing stream wrapper.

I think that a better manage of URI it is needed during conversion, but I'm not an expert... Maybe the Ubercart catalog module would be a good example, since it does similar upgrade --> see uc_catalog.install

Niklas Fiekas’s picture

Thanks again.

Maybe this is enough for our purpose (?):

-    $file->uri = $row['path'];
+    $file->uri = file_build_uri($row['path']);

Next I should really setup a test site with some images myself.

mandreato’s picture

I've retried, now there is another problem:

Update #7000
Failed: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://_A_FILE_NAME_.png' for key 'uri': INSERT INTO {file_managed} (uri, filesize, status, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => public://_A_FILE_NAME_.png [:db_insert_placeholder_1] => 303411 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => 1336889803 ) in drupal_write_record() (line 7013 of ...\includes\common.inc).

Maybe this is due to the fact that some taxonomy term on my site uses the same image filename as of certain products (nodes).
For example:
- node A has the image filename imageA.png stored in ...\sites\default\files
- taxonomy term A has the same image filename imageA.png stored in ...\sites\default\files\category_pictures
This is similar to #1176186: D6 -> D7 upgrade: Duplicate files cause Integrity constraint violation: 1062 Duplicate entry 'xx' for key 'PRIMARY' so I think I can resolve it by forcing a unique filename for every taxonomy term...

mandreato’s picture

I've retried again, after deleting all image name duplications.
Now there is another kind of problem:

Warning: filesize() [function.filesize]: stat failed for public://_A_FILE_NAME_.png in file_save() (line 570 of ...\includes\file.inc).

mandreato’s picture

FYI I was able to merge logic from uc_catalog.install into the following taxonomy_image.install and it worked !


/**
 * @file
 * Update functions for the taxonomy_image module.
 */

/**
 * Upgrades field data from the Drupal 6 version.
 */
function taxonomy_image_update_7000(&$context) {
  if (!db_table_exists('term_image')) {
    return;
  }

  $query = db_select('term_image', 't')
    ->fields('t', array('tid', 'path'));

  // Initiliaze by creating the field and counting the entries.
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = $query->countQuery()->execute()->fetchField();
    $sandbox['last_tid'] = -1;

    if (!field_info_field('taxonomy_image')) {
      field_create_field(array(
        'field_name' => 'taxonomy_image',
        'type' => 'image',
        'cardinality' => 1,
        'translatable' => TRUE,
        'entity_types' => array('taxonomy_term'),
      ));
    }
  }

  // Select ten rows at a time.
  $result = $query
    ->orderBy('tid', 'ASC')
//    ->range(0, 10)
    ->condition('tid', $sandbox['last_tid'], '>')
    ->execute();

  // Upgrade each row.
  while($row = $result->fetchAssoc()) {
    $rows_exist = TRUE;

    // Load the term.
    $term = taxonomy_term_load($row['tid']);
    if (!$term) {
      continue;
    }
    $bundle = $term->vocabulary_machine_name;

    // Ensure the taxonomy_image field is instanciated.
    if (!field_info_instance('taxonomy_term', 'taxonomy_image', $bundle)) {
      field_create_instance(array(
        'field_name' => 'taxonomy_image',
        'entity_type' => 'taxonomy_term',
        'label' => t('Image'),
        'bundle' => $bundle,
        'description' => t('The image of this term.'),
        'required' => FALSE,
        'widget' => array(
          'type' => 'image_image',
        ),
      ));
    }

    $files = db_query_range('SELECT tid, f.fid, uid, filename, filepath AS uri, filemime, filesize, status, timestamp FROM {term_image} ti inner join {files} f on f.filename = ti.path where tid = :current', 0, 500, array(':current' => $row['tid']), array('fetch' => PDO::FETCH_ASSOC));
    $basename = variable_get('file_directory_path', conf_path() . '/files');
    $scheme = variable_get('file_default_scheme', 'public') . '://';

    foreach ($files as $file) {
      // Get term id for the image.
      $tid = $file['tid'];
      // Don't break the insert query with extra data.
      unset($file['tid']);

      $file['uri'] = $scheme . str_replace($basename, '', $file['uri']);
      $file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
      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();

      // Add the usage entry for the file.
      file_usage_add((object) $file, 'file', 'taxonomy_term', $tid);

      $term = (object) array(
        'tid' => $tid,
        'taxonomy_image' => array(
          LANGUAGE_NONE => array(
            0 => array(
              'fid' => $file['fid'],
            ),
          ),
        ),
      );

      _update_7000_field_sql_storage_write('taxonomy_term', $bundle, $term->tid, NULL, 'taxonomy_image', $term->taxonomy_image);

      $sandbox['message'] = check_plain($file['filename']);
    }

    // Increase counters.
    $sandbox['progress']++;
    $sandbox['last_tid'] = $term->tid;
  }

  // Finalize.
  if (empty($rows_exist)) {
    db_drop_table('term_image');
    return t('Taxonomy image field data has been migrated. Settings must be adjusted manually.');
  }
  else {
    $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
  }
}

Niklas Fiekas’s picture

Sounds awesome. Thanks mandreato. Can you upload a patch?

mandreato’s picture

See the attached patch. Warning: newbie here !

Niklas Fiekas’s picture

Status: Needs review » Needs work

Thanks again. The patch looks good except a few whitespace issues and line breaks, but I can fix that myself.

I am a bit worried about this one:

+++ b/taxonomy_image.installundefined
@@ -1,94 +1,126 @@
+//    ->range(0, 10)

Does that mean we would no longer page the query, but instead try to import all files at once? That might exceed execution time, when there are lots of rows.

mandreato’s picture

I tried to keep the range statement, but it caused to process only 10 records. Keep in mind that I'm not an expert in PHP... So, since I have <200 terms, I preferred to work them all together.

splash112’s picture

New patch, mostly based on the work of mandreato

- made sure image module is enabled
- batch.api working
- tried to clean up some mess with duplicate file entries from drupal 5 #1260938: d6 to d7 update fails on file duplicates '#7061 Integrity constraint violation'

Somehow, some of the images are not in the files table and will not get upgraded. Rest seems to work pretty ok.

splash112’s picture

Status: Needs work » Needs review
splash112’s picture

New version, should now upgrade as much information as possible

splash112’s picture

too late for me tonight. Just a small bugfix. All images not in the files directory should be attached as well.

mandreato’s picture

Status: Needs review » Reviewed & tested by the community

I've done another upgrade cycle with patch #19 and all taxonomy images were managed correctly.
Thanks !

tjharman’s picture

My upgrade from D6-D7 didn't carry across all the images.
I've been running my D7 site in production for a while now, so I can't roll it back.

Is there some way to trigger the taxonomy_image upgrade again though?

Disabling and re-enabling the module doesn't work. Now I've applied the patch in #19 I'd like to try again in the hope all my images follow me this time.

Thanks!

tjharman’s picture

Just a re-ask of the #21.
Would like to "try again" but can't see seem to trigger the upgrade attempt.

GStegemann’s picture

How about setting the schema_version in the system table of this module to something lower than 7000 and running update.php again?