ThorntonStuart / SimpleCloner

An entry cloning module compatible with EE3
5 stars 3 forks source link

Issues with Ansel when deleting a cloned entry #8

Open mvdesign opened 7 years ago

mvdesign commented 7 years ago

I'm using EE 3.5.5, Ansel 2.0.3, and Simple Cloner 1.2.0. I first experienced this issue on a development site, but I was able to recreate it with a clean install of EE with only Ansel and Simple Cloner installed.

Here's the issue: I have a channel with an Ansel field. I have a simple template that calls the image URL for the Ansel field. When I create an entry (EntryA) and add an image to the Ansel field, the template displays the URL properly. When I clone the entry in Simple Cloner (EntryA-Clone), the template displays the URL properly for both entries. But if I delete EntryA-Clone, the template breaks and generates a Fatal Error. The template remains broken until I open the EntryA, remove the image(s) from the Ansel field, save the entry, and then relink the image(s) within the Ansel field. Once I do that, the template again displays the image URL properly.

Here are the error messages that I get:

Undefined offset: 149
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 306
Severity: E_NOTICE

Notice
Undefined offset: 12
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 308
Severity: E_NOTICE

Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 365
Severity: E_NOTICE

Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 365
Severity: E_NOTICE

Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 367
Severity: E_NOTICE

Fatal error: Uncaught Error: Call to a member function getUrlSafeParam() on null in /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php:367 Stack trace: 
#0 /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php(217): BuzzingPixel\Ansel\Service\AnselImages\ImagesTag->setVariablesFromRecord(Object(BuzzingPixel\Ansel\Record\Image)) 
#1 /path/to/system/user/addons/ansel/Controller/Field/ImagesTag.php(121): BuzzingPixel\Ansel\Service\AnselImages\ImagesTag->getVariables() 
#2 /path/to/system/user/addons/ansel/ft.ansel.php(762): BuzzingPixel\Ansel\Controller\Field\ImagesTag->parse(Array, '\n\t Small: {i...') 
#3 /path/to/system/ee/legacy/libraries/api/Api_channel_fields.php(409): Ansel_ft->replace_tag('{"placeholder":...', Array, '\n\t Small: {i...') 
#4 /path/to/system/ee/legacy/libraries/channel_entries_parser/components/Custom_field_pair.php(203): in /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php on line 367

I opened a support ticket with TJ at BuzzingPixel, and here is his explanation for what he thinks might be happening:

It sounds like Simple Cloner is duplicating the exp_ansel_images table rows but not creating the images themselves, but rather pointing back to the images Ansel created for the original field/entry.

The way Ansel works is that the original image is uploaded to the specified directory for source images, then that image is manipulated according to the field settings and crop lasso and saved as a new image. That image that Ansel manipulated and created is considered “owned” by the originating field. As such, if the image row is deleted, or the entry or owning element is deleted, the manipulated image is deleted. In the case of Simple Cloner (from what it sounds like it is doing), if it’s just duplicating the table rows in exp_ansel_images, then when you delete one of the image rows or entries, Ansel deletes the image because of the assumed ownership of the image. Thus that image goes missing for the other entry.

The last time I looked at Simple Cloner, it looked like it was doing a lot of procedural work, direct database calls and so forth. What would be ideal would be for Simple Cloner to prep the data that Ansel expects on entry submission, then run Ansel’s field type methods for the new entry. Failing that, Simple Cloner will need to duplicate the manipulated image for each image row in the containing element (entry), add it to the EE (or Assets or Treasury) file manager in the appropriate way, and then update the IDs in the duplicated exp_ansel_images table row to point to the new image.

Please let me know if you have any other questions about my setup. Thanks for your time.

ThorntonStuart commented 7 years ago

After studying the code today, here is what I believe is happening. The support for duplicating entries was provided in v1.2.0 which coincided with building in support for the EEHarbor module Assets. I believe the contributor who built this functionality was using Assets to handle the images created by Ansel and as a result built this compatibility to work with Assets but not with the EE file manager (which from I conversation I believe you are using?). I am getting to work now on building the file manager compatibility, I'm hoping I can get it pushed by the end of the week.

mvdesign commented 7 years ago

Thanks for looking into this, Stuart. I am indeed using the EE file manager. I look forward to seeing what you are able to figure out. Let me know if you need my help with testing.

mvdesign commented 7 years ago

@matthewjohns0n Would you be willing to chat with me briefly about this issue? My email address is matt [at] dsite dot com. Thanks!