[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.

eZ debug

Timing: Jan 19 2025 06:14:39
Script start
Timing: Jan 19 2025 06:14:39
Module start 'layout'
Timing: Jan 19 2025 06:14:39
Module start 'content'
Timing: Jan 19 2025 06:14:39
Module end 'content'
Timing: Jan 19 2025 06:14:39
Script end

Main resources:

Total runtime0.0149 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 590.2891152.6250
Module start 'layout' 0.00490.0024 742.914139.4453
Module start 'content' 0.00730.0056 782.359493.3516
Module end 'content' 0.01300.0019 875.710934.3047
Script end 0.0148  910.0156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002416.4633140.0002
Check MTime0.00117.3304140.0001
Mysql Total
Database connection0.00064.297810.0006
Mysqli_queries0.002013.124430.0007
Looping result0.00000.067410.0000
Template Total0.001610.610.0016
Template load0.00085.219910.0008
Template processing0.00085.388310.0008
Override
Cache load0.00063.948210.0006
General
dbfile0.00117.290380.0001
String conversion0.00000.048140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs