Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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) {
Comment | File | Size | Author |
---|---|---|---|
#2 | upload.module.is_array.patch | 4.39 KB | markus_petrux |
#1 | 53666.patch | 5.99 KB | dopry |
Comments
Comment #1
dopry CreditAttribution: dopry commentedHere 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.
Comment #2
markus_petrux CreditAttribution: markus_petrux commentedIn the meantime I was also writing a patch. :-/
Mine also removes some empty lines here and there.
Comment #3
chx CreditAttribution: chx commentedfor markus' patch. Nice work.
Comment #4
dopry CreditAttribution: dopry commented+1 on markus's as well...
Comment #5
kkaefer CreditAttribution: kkaefer commented+1, patch works also for me.
Comment #6
Patrick Nelson CreditAttribution: Patrick Nelson commentedDidn'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.
Comment #7
dopry CreditAttribution: dopry commentedkilles just committed this patch... try updating to head...
You are using simplenews? I'll see if I can replicate..
Comment #8
dopry CreditAttribution: dopry commentedI just test with cvs head, with simplenews from cvs.
Created a newsletter item without error. using head.
Comment #9
Patrick Nelson CreditAttribution: Patrick Nelson commentedDone it. Was lagging behind on form.inc version.
Everything works now.
Yay.
Comment #10
(not verified) CreditAttribution: commented