fix: asegurar despliegue del calendario litúrgico
This commit is contained in:
@@ -1259,6 +1259,23 @@ add_shortcode('fea_evangelio_diario', function($atts) {
|
|||||||
return $id ? get_post((int) $id) : null;
|
return $id ? get_post((int) $id) : null;
|
||||||
};
|
};
|
||||||
$video = $find_video();
|
$video = $find_video();
|
||||||
|
// Hasta que el importador instale el JSON y reindexe, conservar el contenido
|
||||||
|
// civil heredado evita dejar la pestaña de texto en blanco durante el despliegue.
|
||||||
|
if (!$texto && !$book_index) {
|
||||||
|
$legacy_text = function() use ($titulo_dia) {
|
||||||
|
global $wpdb;
|
||||||
|
$id = $wpdb->get_var($wpdb->prepare(
|
||||||
|
"SELECT p.ID FROM {$wpdb->posts} p
|
||||||
|
JOIN {$wpdb->term_relationships} tr ON tr.object_id = p.ID
|
||||||
|
JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
|
||||||
|
WHERE tt.taxonomy = 'category' AND tt.term_id = 14
|
||||||
|
AND p.post_type = 'post' AND p.post_status = 'publish'
|
||||||
|
AND LOWER(TRIM(p.post_title)) = %s
|
||||||
|
ORDER BY p.ID ASC LIMIT 1", $titulo_dia));
|
||||||
|
return $id ? get_post((int) $id) : null;
|
||||||
|
};
|
||||||
|
$texto = $legacy_text();
|
||||||
|
}
|
||||||
|
|
||||||
// navegación por día del calendario (año irrelevante; usamos un año bisiesto fijo)
|
// navegación por día del calendario (año irrelevante; usamos un año bisiesto fijo)
|
||||||
$base = get_permalink();
|
$base = get_permalink();
|
||||||
|
|||||||
@@ -12,7 +12,9 @@
|
|||||||
*/
|
*/
|
||||||
$apply = getenv('FEA_EVANGELIO_APPLY') === '1';
|
$apply = getenv('FEA_EVANGELIO_APPLY') === '1';
|
||||||
$book_file = __DIR__ . '/../data/evangelio-diario/entradas-libro.json';
|
$book_file = __DIR__ . '/../data/evangelio-diario/entradas-libro.json';
|
||||||
|
$calendar_file = __DIR__ . '/../data/evangelio-diario/calendario-liturgico-2026-2040.json';
|
||||||
if (!is_readable($book_file)) { fwrite(STDERR, "No se lee $book_file\n"); exit(2); }
|
if (!is_readable($book_file)) { fwrite(STDERR, "No se lee $book_file\n"); exit(2); }
|
||||||
|
if (!is_readable($calendar_file)) { fwrite(STDERR, "No se lee $calendar_file\n"); exit(2); }
|
||||||
$book = json_decode(file_get_contents($book_file), true, 512, JSON_THROW_ON_ERROR);
|
$book = json_decode(file_get_contents($book_file), true, 512, JSON_THROW_ON_ERROR);
|
||||||
if (count($book) !== 500) { fwrite(STDERR, "El libro debe tener 500 entradas\n"); exit(2); }
|
if (count($book) !== 500) { fwrite(STDERR, "El libro debe tener 500 entradas\n"); exit(2); }
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ $existing = get_posts([
|
|||||||
'category' => 14, 'orderby' => 'ID', 'order' => 'ASC',
|
'category' => 14, 'orderby' => 'ID', 'order' => 'ASC',
|
||||||
]);
|
]);
|
||||||
$used = [];
|
$used = [];
|
||||||
$updated = $ambiguous = $unmatched = 0;
|
$updated = $ambiguous = $unmatched = $duplicate = 0;
|
||||||
$to_update = [];
|
$to_update = [];
|
||||||
foreach ($existing as $post) {
|
foreach ($existing as $post) {
|
||||||
$matches = [];
|
$matches = [];
|
||||||
@@ -38,22 +40,31 @@ foreach ($existing as $post) {
|
|||||||
if (str_contains($norm($post->post_content), $motto)) $matches = array_merge($matches, $indices);
|
if (str_contains($norm($post->post_content), $motto)) $matches = array_merge($matches, $indices);
|
||||||
}
|
}
|
||||||
$matches = array_values(array_unique($matches));
|
$matches = array_values(array_unique($matches));
|
||||||
if (count($matches) !== 1 || isset($used[$matches[0]])) {
|
if (count($matches) !== 1) {
|
||||||
$ambiguous += count($matches) > 1; $unmatched += count($matches) === 0;
|
$ambiguous += count($matches) > 1; $unmatched += count($matches) === 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (isset($used[$matches[0]])) { $duplicate++; continue; }
|
||||||
$idx = $matches[0]; $used[$idx] = true;
|
$idx = $matches[0]; $used[$idx] = true;
|
||||||
$entry = $book[$idx - 1];
|
$entry = $book[$idx - 1];
|
||||||
$to_update[] = [$post->ID, $idx, $entry];
|
$to_update[] = [$post->ID, $idx, $entry];
|
||||||
$updated++;
|
$updated++;
|
||||||
}
|
}
|
||||||
$planned_new = count($book) - count($used);
|
$planned_new = count($book) - count($used);
|
||||||
if ($ambiguous || $unmatched) {
|
if ($ambiguous || $unmatched || $duplicate) {
|
||||||
printf("DRY-RUN: existentes indexados=%d; nuevos=%d; ambiguos=%d; sin coincidencia=%d; total=%d\n",
|
printf("DRY-RUN: existentes indexados=%d; nuevos=%d; ambiguos=%d; sin coincidencia=%d; duplicados=%d; total=%d\n",
|
||||||
$updated, $planned_new, $ambiguous, $unmatched, count($book));
|
$updated, $planned_new, $ambiguous, $unmatched, $duplicate, count($book));
|
||||||
fwrite(STDERR, "ABORTAR APLICACIÓN: hay posts existentes sin correspondencia única.\n");
|
fwrite(STDERR, "ABORTAR APLICACIÓN: hay posts existentes sin correspondencia única.\n");
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
// El JSON se instala antes de tocar contenido: el shortcode lo consume desde
|
||||||
|
// WP_CONTENT_DIR/fea-data y así código y calendario llegan como una unidad.
|
||||||
|
if ($apply) {
|
||||||
|
$calendar_target = WP_CONTENT_DIR . '/fea-data/calendario-liturgico-2026-2040.json';
|
||||||
|
if (!wp_mkdir_p(dirname($calendar_target)) || !copy($calendar_file, $calendar_target)) {
|
||||||
|
fwrite(STDERR, "No se pudo instalar el calendario en $calendar_target\n"); exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($apply) foreach ($to_update as [$post_id, $idx, $entry]) {
|
if ($apply) foreach ($to_update as [$post_id, $idx, $entry]) {
|
||||||
update_post_meta($post_id, '_fea_book_index', (string) $idx);
|
update_post_meta($post_id, '_fea_book_index', (string) $idx);
|
||||||
update_post_meta($post_id, '_fea_cita', $entry['citation']);
|
update_post_meta($post_id, '_fea_cita', $entry['citation']);
|
||||||
@@ -78,5 +89,5 @@ foreach ($book as $i => $entry) {
|
|||||||
}
|
}
|
||||||
$created++;
|
$created++;
|
||||||
}
|
}
|
||||||
printf("%s: existentes indexados=%d; nuevos=%d; ambiguos=%d; sin coincidencia=%d; total=%d\n",
|
printf("%s: existentes indexados=%d; nuevos=%d; ambiguos=%d; sin coincidencia=%d; duplicados=%d; total=%d\n",
|
||||||
$apply ? 'APLICADO' : 'DRY-RUN', $updated, $created, $ambiguous, $unmatched, count($book));
|
$apply ? 'APLICADO' : 'DRY-RUN', $updated, $created, $ambiguous, $unmatched, $duplicate, count($book));
|
||||||
|
|||||||
Reference in New Issue
Block a user