Affichage des requêtes réalisées

This commit is contained in:
Vincent Calame 2021-10-20 19:43:09 +02:00 committed by root
parent 40b2fc0c2a
commit 98c4b5752e
2 changed files with 21 additions and 4 deletions

View File

@ -81,10 +81,11 @@ function balise_LIBREAVOUS_IMPORT($p) {
function libreavous_import_run($id_article) { function libreavous_import_run($id_article) {
$id_article = intval($id_article); $id_article = intval($id_article);
$existant = sql_select("podcast_code","spip_articles","id_article=".$id_article); $existant = sql_select("podcast_code,titre","spip_articles","id_article=".$id_article);
if ($existant and sql_count($existant)>0) { if ($existant and sql_count($existant)>0) {
$r = sql_fetch($existant); $r = sql_fetch($existant);
$code_emission = $r["podcast_code"]; $code_emission = $r["podcast_code"];
$titre_emission = $r["titre"];
if(strlen($code_emission) == 0) { if(strlen($code_emission) == 0) {
return "Le code de l'émission n'est pas renseigné"; return "Le code de l'émission n'est pas renseigné";
} }
@ -92,6 +93,7 @@ function libreavous_import_run($id_article) {
return "Émission inconnue = ".$id_article; return "Émission inconnue = ".$id_article;
} }
$erreurs = array(); $erreurs = array();
$logs = array();
$json = false; $json = false;
$podcast_duree = ""; $podcast_duree = "";
$ogg_size = ""; $ogg_size = "";
@ -189,6 +191,7 @@ function libreavous_import_run($id_article) {
'podcast_mp3' => $mp3_size, 'podcast_mp3' => $mp3_size,
'podcast_ogg' => $ogg_size 'podcast_ogg' => $ogg_size
); );
$logs[] = sql_updateq("spip_articles", $emissionArray, "id_article=".$id_article,'','',false);
sql_updateq("spip_articles", $emissionArray, "id_article=".$id_article); sql_updateq("spip_articles", $emissionArray, "id_article=".$id_article);
foreach ($chapitres as $chapitre) { foreach ($chapitres as $chapitre) {
$code_chapitre = $chapitre["short_chapter_name"]; $code_chapitre = $chapitre["short_chapter_name"];
@ -209,14 +212,29 @@ function libreavous_import_run($id_article) {
if ($chapitreExistant and sql_count($chapitreExistant)>0) { if ($chapitreExistant and sql_count($chapitreExistant)>0) {
$r = sql_fetch($chapitreExistant); $r = sql_fetch($chapitreExistant);
$id_chapitre = $r["id_chapitre"]; $id_chapitre = $r["id_chapitre"];
$logs[] = sql_updateq("spip_chapitres", $chapitreArray, "id_chapitre=".$id_chapitre,'','',false);
sql_updateq("spip_chapitres", $chapitreArray, "id_chapitre=".$id_chapitre); sql_updateq("spip_chapitres", $chapitreArray, "id_chapitre=".$id_chapitre);
} else { } else {
$logs[] = sql_insertq("spip_chapitres", $chapitreArray, '', '', false);
$id_nouveau_chapitre = sql_insertq("spip_chapitres", $chapitreArray); $id_nouveau_chapitre = sql_insertq("spip_chapitres", $chapitreArray);
} }
} }
$texteReponse = "Émission traitée : ". $code_emission; $texteReponse = "<p>Émission traitée : ". $code_emission." / ".$titre_emission."</p>";
if (count($erreurs) > 0) { if (count($erreurs) > 0) {
$texteReponse .= "<br><br>Erreurs : <br>".implode(" <br> ", $erreurs); $texteReponse .= "<h2>Erreurs</h2>";
$texteReponse .= "<ul>";
foreach ($erreurs as $erreur) {
$texteReponse .= "<li><p>".$erreur."</p></li>";
}
$texteReponse .= "</ul>";
}
if (count($logs) > 0) {
$texteReponse .= "<h2>Requêtes effectuées</h2>";
$texteReponse .= "<ul>";
foreach ($logs as $log) {
$texteReponse .= "<li><p>".$log."</p></li>";
}
$texteReponse .= "</ul>";
} }
return $texteReponse; return $texteReponse;
} }

View File

@ -3,7 +3,6 @@
<title>Import</title> <title>Import</title>
</head> </head>
<body> <body>
<p>
#LIBREAVOUS_IMPORT{#ENV{id_article}} #LIBREAVOUS_IMPORT{#ENV{id_article}}
</body> </body>
</html> </html>