I would like to have a description field for images that can contain more than 128 characters. I read about the possibility to change the settings for the filefield description, but it was also suggested not to use that field. So now I'm thinking about using the title field (which seems to allow the use of a textarea) or a custom field created with the Imagefield Extended module. To do so, I need to copy the ALT texts of more than a 1000 images to the other field. But the information of those fields are not stored in separate database fields, but inside the 'field_image_data' in the 'content_field_foo' table. Can somebody tell me how I could copy existing data from the ALT field to either the title field or a custom field?

Using CCK 6.x-2.6 and Imagefield 6.x-2.3.

Comments

quicksketch’s picture

If you're familiar with PHP, you can write a small script and simply execute it in a PHP node or using the execute PHP block provided by the Devel module.

$result = db_query("SELECT vid, delta, field_field_data FROM {content_field_foo}");
while ($row = db_fetch_object($result)) {
  $data = unserialize($row->field_field_data);
  $data['title'] = $data['alt'];
  $data['alt'] = '';
  db_query("UPDATE {content_field_foo} SET field_field_data = '%s' WHERE vid = %d AND delta = %d", serialize($data), $row->vid, $row->delta);
}

I haven't checked this code at all, I'd highly suggest doing a database backup before running PHP code against your database.

yan’s picture

Status: Active » Fixed

Great, that works. Thanks! First I didn't realize that 'field_field_data' had to be adjusted, too (in my case: field_image_data). I used the same for a field made with the Imagefield Extended module (I called it 'description_text' and it allows formatting):

$result = db_query("SELECT vid, delta, field_image_data FROM content_field_image");
while ($row = db_fetch_object($result)) {

  $data = unserialize($row->field_image_data);

  $data['description_text']['body'] = $data['alt'];
  $data['description_text']['format'] = 1;
  $data['description_text']['style'] = 'formatted';
  $data['title'] = '';

  db_query("UPDATE content_field_image SET field_image_data = '%s' WHERE vid = %d AND delta = %d", serialize($data), $row->vid, $row->delta);
}
summit’s picture

Nice way for a database update switch! greetings, Martijn

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.