Hi,

Got a situation where I wish to update a bunch of Scald Image atoms, eg. we need to programmatically update the images for all the Scald Images on the system.

What I have done now is I fetched all the Scald Image entities with EntityFieldQuery and after that used scald_atom_load to load the objects. Then I updated the base_entity image url and filename + thumbnail url into a new one (an existing image and its path) and tried to use scald_atom_save on it.

For some reason, the atoms do not get updated but not receiving any error message either. Question is, is the scald_atom_save the correct function to use for updating an existing atom?

Comments

jcisio’s picture

I've just tested and don't have any problem. You even don't have to update the base_id because it will be synchronized with field_thumbnail.

My test that works (tested with the latest git):

$atom = scald_atom_load(10);
// 9 is fid of another file.
$atom->scald_thumbnail[LANGUAGE_NONE][0]['fid'] = 9;
scald_atom_save($atom);
gifad’s picture

For this simple task, I'd go directly to db_update the base_id field of scald_atoms table;

Am I wrong ?
(Besides caching issues...)

gifad’s picture

Yes, I was wrong, I forgot to manage the file_usage table;

Note that the snippet provided by jcisio works (no surprise), but, if the "old" file was not used by another module, it is deleted immediately, from file_managed table, and from disk !
This may be the desired effect, or not...

jcisio’s picture

Status: Active » Fixed

If you want to manipulate the database directly, you need to modify at the same time: 1/ the scald_atoms table for base_id, 2/ the field_thumbnail table 3/ the file_usage table.

And yes, the fact the unused files are deleted is a desired effect. At least, it is not a bug. More detail here #1399846: Make unused file 'cleanup' configurable.

Also, I think that this issue is fixed.

gifad’s picture

Thanks, jcisio, for the infos

Status: Fixed » Closed (fixed)

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