Page 1 of 1

CMS does not evaluate included scripts

Posted: Fri Nov 21, 2008 10:27 am
by jensr
Hi,

I wrote a modul that just includes another script. This worked fine until version 1.4. With version 1.4 it seems like CMS Made simple does not evaluate the content of the included script anymore:

TestModule.module.php:

Code: Select all

<?php

class TestModule extends CMSModule
{
    function GetName()
    {
        return 'TestModule';
    }

    function GetFriendlyName()
    {
        return 'testModule';
    }

    function GetVersion()
    {
        return '1.0';
    }
         
    function IsPluginModule()
    {
         return true;
    }
	
	function Install()
	{
		//
	}
	
	function InstallPostMessage()
	{
		return "Installed TestModule Module successfully";
	}
	
	function Uninstall()
	{
		//
	}
	
	function UninstallPostMessage()
	{
		return "TestModule Module successfully uninstalled";
	}
	
	function DoAction($action, $id, $params, $returnid=-1)
	{		
		error_reporting(E_ALL);
	
		require_once('include_me.php');
		
                test();

		return;
	}
}

?>
include_me.php

Code: Select all

<?php

echo "1";

function test()
{
	echo "2";
}

?>
The output in Version 1.4 is: 2
The output in Version 1.3 is: 12

Perhaps someone can help me?

Kind regards
Jens

Re: CMS does not evaluate included scripts

Posted: Sat Nov 22, 2008 8:22 am
by oi_antz
Are you sure it is not echoing 1 somewhere other than where you expect it? It sounds to me like DoAction might be called earlier in the execution than you expect, and the require_once statement is preventing it from being called a second time when you use the cms_module tag. Try changing echo "1" to echo "abcdefg" and do a search in the source for abcedfg.

Re: CMS does not evaluate included scripts

Posted: Sat Nov 22, 2008 3:23 pm
by jensr
Hi oi_antz,

I changed "1" to "abcdefg" but I can't find it in the source code.

When I change the include type to from "require_once" to "require" I get a "Cannot redeclare test() Error". So it seems like the function is realley called more that one time, but I am wondering why I can't find "abcdefg" in the source code.

The strange thing is, that this module works with fine with version 1.3, but not 1.4.

Kind regards,
Jens

Re: CMS does not evaluate included scripts

Posted: Mon Nov 24, 2008 4:31 am
by oi_antz
Try this code at the start of method DoAction(), might give some insight into the execution path:

Code: Select all

<?php
if(!isset($this->counter)) $this->counter = 0;
$this->counter++;
try{
    throw new exception('called '.$this->counter.' times for action: '.$action);
}catch(exception $e){
    echo '<h2>'.$e->getMessage().'</h2><pre>'."\n".$e->getTraceAsString().'</pre>';
}

Re: CMS does not evaluate included scripts

Posted: Mon Nov 24, 2008 8:03 am
by jensr
Ok, this code echoes following output:
called 2 times for action: default

#0 /var/www/vhosts/test/httpdocs/lib/classes/class.module.inc.php(1535): TestModule->DoAction('default', 'm5', Array, '17')
#1 /var/www/vhosts/test/httpdocs/lib/module.functions.php(130): CMSModule->DoActionBase('default', 'm5', Array, '17')
#2 /var/www/vhosts/test/httpdocs/plugins/function.cms_module.php(21): cms_module_plugin(Array, Object(Smarty_CMS))
#3 /var/www/vhosts/test/httpdocs/tmp/templates_c/17-^%%70^707^707A8977%%content%3Acontent_en.php(5): smarty_cms_function_cms_module(Array, Object(Smarty_CMS))
#4 /var/www/vhosts/test/httpdocs/lib/smarty/Smarty.class.php(1265): include('/var/www/vhosts...')
#5 /var/www/vhosts/test/httpdocs/plugins/function.content.php(118): Smarty->fetch('content:content...', '', '17-')
#6 /var/www/vhosts/test/httpdocs/tmp/templates_c/^%%70^705^70549F33%%template%3A28.php(179): smarty_cms_function_content(Array, Object(Smarty_CMS))
#7 /var/www/vhosts/test/httpdocs/lib/smarty/Smarty.class.php(1265): include('/var/www/vhosts...')
#8 /var/www/vhosts/test/httpdocs/index.php(290): Smarty->fetch('template:28', '', '')
#9 {main}

Re: CMS does not evaluate included scripts

Posted: Mon Nov 24, 2008 8:37 am
by oi_antz
Ok, thats good news, meaning you only get instantiated once. Try putting

Code: Select all

echo $action; 
exit;
after the code I gave you, will display the first stack trace, you should be able to investigate with that info.

Re: CMS does not evaluate included scripts

Posted: Mon Nov 24, 2008 9:29 am
by jensr
Hi oi_antz,

thanks a lot for your great help.

I modified the module like this:

Code: Select all

<?php

class TestModule extends CMSModule
{
    function GetName()
    {
        return 'TestModule';
    }

    function GetFriendlyName()
    {
        return 'testModule';
    }

    function GetVersion()
    {
        return '1.0';
    }
         
    function IsPluginModule()
    {
         return true;
    }
	
	function Install()
	{
		//
	}
	
	function InstallPostMessage()
	{
		return "Installed TestModule Module successfully";
	}
	
	function Uninstall()
	{
		//
	}
	
	function UninstallPostMessage()
	{
		return "TestModule Module successfully uninstalled";
	}
	
	function DoAction($action, $id, $params, $returnid=-1)
	{		
		if(!isset($this->counter))
			$this->counter = 0;
		$this->counter++;
		
		if ($this->counter == 1)
			return;

		require('include_me.php');
		
                test();

		return;
	}
}
?>
Not very nice, but a workaround for this strange problem.

Kind regards.
Jens