I get the following error when loading an FAQ node.
Warning: Invalid argument supplied for foreach() in faq_load() (line 345 of /Applications/MAMP/htdocs/pingfm-d7/sites/all/modules/faq/faq.module).
I get the following error when loading an FAQ node.
Warning: Invalid argument supplied for foreach() in faq_load() (line 345 of /Applications/MAMP/htdocs/pingfm-d7/sites/all/modules/faq/faq.module).
Comments
Comment #1
Steven Brown commentedThe way this error occurs is when you do the following steps.
The error happens because we uninstalled the FAQ module which removed the faq_questions table and data. So now during the hook_load() function in FAQ module we have an issue because the query will never find anything so $result will = 0.
The second foreach loop will now throw the error that we see stated in the issue description.
Question is should we do anything about this random use case. It's very unlikely that it will happen to people.
Then again maybe during the installation process we should see if there are any nodes of type faq and if so then add the data to the faq_questions table. This should solve the issue.
Comment #2
drakythe commentedI can confirm this bug does indeed happen. Recreated with those steps. The error kind of goes unnoticed when you enable the module because the error only shows up on pages where the FAQ node loads. In my case it was pretty apparent since I had promoted the FAQ node to the front page. Returning 'home' after re-enabling the module instantly got me the error.
This is a rare use case, I think, but its still a bug that could be fixed.
EDIT:
After further testing, I have discovered that once your uninstall the FAQ module, the 'Question Details' field is removed as well. That is sort of a 'duh' but what it means is if the decision is made to re-import the questions into the FAQ table they will no longer contain their 'Question Details' field. The short question and body fields will still be stored though.
Comment #3
WriteCo commentedSo, what is the easiest way to make the error go away?
Comment #4
drakythe commentedThe easiest way to make the error go away is to delete your old FAQs. If you would like to keep them, you could manually re-import them into the proper SQL table. I was able to make the error go away that way as well, though as mentioned once the module has been removed you lose all the "question details" fields.
Comment #5
Steven Brown commentedFirst, I want to point out the main reason for this post is so that if someone comes across this issue on their own site they will know why they are getting it.
@writeco - So there's not an easy way to fix this. It works as designed. If someone was going through all the same steps I did during testing on a production site, then they better have a backup (as they should).
Reasons why we can't fix this are the following. (Please correct me if I'm wrong)
Comment #6
philosurfer commentedthis use case popped up for me..
this should be resolved..
what is preventing the pm-uninstall from properly stating that it will delete the faq's and have it properly uninstall the module as it should?
Comment #7
Steven Brown commented@philosurfer The reason we don't do this is stated in #5 Reason 2.
Comment #8
philosurfer commentedAdd an option to remove nodes during uninstall?
Comment #9
Steven Brown commentedWhere would you suggest this option be? As far as I know I can't add it to the uninstall process because when uninstalling a module Drupal fires off hook_uninstall(). Since there's not an additional form to say yes I would like to also delete these nodes. I'm not sure how to go about this.
Also, if there is a way or if I'm wrong with the above statement then I personally don't see a problem implementing the solution. I would run it by Stella before I committed it though.
NOTE:: Fixed a typo
Comment #10
jlongbottom commentedThis use case popped up for me too.
I fixed this error by editing the FAQ node and saving again. Luckily I only had 1 FAQ node, but this could be tedious for people that have more.
Comment #11
daniel.moberly commentedAnyone who is still running into this problem (I just did) - here is a cheap fix to get the error messages to stop showing up/clogging up your logs:
Run this query against your DB: