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

Steven Brown’s picture

The way this error occurs is when you do the following steps.

  1. Install FAQ Module
  2. Create a FAQ node
  3. Disable and Uninstall FAQ Module
  4. Enable FAQ Module

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.

drakythe’s picture

I 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.

WriteCo’s picture

So, what is the easiest way to make the error go away?

drakythe’s picture

The 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.

Steven Brown’s picture

Status: Active » Closed (works as designed)

First, 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)

  1. When the FAQ module is uninstalled we lose the faq_questions table.
  2. During the installation of FAQ we can not assume that any node that is of type 'faq' was created by a previous installation of FAQ module. Nothing prevents the admin from creating a node of type 'faq' without using this module.
  3. And finally even if we ignored the issue from 2 and assumed that those nodes are indeed from our FAQ module. We still don't have the data that was stored in faq_questions table. So we can't fix that.
philosurfer’s picture

this 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?

Steven Brown’s picture

@philosurfer The reason we don't do this is stated in #5 Reason 2.

philosurfer’s picture

Add an option to remove nodes during uninstall?

Steven Brown’s picture

Where 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

jlongbottom’s picture

This 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.

daniel.moberly’s picture

Issue summary: View changes

Anyone 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:

INSERT INTO faq_questions 
	SELECT 
		node.nid, node.nid, node.title, '' 
	FROM node 
	LEFT JOIN faq_questions 
	ON node.nid = faq_questions.nid 
	WHERE 
		node.type = 'faq' AND 
		faq_questions.nid IS NULL