array_reverse() warning on refresh

masoha - November 15, 2007 - 02:28
Project:FeedAPI
Version:5.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:critical
Assigned:Aron Novak
Status:closed
Description

Hello, I installed Feedapi, not errors, not warnings, when I create a new feed everything works as expected, however the node is empty.
If I select the refresh tab the following error is shown:

warning: array_reverse() [function.array-reverse]: The argument should be an array in /home/mycompla/public_html/software/modules/feedapi/feedapi.module on line 324.
warning: Invalid argument supplied for foreach() in /home/mycompla/public_html/software/modules/feedapi/feedapi.module on line 329.

I followed the installation steps three times, always the same result, of course I made a backup before install the module, so every time that I retry was after I restored the database.

Any help will be appreciated

#1

deanx0r - November 15, 2007 - 04:15

I'm actually having the same issue, error is as follows...

    * warning: array_reverse() [function.array-reverse]: The argument should be an array in /var/www/vhosts/blah/subdomains/dev/httpdocs/modules/feedapi/feedapi.module on line 335.
    * warning: Invalid argument supplied for foreach() in /var/www/vhosts/blah/subdomains/dev/httpdocs/modules/feedapi/feedapi.module on line 340.

#2

alex_b - November 15, 2007 - 15:06

This guy seems to be the culprit:

<?php
$items
= array_reverse($feed->items);
?>

@masoha, looks like you're using beta 1, right? Or at least not last nights dev snapshot.

Either way, deanx0r's report suggests that the issue is not resolved in the 5.x branch at all.

Which PHP version are you guys using? Could you post the feed that caused the error message?

It seems that the there is a problem a couple of lines above $items = array_reverse($feed->items); :

<?php
$feed
= _feedapi_call_parsers($feed, $feed->parsers, $feed->half_done ? FALSE : TRUE);
      if (
$feed === FALSE) {
      
// ...
     
return;
      }
?>

does _feedapi_call_parsers return a non-false value even though it couldn't produce feed items?

IMO, we should redefine _feedapi_call_parsers($feed, ...) to _feedapi_call_parsers(&$feed, ...) because PHP5 passes objects by reference by default. The call of the function would then change to:

<?php
_feedapi_call_parsers
($feed, $feed->parsers, $feed->half_done ? FALSE : TRUE);
?>

And assuming that the function does not destroy the passed in $feed object, we could then test

<?php
if (!$feed->items) {
// ...
return;
}
?>

which would solve this issue.

#3

alex_b - November 16, 2007 - 15:17
Title:Error when refresh » array_reverse() warning on refresh
Priority:normal» critical

#4

Aron Novak - November 16, 2007 - 22:23
Category:support request» bug report

Unfortunately I cannot reproduce the bug.
To make sure that everything is okay w/ FeedAPI installation and the server environment, please run the simpletest tests of feedapi.
http://drupal.org/project/simpletest - you can find simpletest here. You have to install it and then go to admin/build/simpletest, select and run feedapi tests. 0 fails should appear. If it's not ok, there is serious problem w/ the installation or with the server environment. (the tests uses an external URL, it's possible that the external site is down and the test fails because of this :), the URL what the tests try to download: http://novaak.net/test_feed.rss )

#5

mohammed76 - November 17, 2007 - 16:04

hi.

I have the same exact problem using the latest development version. first here's my server environment details:

Drupal: 5.3  
Configuration file: Protected  
Cron maintenance tasks: Last run 2 min 10 sec ago   
Database schema: Up to date  
File system: Writable (public download method)  
GD library: bundled (2.0.28 compatible)  
MySQL database: 5.0.27  
PHP: 5.1.2  
Unicode library: PHP Mbstring Extension  
Web server: Apache/1.3.37 (Unix) PHP/5.1.2 mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a 

and below are the results of the test module:

Drupal Unit Tests 32 passes, 15 fails and 9 exceptions. 2 test cases complete:

FeedAPI 2 test cases complete: 32 passes, 15 fails and 9 exceptions.
FeedAPI Node basic functions 17 passes, 8 fails and 6 exceptions.
FeedAPI Node basic functions: Refresh a feed and find out if it's okay. Uses SimplePie parser for parsing and downloading.

[role] created name: simpletest_n31Q, id: 5 at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 278] 
OK  
[role] created permissions: administer feedapi, advanced feedapi options, administer nodes, create feedapi_node_simpletest_P7yh content at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php
line 282] 
OK  
[user] name: simpletest_vgMB pass: nPabW4TrNB created at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 312] 
OK  
[browser] GET http://www.atexplorer.com/user at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 107] 
OK  
[browser] Setting name="simpletest_vgMB" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 111] 
OK  
[browser] Setting pass="nPabW4TrNB" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 111] 
OK  
[browser] POST by click on Log in at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 125] 
OK  
[login] found name: simpletest_vgMB at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 343] 
OK  
[login] not blocked at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 344] 
OK  
[login] not reserved at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 345] 
OK  
[browser] GET http://www.atexplorer.com/node/add/feedapi_node_simpletest_P7yh at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php
line 107] 
OK  
[browser] Setting feedapi[feedapi_url]="http://novaak.net/test_feed.rss?simpletest_Vfdl" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php
line 111] 
OK  
[browser] POST by click on Submit at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 125] 
OK  
The node is created. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 48] 
FAIL  
The feed node is in the database at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 52] 
FAIL  
The feed can be loaded. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 54] 
FAIL  
The proper number of items were created at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 58] 
FAIL  
The first news item is a story. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 78] 
FAIL  
All news items have the same type. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 79] 
FAIL  
All news item titles are longer than 0 character. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 82] 
FAIL  
All news item bodies are longer than 0 character. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 83] 
FAIL  
All news items has the proper author. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 84] 
OK  
All news item database entries are deleted because of feed deletion. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test
line 91] 
OK  
All nodes belonging to a news item are deleted. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test line 95] 
OK  
The content-type's setting variable is successfully deleted. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test
line 105] 
OK  
Unexpected PHP error [sort() expects parameter 1 to be array, null given] severity [E_WARNING] in [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test
line 80] 
EXCEPTION  
Unexpected PHP error [sort() expects parameter 1 to be array, null given] severity [E_WARNING] in [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_node/feedapi_node.module.test
line 81] 
EXCEPTION  
Unexpected PHP error [Invalid argument supplied for foreach()] severity [E_WARNING] in [/home/explorer/public_html/modules/node/node.module line 521] 
EXCEPTION  
Unexpected PHP error [implode() [function.implode]: Bad arguments.] severity [E_WARNING] in [/home/explorer/public_html/modules/node/node.module
line 525] 
EXCEPTION  
Unexpected PHP error [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp,
r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions
r ON r.vid = n.vid WHERE ] severity [E_USER_WARNING] in [/home/explorer/public_html/includes/database.mysql.inc line 172] 
EXCEPTION  
Unexpected PHP error [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
')' at line 1 query: SELECT COUNT(*) FROM node WHERE nid IN ()] severity [E_USER_WARNING] in [/home/explorer/public_html/includes/database.mysql.inc
line 172] 
EXCEPTION 
FeedAPI Aggregator basic functions 15 passes, 7 fails and 3 exceptions.
FeedAPI Aggregator basic functions: Refresh a feed and find out if it's okay. Uses Common Syndication Parser for parsing and downloading.

[role] created name: simpletest_ywDw, id: 6 at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 278] 
OK  
[role] created permissions: administer feedapi, advanced feedapi options, administer nodes, access news feeds, create aggreg_simpletest_NWlk content at
[/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 282] 
OK  
[user] name: simpletest_rdOA pass: 5TcfSVYaiP created at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 312] 
OK  
[browser] GET http://www.atexplorer.com/user at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 107] 
OK  
[browser] Setting name="simpletest_rdOA" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 111] 
OK  
[browser] Setting pass="5TcfSVYaiP" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 111] 
OK  
[browser] POST by click on Log in at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 125] 
OK  
[login] found name: simpletest_rdOA at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 343] 
OK  
[login] not blocked at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 344] 
OK  
[login] not reserved at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 345] 
OK  
[browser] GET http://www.atexplorer.com/node/add/aggreg_simpletest_NWlk at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php
line 107] 
OK  
[browser] Setting feedapi[feedapi_url]="http://novaak.net/rss.xml?simpletest_c6JP" at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php
line 111] 
OK  
[browser] POST by click on Submit at [/home/explorer/public_html/sites/all/modules/simpletest/drupal_test_case.php line 125] 
OK  
The node is created. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test line 49] 
FAIL  
The feed node is in the database at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test line 53] 
FAIL  
The feed can be loaded. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test line 55] 
FAIL  
The source's page is empty before refreshing. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test
line 59] 
FAIL  
The proper number of items were created. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test line
63] 
FAIL  
The third news title can be read at the source page. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test
line 66] 
FAIL  
The proper number of items can be found in the database. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test
line 70] 
FAIL  
All the news items are deleted from the database. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test
line 77] 
OK  
The content-type's setting variable is successfully deleted. at [/home/explorer/public_html/sites/all/modules/feedapi/feedapi_aggregator/feedapi_aggregator.module.test
line 87] 
OK  
Unexpected PHP error [Invalid argument supplied for foreach()] severity [E_WARNING] in [/home/explorer/public_html/modules/node/node.module line 521] 
EXCEPTION  
Unexpected PHP error [implode() [function.implode]: Bad arguments.] severity [E_WARNING] in [/home/explorer/public_html/modules/node/node.module
line 525] 
EXCEPTION  
Unexpected PHP error [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
'' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp,
r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions
r ON r.vid = n.vid WHERE ] severity [E_USER_WARNING] in [/home/explorer/public_html/includes/database.mysql.inc line 172] 
EXCEPTION 

#6

As If - November 17, 2007 - 16:13

I had the same problem for a couple hours while trying to configure a site with all the submodules except simplepie. I tried several hacks, none worked (although there definitely should be a test there for !$items). Anyway, I went through the whole setup again, this time following ALL the instructions anally, and running test refreshes each time I changed something. The most important document for me was the README for the Inherit submodule. And the last thing I changed - before it began working properly - was setting the weight of FeedAPI Inherit higher than the weight of FeedAPI Node (higher than everything else, actually).

So for me this turned out to be a simple problem. Not actually a bug at all. The solution is buried in the subfolder documentation, and it's weird, but it's right there in black & white.

(Maybe it also explains why it doesn't happen for Aron, eh?)

LVX
TF

#7

mohammed76 - November 18, 2007 - 13:17

It worked! it's a matter of a parcer for me though. parser_common_syndication never worked, so I had to use parser_simplepie. I do have php 5 but it threw those errors on me.

something else, is there a way to make the author of the node created by feed api the same as the original author? may be I need to open a separate support or feature request for this?

#8

alex_b - November 18, 2007 - 17:00

@As If: I am working on a improved version of feedapi_inherit, which won't have the weight problem any more.

@nattiq: "parser_common_syndication never worked" means that feedapi always spat those array_reverse() errors and never produced node items?

something else, is there a way to make the author of the node created by feed api the same as the original author? may be I need to open a separate support or feature request for this?

The beta 1 version behaves differently from the latest dev snap shot. In the latest version, there is no explicit feed item author anymore. The feed item author is always inherited from the feed author. This seems to be a good default behaviour for known use cases. For a more detailed discussion, please see this issue: http://drupal.org/node/191805

#9

mohammed76 - November 18, 2007 - 18:04

"@nattiq: "parser_common_syndication never worked" means that feedapi always spat those array_reverse() errors and never produced node items?"

yes exactly. this is what I meant.

"The feed item author is always inherited from the feed author." exactly the functionality I am looking for, but although I am running the latest snapshot, it sets the author to who ever created the feed_node or to guest if that is left blank.

use case: I have news site which simply aggregates content from other rss feeds / blogs. it makes sense if I could retain the same original author on those created nodes other than addressing them to myself or other users of my site. if my user name was "mohammed" then each time I create a feed_node the author becomes "mohammed", not the original author of that aggregated news item. hope it's clear enough?

#10

Aron Novak - November 19, 2007 - 13:02
Status:active» postponed (maintainer needs more info)

For common syndication parser: I spotted one possibly problematic part in the code (SQL-related), so w/ versions before mysql 4.1, the SQL table could not be created. Please double check that the parser_common_syndication table in the SQL db exists and please paste here some sample lines if it's not empty.

#11

mohammed76 - November 19, 2007 - 13:19

hi.

but I am running MySQL database: 5.0.27, would this still apply to me?  
thanks.

#12

Aron Novak - November 19, 2007 - 13:38

nattiq: it does not apply to you in this case.
Is it possible that your hosting provider disable some way of http downloading?
Can you try out that http://drupal.org/project/aggregation module works or not at your site? Because the common syndication parser is ported from that module.

#13

alex_b - November 20, 2007 - 21:43
Status:postponed (maintainer needs more info)» needs review

At least we should not run into the array_reverse() error message - this patch takes care of that. Feed refreshing fails with "Could not refresh feed" message if _feedapi_call_parsers does not return an array in $feed->items.

Aron, could you check this patch wether it conforms your intentions on return value handling of _feedapi_call_parsers?

AttachmentSize
fix_array_reverse_error.patch 1006 bytes

#14

XPectIT - November 23, 2007 - 06:53

Hi Aron,
hi alex_b,

I had the same error message with array_reverse() but I could track it down a little bit.

I had to go to:
/admin/settings/feedapi_aggregator and
/admin/settings/feedapi
press "save".

After that, the error disappeared and it works as expectit.
My used modules:

FeedAPI Aggregator 5.x-1.0-beta1
Common syndication parser 5.x-1.0-beta1
FeedAPI 5.x-1.0-beta1
FeedAPI Node 5.x-1.0-beta1

Hope I could help

#15

trevortwining - November 27, 2007 - 15:59

Hi all, having a similar problem,

Drupal 5.3
MySQL database 5.0.45
PHP 5.2.3-1ubuntu6
Unicode library PHP Mbstring Extension
Web server Apache/2.2.4 (Ubuntu) PHP/5.2.3-1ubuntu6

FeedAPI Aggregator 5.x-1.0-beta1
Common syndication parser 5.x-1.0-beta1
FeedAPI 5.x-1.0-beta1
FeedAPI Node 5.x-1.0-beta1

Installing/configuring core aggregator.module works

Steps to resolve above do not work. I haven't tried installing simplepie module yet.

My backtrace info is attached. If you note the parsers setting in the object is set to simplepie. I just want to reiterate that I have not installed simplepie at all.

I'm going to take a look at it and see if I can write a patch. if it's looking for the wrong parser, that would be a good reason for the error.

AttachmentSize
Screenshot.png 83.45 KB

#16

alex_b - November 27, 2007 - 19:39

Thanks XPectIT and trevor,

Your reports gave me the final hint. Here is what's going on:

feedapi_node and feedapi_aggregator install default content types and configure them by default with parser_simplepie:

<?php
// feedapi_node.install
variable_set('feedapi_settings_feedapi_node', unserialize('a:3:{s:7:"enabled";s:1:"1";s:7:"parsers";a:1:{s:16:"parser_simplepie";a:2:{s:7:"enabled";s:1:"1";s:6:"weight";s:1:"0";}}s:10:"processors";a:1:{s:12:"feedapi_node";a:7:{s:7:"enabled";s:1:"1";s:6:"weight";s:1:"0";s:12:"content_type";s:5:"story";s:9:"node_date";s:4:"feed";s:7:"promote";s:1:"3";s:9:"list_feed";s:1:"3";s:4:"user";s:5:"admin";}}}'));
?>

So, when you don't use parser_simplepie, you won't get a correct setting. The problem here is, that at install time, we don't know which parser the user picked. The solution is not straightforward.

* It would be ideal to detect the parser being installed and configure the node type accordingly, I have not yet figured out how to do that. A check module_exists() in hook_install() returns FALSE for modules being installed.
* Doing a fallback to any other enabled parser is a possibility, but not very clean.
* A better user warning is another option, but this even less elegant.

#17

alex_b - November 27, 2007 - 19:42
Status:needs review» needs work

#18

Aron Novak - November 27, 2007 - 20:24
Assigned to:Anonymous» Aron Novak

The planned solution in short: the parsers installer will set the default parser, not the processors. I'll commit a patch today.

#19

Aron Novak - November 27, 2007 - 22:30
Status:needs work» fixed

I committed the fix.
Before you try it out the new version of the code, please do the following:
- disable and uninstall all the processors and the parsers.
- install the needed processors and parsers

Please report me if you experience such problems after trying out the latest dev version (or the proper cvs branch)

#20

alex_b - November 28, 2007 - 16:38

Great, Aron. Thank you for this patch.

Just one addition to Aron's last comment: The array_reverse() error is a mere installation issue. If you overcame it by going to the content type edit page and configuring the content type correctly, you are fine. You can upgrade to the latest dev version of FeedAPI, run DB update scripts (if necessary, this patch doesn't add any DB updates) and be happy.

Only if you whish to test the repaired installation routines, follow the steps that Aron described (disable, uninstall, install processors and parsers).

#21

trevortwining - December 7, 2007 - 20:35

Thanks for your work on this Aron and Alex,

I'm going to do the long way and test right from re-installation.

#22

Anonymous - December 21, 2007 - 20:41
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.