Hi there,

I hope I'm not duplicating this issue #408088: Tokens not replaced in node output but you mentioned the need to create a new issue. I have changed the title and alt on my images using the new tokens but unless I open each node and save it again the new alt and titles aren't being adopted.

I've tried publishing all the nodes through the content section but that doesn't work. Is there a way of flushing (is that the right word?) all the alt and title tags?

Thanks

Thomas

Comments

Deciphered’s picture

Component: User interface » Code
Category: support » feature
Status: Active » Postponed

Hi Thomas,

I can certainly see the benefits of such a feature, and as it would be built on top of FileField Paths 'Retroactive changes' functionality it would actually be quite simple to implement.

However, there are a few issues that could be possible deal breakers:
- As with 'Retroactive changes', the module has to load in every single node of the content-type and reprocess them, which could potentially overload your server depending on the number of nodes.
- As the unprocessed version of the ALT and Title fields are not stored anywhere it would have to replace all ALT and Title fields with the new default which means any custom entries would be over-written.

I will keep the idea in mind and if I can come up with a solution I will look at implementing it.

Cheers,
Deciphered.

artscoop’s picture

Hi,

as you say, it would be a nice feature to have in Imagefield tokens.
I have some strange issue with all my nodes not having any Title or Alt Text.
And I've found out why : it's because I use Imagefield Import to create nodes.

So indeed, it would be great to overwrite these values.
Cheers

Deciphered’s picture

Hi artscoop,

I have just submitted a patch for ImageField Import to retain the ALT and Title defaults during import which allows it to work correctly with ImageField Tokens.
#435060: ImageField Data Defaults

As for this function, your interest is duly noted, but I still have to work out exactly how I will approach things.

Cheers,
Deciphered.

Deciphered’s picture

Status: Postponed » Fixed

Inherited functionality from the "Active updating" functionality just added to FileField Paths.

Cheers,
Deciphered.

Status: Fixed » Closed (fixed)

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

sammyman’s picture

Hi there. I am in the same situation. I have about 2000 tokens that I would like to "flush" so the new tokens are visible. Is there anyway to do this with content management filter or anything like that where I could automatically "edit" and save each node?

FiNeX’s picture

I've the same problem... with the only difference that I've about 5000 nodes to update... I've solved with an hand made script, but it could be useful to have an option to update alt and title tags on existing nodes.

FiNeX’s picture

Status: Closed (fixed) » Needs review

This is the script I've used to update my DB in order to update retroactively all titles and alts of the existing image field. In my specific case I've set the node title for both. If yuou have more complex tokens, you've to change a bit the script.

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$sql = "SELECT
  i.field_PUTS_YOUR_FIELD_NAME_HERE_data AS data,
  n.title AS title,
  i.vid AS vid,
  i.nid AS nid
FROM content_field_PUTS_YOUR_FIELD_NAME_HERE AS i
LEFT JOIN node AS n
ON (i.vid = n.vid AND i.nid = n.nid)";

$result = db_query($sql);
while ($row = db_fetch_object($result)) {
  $rowarray = unserialize($row->data);
  $rowarray['alt'] = str_replace("'", "", $row->title);
  $rowarray['title'] = str_replace("'", "", $row->title);
  $sql = "UPDATE content_field_immagine_vetrina_1
  SET field_PUTS_YOUR_FIELD_NAME_HERE_data = '" . serialize($rowarray) . "'
  WHERE nid=" . $row->nid . " AND vid=" . $row->vid . ";";
  if (!db_query($sql)) {
    print "Error updating nid: " . $row->nid . " - vid: " . $row->vid;
  }
}

Be careful, don't execute the script as is: edit it to match your fields. I suggest to add this script (or a more general one) on the docs, or adding a link to this thread on the main page of the module.

Bye

maartendeblock’s picture

The last part contains a few errors and will not work.

If you serialize an array { and } will be used. These are also used to replace table names in case a db_prefix is used. The correct code should be something like this:

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$sql = "SELECT
  i.field_PUT_YOUR_FIELD_NAME_HERE_data AS data,
  n.title AS title,
  i.vid AS vid,
  i.nid AS nid
FROM {content_type_PUT_YOUR_CONTENT_TYPE_HERE} AS i
LEFT JOIN {node} AS n
ON (i.vid = n.vid AND i.nid = n.nid)";

$result = db_query($sql);
while ($row = db_fetch_object($result)) {
	$rowarray = unserialize($row->data);
  $rowarray['alt'] = str_replace("'", "", $row->title);
  $rowarray['title'] = str_replace("'", "", $row->title);
  
  $sql = "UPDATE {content_type_PUT_YOUR_CONTENT_TYPE_HERE}
  SET field_PUT_YOUR_FIELD_NAME_HERE_data  = '%s'
  WHERE nid=%d AND vid=%d;";
  if (!db_query($sql, serialize($rowarray), $row->nid, $row->vid)) {
    print "Error updating nid: " . $row->nid . " - vid: " . $row->vid.'';
  }
}
cancerian7’s picture

Thanks maartendeblock. Your code worked.

JordanMagnuson’s picture

Title: Flushing old tokens » Retroactive Update functionality (ala Filefield Paths)
Status: Needs review » Active

Inherited functionality from the "Active updating" functionality just added to FileField Paths.

Cheers,
Deciphered.

This is great. Would it be possible to add "Retroactive updating" also, now that that functionality has been added to FileField Paths (which works great, I might add)? I have over 2000 nodes with images that have no alt or title tags, and I need to figure out some way to retroactively update them all... it seems like FileField Paths' method might easily be adopted for use with ImageField Tokens?

heyyo’s picture

If there is already title or alt defined it will be replaced by the node title, may be better to keep the existing alt title which should be more precise.

if (empty($rowarray['alt'])){
	 $rowarray['alt'] = str_replace("'", "", $row->title);
  }
  if (empty($rowarray['title'])){
	$rowarray['title'] = str_replace("'", "", $row->title);
  }
Cyberwolf’s picture

Subscribing.

Agileware’s picture

Also, with those scripts note that depending on your field the table might be
content_field_FIELDNAME
or
content_type_CONTENTTYPE

If it is a multiple value field or the field is used on multiple content types it will be the former, otherwise the latter.

Agileware’s picture

Also, if you are using a multiple value field you will also need to use the delta column in your sql queries to make sure everything is unique.

rickh’s picture

Hey guys, i'm pretty new to Drupal but I have a resonably large site that desperately needs this functionality. I'm not exactly sure how to implement the code above. Is it a patch/custom module or does it have to do with the databse itself. Know absolutley nothing about databses so any help would be greatly appreciated

13rac1’s picture

Status: Active » Closed (works as designed)

Retroactively resaving nodes can be done with: http://drupal.org/project/views_bulk_operations

A good description of resaving all nodes programmatically in D5 and D6 can be found here: http://www.templatezine.com/2010/06/drupal-re-save-all-site-nodes/

13rac1’s picture

Issue summary: View changes

...minor edit: converted the link pointing to the issue to the [#...] format.