Upon submitting settings to the system I received the following error:

Warning: Invalid argument supplied for foreach() in /devel/modules/nodelimit/nodelimit.module on line 160

Warning: Invalid argument supplied for foreach() in /devel/modules/nodelimit/nodelimit.module on line 160

Warning: Cannot modify header information - headers already sent by (output started at /devel/modules/nodelimit/nodelimit.module:160) in /devel/includes/common.inc on line 266

This may have to do with custom roles that are created and used on the site. More digging will be done :)

pjb

CommentFileSizeAuthor
#16 nodelimit.module9.1 KBcode rader

Comments

Coyote’s picture

Hmmm... I'm not getting that, and I've tested it with and without custom roles.

Are you using this on 4.7, or on HEAD, or something else?

I'm looking at the code on line 160, and there shouldn't be a way for an empty array to get passed to the code there, which is what normally would cause that sort of error.

It looks as though, somehow, an empty array is getting passed to that foreach loop somehow.

I'll try stepping through the code, and messing with some stuff, but if you can provide any more feedback, or if anyone has any ideas, please let me know. I might need to just add some error-checking, or switch to while loops instead of foreach. : /

pjb’s picture

Agh sorry...4.7! I will investigate further tomorrow after work. :) Apologies for the vagueness.

pjb

Anonymous’s picture

I am getting the following error after submitting settings:
warning: Invalid argument supplied for foreach() in xxxxxxx/modules/nodelimit/nodelimit.module on line 161.
warning: Invalid argument supplied for foreach() in xxxxxxx/modules/nodelimit/nodelimit.module on line 161.

I am working with drupal 4.7-3

I tested the limit with a cck node in organic groups. The userrole is limited to make 1 cck node. With limit set to 1 (checked in admin/nodelimit) I could make multiple nodes.

The error message is only after pushing the submith button. I used nodelimit 4.7 and cvs

larry’s picture

Hello,

Great module idea, very, very useful. However, I can confirm this error as well. I get:

warning: Invalid argument supplied for foreach() in C:\Apache\Apache2\htdocs\drupal\modules\nodelimit\nodelimit.module on line 161.
warning: Invalid argument supplied for foreach() in C:\Apache\Apache2\htdocs\drupal\modules\nodelimit\nodelimit.module on line 161.

and strangely enough I get the same error twice as above. I'm using 4.7.3 and the organic groups module...if that makes a difference. Still, I continued to test as everything, excluding the above errors, was still workable. Node limits were not being respected, making the module useless. I get the alternative menu and I can see the per node settings, but the limits simply don't work.

Thanks for looking into this...it's really a cool idea to use.

cheers,

larry

Coyote’s picture

As for the foreach error, I am _completely_ unable to duplicate this error. I have tried it out with fresh installs of 4.7.3, with and without organic groups installed, and with and without custom roles created. It just won't do it for me, so I don't know what's causing it.

As for the problem with nodelimit not preventing users from creating more nodes of a type than they are supposed to, I think I have that one nailed, and will be uploading an update tonight.

Coyote’s picture

I have tested this now with cck and contentO node types, and did not get the foreach error. I just don't know what could be causing it, or under what circumstances. I've tried it with and without organic groups.

I've just uploaded a new version of the module for the 4.7 branch. If the folks who were getting this error will please try it out and see if they're still getting the error, and let me know, that would be a help.

JohnNoc-old’s picture

getting the same error and i have downloaded the module 14.oct. :-(((

* warning: Invalid argument supplied for foreach() in /home/xxx/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 158.
* warning: Invalid argument supplied for foreach() in /home/xxx/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 158.

this is actually a fabulous module but unfortunately i get this warning :-(((

i do not get the "Cannot modify header information" warning as pjb stated above though.

i checked the database...the configuration has been inserted to 'nodelimit_types' table

info:
Drupal 4.7.3
with nodes:

  • blog
  • book
  • forum
  • page
  • poll
  • story
  • janode
  • image
  • userlink
  • wishlist

no cck modules. no organic groups.

with 3 additional roles (editors, admins and superuser).

server setup:
Linux Apache 1.3.34 (Unix)
PHP 4.4.2
MySQL 4.1.19-standard

hmmmm... i surely hope this can be fixed :-)) because this is a module sent from heaven!!!

one more thing, do i have to put 0 as well if the user role has no access to the creation of a particular node type set in /admin/access ?

Coyote’s picture

Okay, this is making me _crazy_.

I cannot for the _life_ of me duplicate the problem. I cannot get the error to appear on my installation. I even tried erasing all settings, and leaving all boxes blank (or again, leaving some boxes blank), in an effort to get the error to appear. Nothing I do results in a foreach error. I have now tried it with and without custom roles, with and without various content types, and with and without modules like cck and contento. Nothing causes this error to appear for me.

When the error appears, is it still saving the settings? Is it saving at least _some_ of the settings? Is anything being inserted into the nodelimit_types database table at all?

Is there anyone who _is_ having this module work, or am I the only one it works for? It works perfectly for me, with no errors, properly limiting node creation, etc. I am using Drupal 4.7.3, php4, mysql 4, Apache webserver, Firefox for my browser. I'm using the standard forms API for Drupal. This one is making me tear my hair out. Or... well... it would be, if I had hair.

(digs furiously through code again)

All right... I've made a blind adjustment to the function that saves the nodelimit settings. What _may_ be happening is that I (perhaps foolishly) told the script to iterate through all form values, which seems to include things like the submit button. Obviously, the submit button doesn't have any roles assigned to it, so it has no array of return values. On my system, it breezes past that without an error. But there probably ought to be an error (which other people are getting).

Anyway, I've made a change to the function which _should_ fix the problem. I ask that folks _please_ try the fix and let me know if it works.

The old code reads:

function nodelimit_admin_overview_submit($form_id, $form_values) {
  db_query("DELETE FROM {nodelimit_types}"); // this should clear dead entries from deleted node types
  foreach ($form_values as $type => $rolelimits) {
    $query = "INSERT INTO {nodelimit_types} (nodetype,role,maxnodes) VALUES ('%s','%d','%d')";
    foreach ($rolelimits as $rid => $limit) {
      db_query($query, $type, $rid, $limit);
    }
  }
}

It should _now_ read:

function nodelimit_admin_overview_submit($form_id, $form_values) {
  $node_types = node_get_types();
  db_query("DELETE FROM {nodelimit_types}"); // this should clear dead entries from deleted node types
  foreach ($node_types as $the_type) {
    $rolelimits = $form_values[$the_type];
    $query = "INSERT INTO {nodelimit_types} (nodetype,role,maxnodes) VALUES ('%s','%d','%d')";
    foreach ($rolelimits as $rid => $limit) {
      db_query($query, $the_type, $rid, $limit);
    }
  }
}

(I include the above, so that in case someone wants to make the changes themselves, rather than wait for them to appear in the main project upload, they can do so. I'm uploading the fix - or what I hope is the fix - right now.)

As for having to put 0 for the limit when access to a role has been disabled... I don't see why you should have to. If the person can't make nodes of that type at all, then regardless of what you set for nodelimit, they won't be able to create nodes of that type.

Coyote’s picture

By the way... PLEASE let me know if this fixes the problem folks. I can't _see_ the problem on my end, so the only way I'll know if this issue has been resolved is if the people who were having it let me know. : )

JohnNoc-old’s picture

this patch made it worse.

before the patch i got two warnings.... but now i have:

  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.
  • warning: Invalid argument supplied for foreach() in /home/norge/public_html/testsite/sites/default/modules/nodelimit/nodelimit.module on line 160.

i have 10 node types active, and there are 9 warnings, so i checked the database and ALL settings the previous version before this patch inserted to the database are all gone except for one which is the wishlist node.

for relevance sake, i am trying to think of a difference between the wishlist module and the other modules. why wishlist module made its way to the database?

The only difference in configuration i have is that the 9 nodetypes which did not make it (namely: blog, book, forum, page, poll, janode, image, story and userlist) have url aliases to add new nodes/content and they are named differently than the default.

The wishlist module which nodelimit seetings were inserted to the database are still on its default name and default url for adding of nodes, because i just installed it and haven't changed its url and name (via path module and locale module, consecutively).

I have a feeling that this causes it because that's the only difference between the module which can be limited and the 9 that give warnings

JohnNoc-old’s picture

i reverted to the original one without the patch.... it inserts all settings in the database and now i have all my nodetypes on the nodelimit_types table again but back to the 2 warnings instead of 9.

anyway, thanks for the huge effort in solving this......this is one of the best contributed modules i have encountered (subjective to my present site's needs).... surely hope this get fixed. :-)

Coyote’s picture

userlist is a content type node? : /

Have you tried this module out on a fresh install, without contributed modules?

It's possible that there's a conflict with another module or something.

Again, I cannot get _any_ errors to appear when I use the module. I get no warnings, no errors, and all functions work fine. This makes me have to _guess_ what the problem is.

Coyote’s picture

Well... in trying to fix the foreach bug, I realized that I introduced another error which could prevent settings from being saved for cck types.

Argh.

I have uploaded (yet another) update to fix this.

I have also reworked the code so that the foreach loop where the problem occurs should _only_ ever be able to get the list of roles it is operating off of directly from the get_roles() Drupal function. This should mean that there is no way for that foreach loo to encounter an empty array, because there should be no way for Drupal to have no installed roles, and no installed node types.

Well... you _could_ have no installed node types, but then nodelimit should present an empty settings screen anyway at that point.

Coyote’s picture

If you don't want to wait for the changes to propagate to the module download page, the new version is available in the CVS repository at:

http://cvs.drupal.org/viewcvs/drupal/contributions/modules/nodelimit/?on...

Coyote’s picture

Status: Active » Fixed

I'm marking this fixed. If anyone has further problems, please let me know.

code rader’s picture

StatusFileSize
new9.1 KB

I think the error may have been coming from certain browser types.

Here is the real fix for the function

function nodelimit_admin_overview_submit($form_id, $form_values) {
	foreach ($form_values as $type => $rolelimits) {
		if ($type != "submit" && $type != "form_id") {
			db_query("DELETE FROM {nodelimit_types} WHERE nodetype='%s'",$type);
			$query = "INSERT INTO {nodelimit_types} (nodetype,role,maxnodes) VALUES ('%s','%d','%d')";
			foreach ($rolelimits as $rid => $limit) {
				db_query($query, $type, $rid, $limit);
			}
		}
  }
}

My browser (Safari) was submitting "submit" and "form_id" as part of the $form_values array. So when the foreach hit it, it choked.

Try it out and then it can really be marked as fixed.

Coyote,
Are you testing on multiple platforms and browsers?

Coyote’s picture

I've already made a fix for this, which should be included in the current 4.7 version.

Instead of iterating through the form values to create the loops, (and filtering out submit and form_id), I put in calls to node_get_types() and user_roles(). I'm worried that using the form values to create the loop will come back to haunt me later if I add other settings to the module. I've also decided that looping through form values in this way just isn't a good idea for other reasons.

The version of the fix I used seems to be fine in Safari.

I'm a mac user also. While I don't use Safari as my browser (and don't really like it), I do test on it, just in case.

It looks like the file you modified was an older version of the module. Looking at it I see the code I originally put in it to keep nodelimit from making settings for anonymous users (sinec disabled), and it's missing the code that fixes the problem with default values.

Please try the current version of nodelimit.module and see how it works for you.

code rader’s picture

I thought I had gotten the latest. Sorry for posting in an area you just closed.

Thanks for your work.

I'm about to check out what you just posted too.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Project: » Lost & found issues

This issue’s project has disappeared. Most likely, it was a sandbox project, which can be deleted by its maintainer. See the Lost & found issues project page for more details. (The missing project ID was 87165)