If I export the image styles that have the cropping dialog to a feature,
and on the production site I revert the styles to the feature code,
the cropping dialog doesn't let me switch between the different styles.

If I set the image styles to overridden status it works, but this is really not desirable on production environment.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pmelab’s picture

The dialog relies on "ieid" and "isid" database fields, which are not present if the style is loaded from code instead. There's got to be another unique identifier. Perhaps style-name, width and height?

olofbokedal’s picture

Status: Active » Needs review
FileSize
2.36 KB

Created a patch that will rely on the style name and effect id instead. Please try it out to see if this will work for you as well.

sebas5384’s picture

Hey! the patch #2 it works! thanks @ojohansson

But! there is a problem, all the crops already made with the Epsa Crop, ins't working anymore.
Thats a really big problem. I'm going look into it a little more deep, to see if i can help :)

Cheers,
Sebas.

sebas5384’s picture

Status: Needs review » Needs work
sebas5384’s picture

It seems that this coordinate isn't right:

{"epsacrop--":{"x":15,"y":12,"x2":340,"y2":243,"w":325,"h":231}}

Its really difficult to tell wich id of effect and preset's machinename belongs to.

I think that an hook_update_N() with some very heavy updates querys to the epsacrop_files table.
For example:

Before:
{"epsacrop--":{"x":15,"y":12,"x2":340,"y2":243,"w":325,"h":231}}

After:
{"epsacrop-6-product_full":{"x":15,"y":12,"x2":340,"y2":243,"w":325,"h":231}}

To me, this seems to be the only way to fix the problem, anyone haves some other ideas?

Cheers,
Sebas.

olofbokedal’s picture

The hook_update_N() way is the way to go. Every stored crop has to be updated to match the new identifier, which has changed from epsacrop-EFFECT_ID-STYLE_ID to epsacrop-EFFECT_ID-STYLE_NAME.

sebas5384’s picture

I'm trying to find a solution to make features work with features that doesn't break all the crops of my sites, but its really difficult to understand everything that is going on under these module(for my, ofcourse).

please, some dev ops help needed here :)

Thanks!
Sebas.

sebas5384’s picture

Well, the problem obviously is because of the missing ids, isid and ieid.
So I search and debug like hell and i found out that features.image.inc when is about to export the data of the image_style is removing those ids.

The thing is, if we apply the patch #2 all the previous cropped images won't work any more. And that is really, really, really bad when you have a site with more than 500 products, and other cropped images.

It seems that the only solution to this is a magical hook_update_N() to migrate the old crops.
And now the question is, whats the best way to do this?

We must do this before others sites appearing to have this problem to with features.

Cheers,
Sebas.

sebas5384’s picture

Status: Needs work » Needs review
FileSize
4.88 KB

Hey! finally I made the update process to the new format without the isid thing.

So I mixup the patch #2 and the hook_update_N(), and now its all working like a charm!

Please give it a test and let me know ;)

The changes are all for the 7.x-2.2 version, so if this gets aproved probably we have to make a patch against the dev branch.

Cheers!,
Sebas.

yvmarques’s picture

Great, I will try it !

Thanks

nyl_auster’s picture

Status: Needs review » Reviewed & tested by the community

Works like a charm :-)

Update works as expected; and now epsacrop work even if imagestyle are "default", exported by a feature.
Thanks sebas5384 !

nyl_auster’s picture

Status: Reviewed & tested by the community » Needs work

well, seems does not work if there is no coords to update. I guess batch is incorrect : it should stop when progress / max = 1; but with no results, it seems that last division get stuck with "0 : -1" for ever and ever. (and as progress incrementation is in foreach, nothing happens when result array is empty).

I'll try to solve this tomorrow.

nyl_auster’s picture

Status: Needs work » Needs review
FileSize
4.76 KB

To solve infinite batch issue when there is nothing to update in database; i just add to the patch above :

if (!$result) {
  return;
}

I attached the full working patch.

cmalek’s picture

Has this branch been ported to the -dev branch yet?

cmalek’s picture

Nevermind, http://drupal.org/files/crop_style_from_code-1396500-8.patch seems to apply cleanly to the latest -dev download.

JesseDP’s picture

Overhere the update hook never dissapears.

I changed this line:

    $sandbox['max'] = count($result) - 1;

to

    $sandbox['max'] = count($result);
mattsmith3’s picture

@ http://drupal.org/files/crop_style_from_code-1396500-8.patch
That patch had absolute paths in it. Here's another copy with out.

Here's another without those. Same patch...

mattsmith3’s picture

Still isn't working for me. It looks like the dialog is storing the crop areas but they aren't showing on display.
Edit: For existing installs, you have to disable and re-enable epsacrop. In my case, I had to re-add existing content too. Only new nodes worked.

olofbokedal’s picture

Modified the patch from #17, which now removes both the effect id and style id from the naming convention.

If the image style exists in code, both the image style and its effects will be missing from the database, causing both style id and effect id to be NULL. I can't see a reason to keep the effect id, since there's no use case where you'd like to have multiple epsa crop effects for the same style?

I've modified the same update function from #17. It now makes sure that it could find a machine name for the image style, otherwise it won't get saved to the database. I've also removed the sandbox variable, since it caused the update function to stall.

ygerasimov’s picture

Status: Needs review » Reviewed & tested by the community
dagomar’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
6.51 KB

Modified the patch in 19, I experienced an undefined index in case no cropping was selected.

nagy.balint’s picture

Tested #21.
Seems to work fine.
Created a new patch without the whitespace problem, and applied for latest dev.
Would be nice to get this commited somehow, as on most sites the image styles are in features, which makes this a major issue indeed.

Aron Novak’s picture

Status: Needs review » Reviewed & tested by the community

Tested #22, works correctly and applies cleanly.

wesleydv’s picture

Issue summary: View changes

#22, works on latest dev, should be committed

yvmarques’s picture

I have committed the patch #22, thanks for it.

yvmarques’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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

coredumperror’s picture

Status: Closed (fixed) » Needs work

The update function from this patch is both badly buggy and utterly terrifying, and should be uncommitted ASAP. Here's why:

1) The big problem is that db_delete() call. It's completely crazy to delete your users' crops if the conversion failed. Thank goodness that code path won't be followed if there were any coords set up for the image in question (because $new_coords won't be empty), or the crops for several thousand images on my site would have been erased with no way to recover them.

2) The code that changes old crop keys to the new format doesn't work on my site. I don't know why, but my site's old crop keys looked like "epsacrop--

", rather than the format of "epsacrop---" which the code appears to expect. That means that the conversion failed to convert my site's crop records. 3) The if ($style['isid'] == $isid) check causes a PHP error, because $style['isid'] doesn't exist. That problem stems from the difference in output format between the Drupal API functions image_styles() and image_style_load(). The first one returns all image style data in an associative array keyed by isid, while the second returns one image style's data with an 'isid' element in the output. This update function appears to expect the output from image_style_load(), but what it actually gets is the output from image_styles(), because that's what _epsacrop_load_styles() calls. This means the check for $style['isid'] will never work, and will always throw an error. 4) It's explicitly stated in the docs for drupal_write_record() that it should never be called in an update hook, due to the schema not necessarily being in a solid state during the update process. That line should be a call to db_update() instead. I wrote a custom script that does what this update hook was supposed to do, and I could adapt it to a replacement patch for EPSACrop if you like.
yvmarques’s picture

I would be grateful if you could share your work, I got great points and if we fix it soon as possible it would be great. Thanks.

coredumperror’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
FileSize
3.71 KB

OK, here's a patch against the current dev version which adds a new update hook that uses the technique that my script uses. It also erases the code from the old, broken hook. Doing it this way (rather than just replacing the code in the broken hook), ensures that people who've already updated to the latest dev get the new hook when they update again and run the update script, and that people who haven't yet updated to the latest dev will not be given the broken code when they update now.

joelhsmith’s picture

On my local copy of my site, I installed the dev version (2014-Mar-13) of EPSA Crop and applied #30. All my custom Image Styles got deleted. And all the images that relied on the Images Styles got resized. Its a huge site so there could be other issues at play.

So have a backup your sites before playing. :-)