[eZ 4.0.0] Extension works once

Author Message

Damien MARTIN

Monday 05 January 2009 6:24:15 am

Hi everybody !

I have a problem with an extension that I'm writing.

The problem is that my fetch is only done when eZ put the page in cache. Once the page is stored, the method from the extension is not called.

<b>Function_definition.php</b>

<?php
	
	$FunctionList['forum_visiter'] = array(
	
		'name' => 'forum_visiter',
		'operation_types' => array(),
		'call_method' => array( 
		
			'include_file' => 'extension/damien/modules/damien/forum.php',
			'class' => 'Forum',
			'method' => 'visiter' ),
			
		'parameter_type' => 'standard',
		'parameters' => array(
		
			array( 	'name' => 'utilisateur', 'type' => 'string', 'required' => true ),
			array( 	'name' => 'topic', 'type' => 'string', 'required' => false )
		
		)
	
	);
	
?>

<b>forum.php</b>

<?php
	
	class Forum {
		
		/**
		 * Rajoute une entrée dans la base de données pour dire quand un utilisateur a été voir un sujet pour la derniere fois
		 * \arg $utilisateur ID de l'utilisateur
		 * \arg $topic ID du noeud correspondant au topic
		 * \return Rien d'utile : true tout le temps
		 */
		function visiter($utilisateur, $topic){
			
			echo "<p>Forum::visiter()</p>";
			
			mysql_connect("xxxxxxxxxx", "xxxxxxxxx", "xxxxxxxxx");
			mysql_select_db("xxxxxxxxx");
			 
			$res = mysql_query("SELECT * FROM visites WHERE id_utilisateur = $utilisateur AND id_topic = $topic");
			
			if(mysql_num_rows($res) > 0)
				$sql = "UPDATE visites SET id_utilisateur = $utilisateur, id_topic = $topic, date_visite = ".time();
			else
				$sql = "INSERT INTO visites (id_utilisateur, id_topic, date_visite) VALUES ($utilisateur, $topic, ".time().")";
			
			mysql_query($sql);
			
			return array("result" => true);
			
		}
		
	}
 
?>

<b>What does it should do ?</b>

When I call the fetch method 'forum_visiter', it should update a database. And it works ! Untill the page is not cached...

Could you give me the reason of this strange behaviour (and how to correct it) ?

Thank in advance

Björn Dieding@xrow.de

Monday 05 January 2009 8:54:52 am

hi you have two options.

either you disable the viewcache for that page

or

you write a new module that you call after the page is loaded. I would do this with a fake js request.

<script type="text/javascript" charset="utf-8" src={concat('view/count/',$node.node_id)|ezurl}></script>

Looking for a new job? http://www.xrow.com/xrow-GmbH/Jobs
Looking for hosting? http://hostingezpublish.com
-----------------------------------------------------------------------------
GMT +01:00 Hannover, Germany
Web: http://www.xrow.com/

Damien MARTIN

Tuesday 06 January 2009 1:37:00 am

I resolved the problem using

{set-block scope=root variable=cache_ttl}0{/set-block}

like you said in your answer.

Thank you very much Björn.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.