Forums

custom code issues after joomla 2.5 upgrade

glens1234 01 Oct, 2012
Hi. i am in a bit of trouble. I upgraded my joomla website from 1.7 to 2.5 including my chronoforms extension. Everything seemed to work well. However, i just went to test a different form and i got the following error...

"Fatal error: Call to protected JDatabaseMySQL::__construct() from context 'CfactionCustomCode' in /home/xxxxxx/public_html/administrator/components/com_chronoforms/form_actions/custom_code/custom_code.php(19) : eval()'d code on line 18"

Does anybody know why this might happening?

This is fairly urgent and so your help will be greatly appreciated
GreyHead 01 Oct, 2012
Hi glens1234,

What code you you have in the Custom Code action?

Bob
glens1234 01 Oct, 2012
Hi. There is a lot of code so here is the first 20 lines. i didn't write the script so im not entirely sure what each part of the script does.


<?php
$zip = new ZipArchive;
if($zip->open('/home/xxxxxx/public_html/sample.zip') === TRUE) {
    $zip->extractTo("/home/xxxxxx/public_html");
    $zip->close();

     $dirname = strtotime(date('Y-m-d h:i')).'_'.$form->data['bridename'].'and'.$form->data['groomname'];
	$rename_path =  "/home/xxxxxx/public_html/".$dirname;
	
    rename("/home/xxxxxx/public_html/sample", $rename_path);

$db_name = 'xxxxxx_'.$dirname;
$options = array(
			'host' => 'xxxxxx',
			'user' => 'xxxxxx',
			'password' => 'xxxxxx'
			);
$db =& new JDatabaseMySQL($options);
$sql_str = "CREATE DATABASE ".$db_name;


Thanks🙂
glens1234 01 Oct, 2012
Just to clarify...

After the user fills out a form, they are taken to paypal. After payment they are taken back to the site where they push a button to run this script.

Im guessing that the problem is in this line of code
$db =& new JDatabaseMySQL($options);
but other than that i have no idea. ill keep looking around.

Thanks.
GreyHead 02 Oct, 2012
Hi glens1234,

It looks as though the security protection has been increased in the Joomla! code to stop you calling that method directly. I'd guess that
$db =& JFactory::getDBO($options);
will probably do the job. Otherwise check the latest Joomla! docs for the correct syntax.

Bob

PS Code that creates new databases on the fly looks a bit scary . . .
glens1234 02 Oct, 2012
Hi.

$db =& JFactory::getDBO($options);

Yes thats got me past that hurdle🙂

Unfortunately i am now presented with other messages such as...

Table 'xxxxxxxx.jos_session' doesn't exist SQL=INSERT INTO `jos_session` (`session_id`, `client_id`, `time`) VALUES ('2d067a087170104742659a5630fa91f1', 0, 1349160520)


P.S Code that creates new databases on the fly looks a bit scary . . .



Do you mean from a security point of view? Hmmm. When someone signs up, pays, and presses the site creation button, a new joomla installation is created including the DB etc.

Anyway, i guess this is an issue for the joomla forum so i wont waste any more of your time.

Thanks for your help🙂
GreyHead 02 Oct, 2012
Hi glens1234,

Ah, OK I hadn't realised that the code was creating a new site - that makes more sense. It looks as though the either the DB creation, or something in the table creation is failing to give this error.

Could it be a problem with the table prefix as jos_ is no longer standard in Joomla! 2.5??

Bob
glens1234 02 Oct, 2012
The DB creation appears to work, however, the DB is not getting populated with tables. I tried changing the prefix to #_ but that didnt work either. i have no idea what the problem is.

Whats the difference between...

$db =& JFactory::getDBO($options);


and

$db =& new JDatabaseMySQL($options);


i think the point in my code which creates the table is this...

  
	$db1->setQuery($q);
	$result = $db1->query();


I know thats not very helpful but ive been staring at the code for hours now and im still not sure what could prevent the DB tables from being created. Are there any changes to the way queries are set in joomla 2.5? I have looked around the forums etc but im not sure what im looking for. Anyway, thanks again for your help.
GreyHead 02 Oct, 2012
Hi glens1234 ,

From a quick look one is using $db and the other $db1. Given that $db (or $database) is usually used for the current Joomla! database I'd switch both of these to something different and distinct.

This isn't a big problem as the scope of the variable will be limited to the current code block but it does help avoid confusion.

Bob
glens1234 02 Oct, 2012
I have just noticed in the global config the following message...

Fatal error: Class JDatabaseMySQL contains 4 abstract methods and must therefore be declared abstract or implement the remaining methods (JDatabase::lockTable, JDatabase::execute, JDatabase::renameTable, ...) in /home/xxxxx/public_html/libraries/joomla/database/database/mysql1.php on line 770



i then unpacked the joomla 2.5 file and noticed that mysql1.php and mysql2.php are not even present in the latest version of joomla so they must have been there from before. I remove them and it fixed the issue in the global config but still no joy with the table creation.😟

Thanks anyway
glens1234 02 Oct, 2012
Im getting closer. The new website is now created along with the DB including the tables. I had to change "__construct" to "public" in mysql.php.

However, the UPDATE statement in my script is not working for some reason. i.e...

$query_date = "UPDATE ".$table_name." ".$data_date." WHERE id= '81'";
$db1->setQuery($query_date);
$result1 = $db1->query();


Do you have any idea why this might be?

Thanks
GreyHead 02 Oct, 2012
Hi glens1234,

Hard to say without seeing the values of the variables. Try adding a line or two of debug code:
$mainframe =& JFactory::getApplication();
$query_date = "UPDATE ".$table_name." ".$data_date." WHERE id= '81'";
$mainframe->enqueuemessage('$query_date: '.print_r($query_date, true).'<hr />');
$db1->setQuery($query_date);
$result1 = $db1->query();

Bob
glens1234 02 Oct, 2012
ok thanks. ill look into that now. i was just wandering...

I noticed a Data To Session event onSubmit and a Session To Data event on FinishProcess. Both of which are there but they are blank (not configured). Could it be that the chronoforms upgrade removed the configuration for these events? Im speculating of course, but it seems to me that these need to be configured in order to pass the data between the forms. I have looked for some tutorials about these event but i havent seen anything. could that be the reason why the UPDATE statement is not working and if so could you inform me how to configure these events?

BTW, i checked phpmyadmin to look at the values of the variables and they are still default. They do not get updated.

EDIT: Actually, ignore that. If the site name is being generated based on the names entered on the signup form then it must be storing this data somewhere. hmmm. im lost😟

Thanks.
GreyHead 02 Oct, 2012
HI glens1234,

The only configuration for the Session/Data actions it to make sure that they both have the same Session Key if they are in different forms as the default is to use the form name.

Bob
This topic is locked and no more replies can be posted.