From b4ee871aa937e749d6c8d970a2c6fb2534a7016c Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Mon, 10 Jan 2005 21:31:58 +0000
Subject: [PATCH] =?UTF-8?q?code=20mort=20+=20lisibilit=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/inc_cron.php3      | 17 +++++++++--------
 ecrire/inc_debug_sql.php3 |  1 -
 ecrire/inc_version.php3   | 36 ------------------------------------
 ecrire/index.php3         |  5 ++++-
 4 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/ecrire/inc_cron.php3 b/ecrire/inc_cron.php3
index 41b193697d..3280d66e00 100644
--- a/ecrire/inc_cron.php3
+++ b/ecrire/inc_cron.php3
@@ -46,14 +46,15 @@ function spip_cron($taches=array()) {
 	global $frequence_taches;
 	$t = time();
 
-	if (!@file_exists(_FILE_MYSQL_OUT)
-	OR ($t - @filemtime(_FILE_MYSQL_OUT) > 300)) {
-		include(_FILE_CONNECT);
-		if (!$GLOBALS['db_ok']) {
-			@touch(_FILE_MYSQL_OUT);
-			spip_log('pas de connexion DB pour taches de fond (cron)');
-			return;
-		}
+	if (@file_exists(_FILE_MYSQL_OUT)
+	AND ($t - @filemtime(_FILE_MYSQL_OUT) < 300))
+		return;
+
+	include(_FILE_CONNECT);
+	if (!$GLOBALS['db_ok']) {
+		@touch(_FILE_MYSQL_OUT);
+		spip_log('pas de connexion DB pour taches de fond (cron)');
+		return;
 	}
 
 	if (!$taches)
diff --git a/ecrire/inc_debug_sql.php3 b/ecrire/inc_debug_sql.php3
index 38a2f2271d..e49ccccda7 100644
--- a/ecrire/inc_debug_sql.php3
+++ b/ecrire/inc_debug_sql.php3
@@ -37,7 +37,6 @@ function erreur_requete_boucle($query, $id_boucle, $type) {
 
 	// Calmer le jeu avec MySQL (si jamais on est en saturation)
 	@touch(_FILE_MYSQL_OUT);	// pour spip_cron
-	@touch(_FILE_LOCK);		// lock hebergeur
 	spip_log('Erreur MySQL: on limite les acces quelques minutes');
 	$GLOBALS['bouton_admin_debug'] = true;
 
diff --git a/ecrire/inc_version.php3 b/ecrire/inc_version.php3
index d89942e9b9..8b15fe0d28 100644
--- a/ecrire/inc_version.php3
+++ b/ecrire/inc_version.php3
@@ -320,7 +320,6 @@ $test_dirs = array(_DIR_CACHE, _DIR_IMG, _DIR_SESSIONS);
 
 // les fichiers qu'on y met, entre autres,
 
-define_once('_FILE_LOCK', _DIR_SESSIONS . 'lock');
 define_once('_FILE_CRON_LOCK', _DIR_SESSIONS . 'cron.lock');
 define_once('_FILE_MYSQL_OUT', _DIR_SESSIONS . 'mysql_out');
 define_once('_FILE_GARBAGE', _DIR_SESSIONS . '.poubelle');
@@ -914,41 +913,6 @@ function table_objet($type) {
 }
 
 
-//
-// Savoir si on peut lancer de gros calculs, et eventuellement poser un lock SQL
-// Resultat : true=vas-y ; false=stop
-//
-function timeout($lock=false, $action=true, $connect_mysql=true) {
-	static $ok = true;
-	global $db_ok;
-
-	// Fichier lock hebergeur ?  (age maxi, 10 minutes)
-
-	if (@file_exists(_FILE_LOCK)
-	AND ((time() - @filemtime(_FILE_LOCK)) < 600))
-		return $ok = false;
-
-	// Ne rien faire ?
-	if (!$action || !$ok)
-		return $ok;
-
-	$ok = false;
-
-	// Base connectee ?
-	if ($connect_mysql) {
-		include_local(_FILE_CONNECT);
-		if (!$db_ok)
-			return false;
-
-		// Verrou demande ?
-		if ($lock AND !spip_get_lock($lock))
-			return false;
-	}
-
-	// C'est bon
-	return true;
-}
-
 //
 // spip_timer : on l'appelle deux fois et on a la difference, affichable
 //
diff --git a/ecrire/index.php3 b/ecrire/index.php3
index 3b6c1be824..2e12e3ecd9 100644
--- a/ecrire/index.php3
+++ b/ecrire/index.php3
@@ -537,10 +537,13 @@ if (abs($t_jour - date('d')) > 2) {
 //
 if (!$bonjour) {
 	if ($optimiser == 'oui' || (time() - lire_meta('date_optimisation')) > 24 * 3600) {
-		if (timeout('optimisation')) {
+		if (!file_exists($lock = _DIR_SESSIONS.'optimisation.lock')
+		OR (time()-filemtime($lock) > 3600)) {
+			touch($lock);
 			ecrire_meta("date_optimisation", time());
 			ecrire_metas();
 			include ("optimiser.php3");
+			unlink($lock);
 		}
 	}
 }
-- 
GitLab