From 9eae34a94bdaef1389431225ae9a1aa78210d531 Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Tue, 19 Jan 2021 17:19:36 +0100
Subject: [PATCH] Normaliser le comportement de document_instituer() en
 appelant les pipelines pre_editon et post_edition avec action=instituer

---
 action/editer_document.php | 76 ++++++++++++++++++++++++++++----------
 paquet.xml                 |  2 +-
 2 files changed, 57 insertions(+), 21 deletions(-)

diff --git a/action/editer_document.php b/action/editer_document.php
index ebafc127..3a61698a 100644
--- a/action/editer_document.php
+++ b/action/editer_document.php
@@ -236,30 +236,66 @@ function document_instituer($id_document, $champs = array()) {
 			return false;
 		}
 	}
-	if ($statut !== $statut_ancien
-		or $date_publication != $date_publication_ancienne
-	) {
-		sql_updateq(
-			'spip_documents',
-			array('statut' => $statut, 'date_publication' => $date_publication),
-			'id_document=' . intval($id_document)
+
+	$champs = array();
+	if ($statut !== $statut_ancien) {
+		$champs['statut'] = $statut;
+	}
+	if ($date_publication != $date_publication_ancienne) {
+		$champs['date_publication'] = $date_publication;
+	}
+
+	// Envoyer aux plugins
+	$champs = pipeline('pre_edition',
+		array(
+			'args' => array(
+				'table' => 'spip_documents',
+				'id_objet' => $id_document,
+				'action' => 'instituer',
+				'statut_ancien' => $statut_ancien,
+				'date_ancienne' => $date_publication_ancienne,
+			),
+			'data' => $champs
+		)
+	);
+
+	if (!count($champs)) {
+		return false;
+	}
+
+	sql_updateq('spip_documents', $champs, 'id_document=' . intval($id_document));
+	if ($statut !== $statut_ancien) {
+		$publier_rubriques = sql_allfetsel(
+			'id_objet',
+			'spip_documents_liens',
+			"objet='rubrique' AND id_document=" . intval($id_document)
 		);
-		if ($statut !== $statut_ancien) {
-			$publier_rubriques = sql_allfetsel(
-				'id_objet',
-				'spip_documents_liens',
-				"objet='rubrique' AND id_document=" . intval($id_document)
-			);
-			if (count($publier_rubriques)) {
-				include_spip('inc/rubriques');
-				foreach ($publier_rubriques as $r) {
-					calculer_rubriques_if($r['id_objet'], array('statut' => $statut), $statut_ancien, false);
-				}
+		if (count($publier_rubriques)) {
+			include_spip('inc/rubriques');
+			foreach ($publier_rubriques as $r) {
+				calculer_rubriques_if($r['id_objet'], array('statut' => $statut), $statut_ancien, false);
 			}
 		}
-		return true;
 	}
-	return false;
+
+	// Invalider les caches
+	include_spip('inc/invalideur');
+	suivre_invalideur("id='document/$id_document'");
+
+	pipeline('post_edition',
+		array(
+			'args' => array(
+				'table' => 'spip_documents',
+				'id_objet' => $id_document,
+				'action' => 'instituer',
+				'statut_ancien' => $statut_ancien,
+				'date_ancienne' => $date_publication_ancienne,
+			),
+			'data' => $champs
+		)
+	);
+
+	return true;
 }
 
 
diff --git a/paquet.xml b/paquet.xml
index bb42d0ad..87a54c5d 100644
--- a/paquet.xml
+++ b/paquet.xml
@@ -1,7 +1,7 @@
 <paquet
 	prefix="medias"
 	categorie="multimedia"
-	version="2.28.1"
+	version="2.29.0"
 	etat="stable"
 	compatibilite="[3.3.0-dev;3.3.*]"
 	logo="prive/themes/spip/images/portfolio-32.png"
-- 
GitLab