Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 05-04-2011, 03:37 AM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Unexpected error

All-

When running an app to create users and posts, I get this error:

<br /><strong>Warning</strong>: Invalid argument supplied for foreach() in <strong>[path]/includes/functions.php</strong> on line <strong>6501</strong><br />av8or1 1

However if I simply comment out the require_once() statements in the "main" source file:

Code:
//require_once( './global.php'                       );
//require_once( LMDIR . '/DatabaseOps.php'      );
//require_once( LMDIR . '/AddNewUser.php'       );
//require_once( LMDIR . '/AddNewCategory.php'   );
//require_once( LMDIR . '/AddNewForum.php'      );
//require_once( LMDIR . '/AddNewThreadPost.php' );
the error message disappears and I can select values from the vB user DB without incident. What I found interesting was that if I went to each of those include/required files and commented everything out between the <?php and ?> I would still get the error. Only by commenting them out in the "main" source file resulted in the error disappearing.

So. Anyone else encountered this before and can help? I did a search, the result of which centered around rebuilding your forum counters and such. I did that but with no change.

Thanks!
Reply With Quote
  #2  
Old 05-04-2011, 11:37 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is a script you wrote yourself (as opposed to one of the vb scripts)? I think you have to define $phrasegroups as an array (and probably define a couple other arrays as well) before including global.php (see the top of any vb page script, like maybe showthread.php)
Reply With Quote
  #3  
Old 05-04-2011, 02:29 PM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi-

Yes, this is the "main" (ergo top-level) script for a utility that I am finishing up to migrate a Lefora forum to vBulletin. I looked at a few examples of top level scripts, especially the impex stuff and tried to follow suit. I don't recall seeing anything about $phrasegroups, but that is indeed the relevant section of code where the failure occurs. I will go back and take another look, I could have easily missed something.

BTW, this failure occurs no matter which require statement is used, either the global script or my own modules. If any of those lines are uncommented, boom, I get the error. What is interesting is that the simplistic version of the db code that immediately follows these require_once statements produces the correct results. By commenting out these require_once statements the error disappears and I still see the same correct results. Wha-?

This:
Code:
$conn = mysql_connect( $lmConfig[ 'dbserver' ], $lmConfig[ 'username'  ],$lmConfig[ 'password' ] );

$lmDB = mysql_select_db( $lmConfig[ 'vbdatabase' ] );

$query = 'SELECT * FROM ' . $lmConfig[ 'vbtableprefix' ] . 'user';

$resultSet = mysql_query( $query );

while( $row = mysql_fetch_array( $resultSet ) )
{
   print $row['username'] . " " . $row['userid'] ."\n";

}

mysql_close( $conn );
produces:
Code:
admin  1
joeuser  2
testuser 3
I'll keep playing around with it and see if I can find the answer. Any help is appreciated; I'll post the result when I figure it out so as to possibly help someone else in the future.

Thanks!
Reply With Quote
  #4  
Old 05-04-2011, 02:33 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What the heck is LMDIR and how did you get that working?
Reply With Quote
  #5  
Old 05-04-2011, 02:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by av8or1 View Post
Hi-
... By commenting out these require_once statements the error disappears and I still see the same correct results. Wha-?
I think that's just because you haven't used any vb stuff in that code you posted, just the mysql stuff that goes directly to the database.

ETA: also, there's more than one global.php, so maybe the example script you looked at used a different one than you're including (there's on in admincp, for instance).
Reply With Quote
  #6  
Old 05-04-2011, 02:47 PM
av8or1 av8or1 is offline
 
Join Date: Mar 2011
Posts: 58
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah yes, sorry for omitting that. LMDIR is a variant of the vB CWD and the impex IDIR. Those definitions call getcwd() and if it returns something, they use that value else '.' - LMDIR is set to the full path to the vB forum directory (/home2/username/www/forum in my case) as defined in the config file. When I execute the script I am in this directory.

I didn't mention it previously only because it didn't seem relevant. I get the error even when I reduce the require_once statement to:

Code:
require_once( './global.php' );
and comment out all of the statements that refer to my stuff, so you have this:

Code:
require_once( './global.php'                  );
//require_once( LMDIR . '/DatabaseOps.php'      );
//require_once( LMDIR . '/AddNewUser.php'       );
//require_once( LMDIR . '/AddNewCategory.php'   );
//require_once( LMDIR . '/AddNewForum.php'      );
//require_once( LMDIR . '/AddNewThreadPost.php' );
Which I found puzzling. At the top of my file I also followed the vB support recommendations thus:

Code:
/*
 * Constants
 *
 * These definitions are used as per the
 * recommendations of vbulletin support
*/
define( 'VB_AREA',            'External' );
define( 'SKIP_SESSIONCREATE', 1          );
define( 'SKIP_USERINFO',      1          );
And thought that perhaps this was causing the problem, but I am not familiar enough with exactly what these do to take a guess. I did rifle through the code a little and discovered that VB_AREA affects which sections of code are executed during page rendering. That said, it seems like you'd still need to include the global script even with these above three definitions. And having said that, one thought that I had was the opposite: that you actually do not need the global script since you are defining yourself to be External and you are skipping the session and user stuff.

Eh, there I go again talking about code I know little about ... kinda like talking out of my backside. And I don't like doing that. Anyway, I needed to get something up and working so I tried various derivations as any programmer ultimately does. And as I mentioned I commented out all of the aforementioned require_once statements and that - to my surprise - returned the correct result set with no errors. But I dunno ... just didn't seem "right" somehow, so I conducted a search on vb.org ... not much turned up, so I decided to post and ask those who are in-the-know.

Thanks again!

--------------- Added [DATE]1304524776[/DATE] at [TIME]1304524776[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
I think that's just because you haven't used any vb stuff in that code you posted, just the mysql stuff that goes directly to the database.

ETA: also, there's more than one global.php, so maybe the example script you looked at used a different one than you're including (there's on in admincp, for instance).
Touche' - good point. You are correct. The direct mysql stuff would work regardless of the vB error since it doesn't use any of the vB code to do its work. Duh.

I set the directory to be the top-level vB directory prior to the global include. And I am in that top-level vB directory when I type "php LMigrate.php"...

Thank you for the feedback, much appreciated!

--------------- Added [DATE]1304534406[/DATE] at [TIME]1304534406[/TIME] ---------------

Ok I figured out what the problem was, but don't know enough about the vB code to say why. The problem does indeed lie with these lines of code:

Code:
/*
 * Constants
 *
 * These definitions are used as per the
 * recommendations of vbulletin support
*/
define( 'VB_AREA',            'External' );
define( 'SKIP_SESSIONCREATE', 1          );
define( 'SKIP_USERINFO',      1          );
Specifically the SKIP_USERINFO line. That is, if I comment out only that one definition, then I don't see the vB error. So....can anyone explain what that does exactly so as to cause this error? And do I really need these lines of code if the plan is to run from the vB top-level forum directory and include the global source plus relevant sources from the includes directory? Ergo, what exactly does it mean to run a script without "loading the vB backend"?

Thanks!

--------------- Added [DATE]1304550656[/DATE] at [TIME]1304550656[/TIME] ---------------

Quote:
Originally Posted by kh99 View Post
This is a script you wrote yourself (as opposed to one of the vb scripts)? I think you have to define $phrasegroups as an array (and probably define a couple other arrays as well) before including global.php (see the top of any vb page script, like maybe showthread.php)
FINAL UPDATE: kh99 was indeed correct in the end. Simply by adding a few definitions of various templates the error went away, thus:

PHP Code:
$phrasegroups = array();
$specialtemplates = array();
$globaltemplates = array();
$actiontemplates = array(); 
Ended up being the difference maker. Just wanted to share this nugget of knowledge with others who might find it useful in the future.

'Still don't know exactly what SKIP_USERINFO does, but I'll get back to that. Right now I've got other higher priority stuff to work on, such as completing the migration. (!) There is another fellow Lefora user who is fed up and wants to bail, and I've agreed to help.

But I digress.

Thanks again!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:53 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08107 seconds
  • Memory Usage 2,235KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete