After applying the patch committed here:
http://drupal.org/node/42358

When adding/editing a node with no uploads I get the "Invalid argument supplied for foreach()" error related to the following snippet:

function upload_save($node) {
  foreach ($node->files as $fid => $file) {
  ...

upload_save() is called from upload_nodeapi(), for op IN ('insert', 'update')

Not sure if this may happen somewhere else, it might be fixed checking if $node->files is an array:

function upload_save($node) {
  if (is_array($node->files) {
    foreach ($node->files as $fid => $file) {
    ...

I think the same problem may happen here:

function upload_delete_revision($node) {
  foreach ($node->files as $file) {

Also, I think there is a redundant check in _upload_validate(). The following:

function _upload_validate(&$node) {
  // Accumulator for disk space quotas.
  $filesize = 0;


  // Check if node->files exists, and if it contains something.
  if (count($node->files) && is_array($node->files)) {
    // Update existing files with form data.
    foreach($node->files as $fid => $file) {

could probably look like:

function _upload_validate(&$node) {
  // Accumulator for disk space quotas.
  $filesize = 0;


  // Check if node->files is an array.
  if (is_array($node->files)) {
    // Update existing files with form data.
    foreach($node->files as $fid => $file) {
CommentFileSizeAuthor
#2 upload.module.is_array.patch4.39 KBmarkus_petrux
#1 53666.patch5.99 KBdopry
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dopry’s picture

Assigned: Unassigned » dopry
Status: Active » Needs review
FileSize
5.99 KB

Here is the sanity checking patch.

I thought upload_load() would cover this for me since it returns and empty array if there a no files, but since I'm leveraging the formAPI these are actually coming from the post. Is there a way to tell the form api to create an empty array of elements if none exist in the form?

This patch should be valid for now.

.darrel.

markus_petrux’s picture

In the meantime I was also writing a patch. :-/

Mine also removes some empty lines here and there.

chx’s picture

Status: Needs review » Reviewed & tested by the community

for markus' patch. Nice work.

dopry’s picture

+1 on markus's as well...

kkaefer’s picture

+1, patch works also for me.

Patrick Nelson’s picture

Didn't work for me - still getting the same error as reported in node/53816.

Will double-check everything (that all is CVS and patches applied) and post again if error is not recreated.

dopry’s picture

killes just committed this patch... try updating to head...

You are using simplenews? I'll see if I can replicate..

dopry’s picture

Status: Reviewed & tested by the community » Fixed

I just test with cvs head, with simplenews from cvs.

Created a newsletter item without error. using head.

Patrick Nelson’s picture

Done it. Was lagging behind on form.inc version.

Everything works now.

Yay.

Anonymous’s picture

Status: Fixed » Closed (fixed)