BoldMinded acquires Ansel, support ending for all add-ons. BoldMinded acquires Ansel, support ending for all add-ons. Read More →
Support has been discontinued. Issues remain available as an archive. Support has been discontinued. Issues remain available as an archive.
When saving image, Craft CMS gives "Trying to get property of non-object"
#11 opened by Thierry Fortier
Description
Solution:
Ansel for Craft 1.0.1 has been released.
<strike>Use this beta version of 1.0.1 of Ansel. You may have to manually clean up the directories. The problem was Ansel was using sourceId
rather than folderId
in many places and this led to Ansel uploading files to the wrong directories, hidden directories, and a whole lot of other badness.</strike>
<strike>One of the problems too is if the PHP errors caused the creation of a directory Ansel needs on Google Cloud storage, but the error caused the folder to never be saved to the database, Craft will run into errors trying to create that folder again because it already exists on Google Cloud Storage. This is actually a Craft problem and there's not anything I can do about it. You can try re-indexing, or you can delete the directory on Google Cloud and let Craft re-create it.</strike>
I have an Ansel field in a global. It is set to hold one image, not allow more than one and is not constrained to JPG.
In the log I can find this :
******************************************************************************************************
2017/04/14 17:55:59 [error] [php] Trying to get property of non-object (/home/runcloud/webapps/news/releases/1492182594/craft/plugins/ansel/Service/AnselImages/SaveRowService.php:228)
Stack trace:
#0 /home/runcloud/webapps/news/releases/1492182594/craft/plugins/ansel/fieldtypes/Ansel_AnselFieldType.php(214): BuzzingPixel\Ansel\Controller\Field\FieldSaveController->save()
#1 /home/runcloud/webapps/news/releases/1492182594/craft/app/services/ElementsService.php(1618): Craft\Ansel_AnselFieldType->onAfterElementSave()
#2 /home/runcloud/webapps/news/releases/1492182594/craft/app/services/GlobalsService.php(408): Craft\ElementsService->saveElement()
#3 /home/runcloud/webapps/news/releases/1492182594/craft/app/controllers/GlobalsController.php(187): Craft\GlobalsService->saveContent()
#4 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/web/actions/CInlineAction.php(49): Craft\GlobalsController->actionSaveContent()
#5 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams()
#6 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/web/CController.php(286): Craft\GlobalsController->runAction()
#7 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/web/CController.php(265): Craft\GlobalsController->runActionWithFilters()
#8 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/web/CWebApplication.php(282): Craft\GlobalsController->run()
#9 /home/runcloud/webapps/news/releases/1492182594/craft/app/etc/web/WebApp.php(817): Craft\WebApp->runController()
#10 /home/runcloud/webapps/news/releases/1492182594/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#11 /home/runcloud/webapps/news/releases/1492182594/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#12 /home/runcloud/webapps/news/releases/1492182594/craft/app/index.php(62): Craft\WebApp->run()
#13 /home/runcloud/webapps/news/releases/1492182594/public/index.php(19): require_once()
REQUEST_URI=/craft/globals/aPropos
The line mentionned is this one :
// Add the image to assets
$highQualUploadResponse = $this->assetsService->insertFileByLocalPath(
$highQualImage,
$builtName,
$folder->id, # This is line 218
AssetConflictResolution::KeepBoth
);
Since I have sentry.io hooked into craft, I could extract this from it :
{
action: globals/saveContent,
CRAFT_CSRF_TOKEN: R0NCt9eBssJydQ4Us0b4dWDIldoowsKdFxPgenq4|2cdd27d15fcfa748370bb2440f9bb00fdb6da01a,
fields: {
logo: {
anselRowId84176326657: {
anselImageDelete: ,
anselImageId: 0,
caption: ,
fileLocation: ,
height: 2160,
order: 1,
sourceFileId: 15,
title: Logo,
width: 2160,
x: 840,
y: 0
},
placeholder: placeholder
},
regionMeteo: Gatineau, QC
},
locale: fr_ca,
setId: 11
}
Replies
- TJ Draper
Replied 4/14/2017 2:57 PM, Edited 4/18/2017 11:42 AM
Hi Thierry,
That's odd. I’ll be looking into this as soon as I can and I’ll let you know if I have any trouble duplicating.
- TJ Draper
Replied 4/15/2017 11:15 AM, Edited 4/18/2017 11:42 AM
Hi Thierry,
I’m really sorry about this issue. I made some mistakes and mixed up source IDs and folder IDs in some instances — which is an under-the-hood technicality in Craft on how Assets work.
I was not able to duplicate that exact issue you described — HOWEVER, I was able to run into all kinds of issues and I believe the root cause would also cause the errors you were seeing. I’ve added a solution to this issue. Could you test it out and let me know how it goes?
- TJ Draper
Replied 4/17/2017 7:15 PM, Edited 4/18/2017 11:42 AM
Hi Thierry,
Have you had a chance to try the fix? Given the nature of this issue, I’d like to get the release out as soon as possible but I was hoping from some feedback from the field.
- Thierry Fortier
Replied 4/18/2017 6:42 AM, Edited 4/18/2017 11:42 AM
Hi TJ,
Sorry for the delayed response. With Easter and the few days off I managed to disconnect quite well it seems.
Anyhow, I just uploaded the new package and I get the same error but the line number changed :
2017/04/18 11:35:54 [error] [php] Trying to get property of non-object (/home/runcloud/webapps/news/releases/1492193728/craft/plugins/ansel/Service/AnselImages/SaveRowService.php:221)
I should add I'm using the chooseAnExistingAsset button and not the drag and drop, as I was when the bug first occured.
- Thierry Fortier
Replied 4/18/2017 7:32 AM, Edited 4/18/2017 11:42 AM
So I did a clean install of the plugin and used two brand new Google "buckets". I had cleaned out the old ones, but I figured a fresh start could not hurt.
I got a different message : File type not allowed (/craft/app/assetsourcetypes/GoogleCloudAssetSourceType.php:412)
Then trying once more with the same image : got the good old Trying to get property of non-object (/ansel/Service/AnselImages/SaveRowService.php:221)
- Thierry Fortier
Replied 4/18/2017 7:40 AM, Edited 4/18/2017 11:42 AM
Hi, me again. After the "Filetype not allowed" error, the folder is created on google cloud which is probably why I get a "Trying to get property of non-object" afterward.
- Thierry Fortier
Replied 4/18/2017 8:03 AM, Edited 4/18/2017 11:42 AM
Sorry for the spam. I dug a little and when I get "Extension not allowed" the extension is : jpg?mtime=20170414135011
I don't know who or what adds the ?mtime=20170414135011 to jpg but it's probably part of the issue.
- TJ Draper
Replied 4/18/2017 8:12 AM, Edited 4/18/2017 11:42 AM
I am out of the office for a dentist appointment this morning but with this information I'll look at this issue as soon as I can.
From the line where you referenced the extension not allowed error, it looks like it's coming from Craft itself? Very odd.
- Thierry Fortier
Replied 4/18/2017 8:16 AM, Edited 4/18/2017 11:42 AM
Yeah, craft is checking anything you upload to an asset folder to make sure the extension is part of it's "Allowed extensions" list.
I added an output to the Craft error message to make it show the extension rejected and that's how I got the "jpg?mtime=20170414135011".
I'll keep digging and if I find anything relevant I'll post it so you canr eview it when you are available once again.
- Thierry Fortier
Replied 4/18/2017 9:34 AM, Edited 4/18/2017 11:42 AM
Alright.
When you fetch an image from Google Cloud (and presumably Amazon s3) the url has ?mtime=something appended to it.
Ansel works with that allthe way up to the moment Craft saves it but Craft does not recognize that URL.
I was able to avoid any error message by changing the line #168 of /ansel/Service/AnselImages/SaveRowService.php
Instead of this :
$filePathForCache = $fileModel->url;
It now reads :
$filePathForCache = strtok($fileModel->url, '?');
Of course I have no clue as to what it may break further down, but the image got saved and from an end user point of vie, it looks like it works.
Hope that helps.
- TJ Draper
Replied 4/18/2017 11:07 AM, Edited 4/18/2017 11:42 AM
Got it. I did not have cache time settings set on my test Assets sources, now that I do, I was able to duplicate the issue.
I did not want to remove the cache query string for downloading the file but I do want to remove it for caching it locally so I made some changes in the cache service.
I’ve changed the solution attachment above to 1.0.1-beta.2 which should resolve the issue.
- Thierry Fortier
Replied 4/18/2017 11:13 AM, Edited 4/18/2017 11:42 AM
Hi TJ,
Seems to be working fine now.
Thanks!
- TJ Draper
Replied 4/18/2017 11:41 AM, Edited 4/18/2017 11:42 AM
Ansel for Craft 1.0.1 has been released. https://buzzingpixel.com/software/ansel-craft/changelog/1-0-1