Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image/logo upload is not working #1

Closed
djzwerg opened this issue Sep 21, 2021 · 24 comments
Closed

Image/logo upload is not working #1

djzwerg opened this issue Sep 21, 2021 · 24 comments
Labels
bug Something isn't working

Comments

@djzwerg
Copy link

djzwerg commented Sep 21, 2021

After uploading a jpg file this error occurs:

Argument 1 passed to file_usage_add() must be an instance of File, int given, called in /pathtobackdrop/modules/webform2pdf/includes/webform2pdf.settings.inc on line 1270

A mail will be created but does not contain the PDF (only crypted text). --> new issue #3

@bugfolder
Copy link
Collaborator

Can you be more specific about where you are uploading a .jpg file? From the line number you quoted, it looks like you're saving a logo file in the header or footer. Is that right?

@djzwerg djzwerg added the bug Something isn't working label Sep 21, 2021
@djzwerg djzwerg changed the title Not working Image/logo upload is not working Sep 21, 2021
@bugfolder
Copy link
Collaborator

So, I just tried this (uploading a .jpg image to the left side in the PDF header section for a new webform) and encountered no error; it saved properly.

Perhaps check the file permissions in your files directory? The uploaded file should be stored in files/webform2pdf.

Can you add a file component to your test webform and specify that directory as the destination for the component? Then see if submitting the webform with a file component is stored properly.

@djzwerg
Copy link
Author

djzwerg commented Sep 21, 2021

@bugfolder it's not possible to change the file component's direction from files/webform/ to files/webform2pdf/ because it is hard-coded. The permissions were set to 775 and the files are still there but nothing to see at the pdf file.

@bugfolder
Copy link
Collaborator

So the logo file was uploaded fully? It's in the directory and its thumbnail shows on the Webform2PDF settings page (in the same section where you uploaded it)?

@djzwerg
Copy link
Author

djzwerg commented Sep 21, 2021

Yes it is in that folder but no its thumbnail won't be shown.

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

I've tried that again on a clean Backdrop site and the issue is still there.

  • Backdrop: 1.20.0
  • Webform: 1.x-4.24.1
  • Webform2pdf: 1.x-4.1.0

@bugfolder
Copy link
Collaborator

One more thing to check (to determine whether it's a problem with mail or with PDF generation).

View one of the submissions and click on the "Download PDF" tab, which should take you to a page like http://example.com/node/4/submission/1/downloadpdf, which should include the logo image. If it's showing up there but not in mail, then it's a mail problem; if it's not showing up there, then it's a problem with the PDF generation.

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

The PDF doesn't contain the logo. I think the issue occurs between physical file upload and using it within the field.

@bugfolder
Copy link
Collaborator

Yes. This helps to establish, though, because it's easier to debug that part of the chain.

Are you comfortable using the Devel module and/or editing PHP to debug? It would be helpful to install and enable Devel, and then insert this line in webform2pdf.settings.inc just before the problematic call to file_usage_add():

dpm($file, '$file');

It's a puzzle because I can't reproduce this error on my test site.

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

@bugfolder I've done and this is the result:
grafik

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

At the Backdrop log:

Notice: Trying to get property 'fid' of non-object in _webform2pdf_save_logo() (line 1272 von /pathtobackdrop/modules/webform2pdf/includes/webform2pdf.settings.inc).

@bugfolder
Copy link
Collaborator

Yup, I'd expect that based on the debug report you showed. Thanks for that, it helps.

So it looks like (at liine 1267) file_move() is returning a status code rather than a file object.

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

I'm glad that this would help. Looking forward to test code changes :)

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

While searching for the debug notice I found that issue.
So I thought maybe it would help to change the line 1270 like this:

 	  if (is_object($file)) {
		file_usage_add($file, 'webform2pdf', $logo, $nid);
		}

I've tried but that doesn't solve this issue. So file_remove() maybe causes this.

@bugfolder
Copy link
Collaborator

Hmm. Turns out I have a pending update that addresses that issue that just hadn't been applied yet. (So I've been using the dev version, which is why I'm not seeing the issue, and you are seeing it. D'oh!) Sit tight, let me get these fixes into a new release version and we'll take it up again.

@bugfolder
Copy link
Collaborator

OK, I've pushed a commit that should at least get us seeing consistent things. Would you download the current development version (from here, using the green "Code" button) and give it a try?

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

Great! It works! Thanks a lot!

@bugfolder
Copy link
Collaborator

Great! Bugfix release to follow shortly.

@djzwerg djzwerg reopened this Sep 22, 2021
@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

Sorry I have to reopen this issue. Now it is not possible to delete an uploaded image:
grafik

@djzwerg
Copy link
Author

djzwerg commented Sep 22, 2021

The Backdrop log file show up two messages:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DefaultEntityController->load() (line 230 of /backdrop/core/modules/entity/entity.controller.inc).

Recoverable fatal error: Object of class File could not be converted to string in DatabaseStatementBase->execute() (line 2284 of /backdrop/core/includes/database/database.inc).

@bugfolder
Copy link
Collaborator

OK, let me go check it out.

@bugfolder
Copy link
Collaborator

Well, I can reproduce this. (So this gives me something to work on.)

@bugfolder
Copy link
Collaborator

@djzwerg, first, apologies for letting so much time pass — I lost track of this issue being open. Just found it (again). There have been a couple of releases since this issue arose, and just trying out the current version, I'm no longer able to reproduce this issue (uploading a logo file, saving, then trying to delete it). Would you try the latest release and see if you still experience the problem?

@bugfolder
Copy link
Collaborator

Since there was no further response on this, I'm closing the issue. But if it reappears (using the current release version), please do feel free to reopen or post a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants