Delete articles and SectionTAs that have another version created
This commit is contained in:
parent
6ec03e49d8
commit
5062a83448
1 changed files with 172 additions and 1 deletions
|
@ -263,12 +263,14 @@ async function exportLegiTexteToMarkdown(
|
||||||
|
|
||||||
for await (const {
|
for await (const {
|
||||||
lienSectionTa,
|
lienSectionTa,
|
||||||
|
liensSectionTa,
|
||||||
parentsSectionTa,
|
parentsSectionTa,
|
||||||
sectionTa,
|
sectionTa,
|
||||||
} of walkStructureTree(context, textelrStructure as LegiSectionTaStructure)) {
|
} of walkStructureTree(context, textelrStructure as LegiSectionTaStructure)) {
|
||||||
await registerLegiSectionTaModifiers(
|
await registerLegiSectionTaModifiers(
|
||||||
context,
|
context,
|
||||||
parentsSectionTa.length + 1,
|
parentsSectionTa.length + 1,
|
||||||
|
liensSectionTa,
|
||||||
lienSectionTa,
|
lienSectionTa,
|
||||||
sectionTa,
|
sectionTa,
|
||||||
)
|
)
|
||||||
|
@ -1113,6 +1115,22 @@ async function registerLegiArticleModifiers(
|
||||||
articleDateDebut,
|
articleDateDebut,
|
||||||
articleDateFin,
|
articleDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const articleVersion of article.VERSIONS.VERSION) {
|
||||||
|
if (articleVersion.LIEN_ART["@id"] === articleId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (articleVersion.LIEN_ART["@fin"] === articleDateDebut) {
|
||||||
|
await addArticleModificateurId(
|
||||||
|
context,
|
||||||
|
articleLien.article_id,
|
||||||
|
"DELETE",
|
||||||
|
articleVersion.LIEN_ART["@id"],
|
||||||
|
articleVersion.LIEN_ART["@debut"],
|
||||||
|
articleVersion.LIEN_ART["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
(articleLien.typelien === "CREATION" && !articleLien.cible) ||
|
(articleLien.typelien === "CREATION" && !articleLien.cible) ||
|
||||||
(articleLien.typelien === "MODIFICATION" && !articleLien.cible)
|
(articleLien.typelien === "MODIFICATION" && !articleLien.cible)
|
||||||
|
@ -1179,6 +1197,22 @@ async function registerLegiArticleModifiers(
|
||||||
articleDateDebut,
|
articleDateDebut,
|
||||||
articleDateFin,
|
articleDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const articleVersion of article.VERSIONS.VERSION) {
|
||||||
|
if (articleVersion.LIEN_ART["@id"] === articleId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (articleVersion.LIEN_ART["@fin"] === articleDateDebut) {
|
||||||
|
await addTexteModificateurId(
|
||||||
|
context,
|
||||||
|
texteVersionLien.texte_version_id,
|
||||||
|
"DELETE",
|
||||||
|
articleVersion.LIEN_ART["@id"],
|
||||||
|
articleVersion.LIEN_ART["@debut"],
|
||||||
|
articleVersion.LIEN_ART["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unexpected texte_version_lien to article ${lienArticle["@id"]}: typelien=${texteVersionLien.typelien}, cible=${texteVersionLien.cible}`,
|
`Unexpected texte_version_lien to article ${lienArticle["@id"]}: typelien=${texteVersionLien.typelien}, cible=${texteVersionLien.cible}`,
|
||||||
|
@ -1277,6 +1311,22 @@ async function registerLegiArticleModifiers(
|
||||||
articleDateDebut,
|
articleDateDebut,
|
||||||
articleDateFin,
|
articleDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const articleVersion of article.VERSIONS.VERSION) {
|
||||||
|
if (articleVersion.LIEN_ART["@id"] === articleId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (articleVersion.LIEN_ART["@fin"] === articleDateDebut) {
|
||||||
|
await addTexteModificateurId(
|
||||||
|
context,
|
||||||
|
articleLien["@cidtexte"],
|
||||||
|
"DELETE",
|
||||||
|
articleVersion.LIEN_ART["@id"],
|
||||||
|
articleVersion.LIEN_ART["@debut"],
|
||||||
|
articleVersion.LIEN_ART["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
articleLien["@typelien"] === "CREATION" &&
|
articleLien["@typelien"] === "CREATION" &&
|
||||||
articleLien["@sens"] === "cible"
|
articleLien["@sens"] === "cible"
|
||||||
|
@ -1301,6 +1351,22 @@ async function registerLegiArticleModifiers(
|
||||||
articleDateDebut,
|
articleDateDebut,
|
||||||
articleDateFin,
|
articleDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const articleVersion of article.VERSIONS.VERSION) {
|
||||||
|
if (articleVersion.LIEN_ART["@id"] === articleId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (articleVersion.LIEN_ART["@fin"] === articleDateDebut) {
|
||||||
|
await addTexteModificateurId(
|
||||||
|
context,
|
||||||
|
article.CONTEXTE.TEXTE["@cid"],
|
||||||
|
"DELETE",
|
||||||
|
articleVersion.LIEN_ART["@id"],
|
||||||
|
articleVersion.LIEN_ART["@debut"],
|
||||||
|
articleVersion.LIEN_ART["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If article has no texte créateur at all, then create a fake one.
|
// If article has no texte créateur at all, then create a fake one.
|
||||||
|
@ -1315,12 +1381,30 @@ async function registerLegiArticleModifiers(
|
||||||
texteModificateurIdByAction.CREATE = texteManquantId
|
texteModificateurIdByAction.CREATE = texteManquantId
|
||||||
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
||||||
{}).CREATE ??= new Set()).add(articleId)
|
{}).CREATE ??= new Set()).add(articleId)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const articleVersion of article.VERSIONS.VERSION) {
|
||||||
|
if (articleVersion.LIEN_ART["@id"] === articleId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (articleVersion.LIEN_ART["@fin"] === articleDateDebut) {
|
||||||
|
const texteModificateurIdByAction =
|
||||||
|
(context.texteModificateurIdByActionById[
|
||||||
|
articleVersion.LIEN_ART["@id"]
|
||||||
|
] ??= {})
|
||||||
|
if (texteModificateurIdByAction.DELETE === undefined) {
|
||||||
|
texteModificateurIdByAction.DELETE = texteManquantId
|
||||||
|
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
||||||
|
{}).DELETE ??= new Set()).add(articleVersion.LIEN_ART["@id"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function registerLegiSectionTaModifiers(
|
async function registerLegiSectionTaModifiers(
|
||||||
context: Context,
|
context: Context,
|
||||||
depth: number,
|
depth: number,
|
||||||
|
liensSectionTa: LegiSectionTaLienSectionTa[],
|
||||||
lienSectionTa: LegiSectionTaLienSectionTa,
|
lienSectionTa: LegiSectionTaLienSectionTa,
|
||||||
sectionTa: LegiSectionTa,
|
sectionTa: LegiSectionTa,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
@ -1376,6 +1460,26 @@ async function registerLegiSectionTaModifiers(
|
||||||
sectionTaDateDebut,
|
sectionTaDateDebut,
|
||||||
sectionTaDateFin,
|
sectionTaDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const otherLienSectionTa of liensSectionTa) {
|
||||||
|
if (otherLienSectionTa["@id"] === sectionTaId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
otherLienSectionTa["@cid"] === lienSectionTa["@cid"] &&
|
||||||
|
otherLienSectionTa["@fin"] === sectionTaDateDebut
|
||||||
|
) {
|
||||||
|
// The other sectionTa is the old version of the sectionTa.
|
||||||
|
await addArticleModificateurId(
|
||||||
|
context,
|
||||||
|
articleLien.article_id,
|
||||||
|
"DELETE",
|
||||||
|
otherLienSectionTa["@id"],
|
||||||
|
otherLienSectionTa["@debut"],
|
||||||
|
otherLienSectionTa["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unexpected article_lien to Section Texte Article ${lienSectionTa["@id"]}: typelien=${articleLien.typelien}, cible=${articleLien.cible}`,
|
`Unexpected article_lien to Section Texte Article ${lienSectionTa["@id"]}: typelien=${articleLien.typelien}, cible=${articleLien.cible}`,
|
||||||
|
@ -1421,6 +1525,26 @@ async function registerLegiSectionTaModifiers(
|
||||||
sectionTaDateDebut,
|
sectionTaDateDebut,
|
||||||
sectionTaDateFin,
|
sectionTaDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const otherLienSectionTa of liensSectionTa) {
|
||||||
|
if (otherLienSectionTa["@id"] === sectionTaId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
otherLienSectionTa["@cid"] === lienSectionTa["@cid"] &&
|
||||||
|
otherLienSectionTa["@fin"] === sectionTaDateDebut
|
||||||
|
) {
|
||||||
|
// The other sectionTa is the old version of the sectionTa.
|
||||||
|
await addArticleModificateurId(
|
||||||
|
context,
|
||||||
|
texteVersionLien.texte_version_id,
|
||||||
|
"DELETE",
|
||||||
|
otherLienSectionTa["@id"],
|
||||||
|
otherLienSectionTa["@debut"],
|
||||||
|
otherLienSectionTa["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unexpected texte_version_lien to Section Texte Article ${lienSectionTa["@id"]}: typelien=${texteVersionLien.typelien}, cible=${texteVersionLien.cible}`,
|
`Unexpected texte_version_lien to Section Texte Article ${lienSectionTa["@id"]}: typelien=${texteVersionLien.typelien}, cible=${texteVersionLien.cible}`,
|
||||||
|
@ -1438,6 +1562,26 @@ async function registerLegiSectionTaModifiers(
|
||||||
sectionTaDateDebut,
|
sectionTaDateDebut,
|
||||||
sectionTaDateFin,
|
sectionTaDateFin,
|
||||||
)
|
)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const otherLienSectionTa of liensSectionTa) {
|
||||||
|
if (otherLienSectionTa["@id"] === sectionTaId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
otherLienSectionTa["@cid"] === lienSectionTa["@cid"] &&
|
||||||
|
otherLienSectionTa["@fin"] === sectionTaDateDebut
|
||||||
|
) {
|
||||||
|
// The other sectionTa is the old version of the sectionTa.
|
||||||
|
await addArticleModificateurId(
|
||||||
|
context,
|
||||||
|
sectionTa.CONTEXTE.TEXTE["@cid"],
|
||||||
|
"DELETE",
|
||||||
|
otherLienSectionTa["@id"],
|
||||||
|
otherLienSectionTa["@debut"],
|
||||||
|
otherLienSectionTa["@fin"],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If Section Texte Article has no texte créateur at all, then use a fake one.
|
// If Section Texte Article has no texte créateur at all, then use a fake one.
|
||||||
|
@ -1452,6 +1596,27 @@ async function registerLegiSectionTaModifiers(
|
||||||
texteModificateurIdByAction.CREATE = texteManquantId
|
texteModificateurIdByAction.CREATE = texteManquantId
|
||||||
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
||||||
{}).CREATE ??= new Set()).add(sectionTaId)
|
{}).CREATE ??= new Set()).add(sectionTaId)
|
||||||
|
// Delete another version of the same article that existed before the newly created one.
|
||||||
|
for (const otherLienSectionTa of liensSectionTa) {
|
||||||
|
if (otherLienSectionTa["@id"] === sectionTaId) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
otherLienSectionTa["@cid"] === lienSectionTa["@cid"] &&
|
||||||
|
otherLienSectionTa["@fin"] === sectionTaDateDebut
|
||||||
|
) {
|
||||||
|
// The other sectionTa is the old version of the sectionTa.
|
||||||
|
const texteModificateurIdByAction =
|
||||||
|
(context.texteModificateurIdByActionById[
|
||||||
|
otherLienSectionTa["@id"]
|
||||||
|
] ??= {})
|
||||||
|
if (texteModificateurIdByAction.DELETE === undefined) {
|
||||||
|
texteModificateurIdByAction.DELETE = texteManquantId
|
||||||
|
;((context.idsByActionByTexteMoficateurId[texteManquantId] ??=
|
||||||
|
{}).DELETE ??= new Set()).add(otherLienSectionTa["@id"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1462,6 +1627,7 @@ async function* walkStructureTree(
|
||||||
): AsyncGenerator<
|
): AsyncGenerator<
|
||||||
{
|
{
|
||||||
lienSectionTa: LegiSectionTaLienSectionTa
|
lienSectionTa: LegiSectionTaLienSectionTa
|
||||||
|
liensSectionTa: LegiSectionTaLienSectionTa[]
|
||||||
parentsSectionTa: LegiSectionTa[]
|
parentsSectionTa: LegiSectionTa[]
|
||||||
sectionTa: LegiSectionTa
|
sectionTa: LegiSectionTa
|
||||||
},
|
},
|
||||||
|
@ -1475,7 +1641,12 @@ async function* walkStructureTree(
|
||||||
lienSectionTa["@id"],
|
lienSectionTa["@id"],
|
||||||
)
|
)
|
||||||
context.legiTexteInternalIds.add(lienSectionTa["@id"])
|
context.legiTexteInternalIds.add(lienSectionTa["@id"])
|
||||||
yield { lienSectionTa, parentsSectionTa, sectionTa: childSectionTa }
|
yield {
|
||||||
|
lienSectionTa,
|
||||||
|
liensSectionTa,
|
||||||
|
parentsSectionTa,
|
||||||
|
sectionTa: childSectionTa,
|
||||||
|
}
|
||||||
const childStructure = childSectionTa.STRUCTURE_TA
|
const childStructure = childSectionTa.STRUCTURE_TA
|
||||||
if (childStructure !== undefined) {
|
if (childStructure !== undefined) {
|
||||||
yield* walkStructureTree(context, childStructure, [
|
yield* walkStructureTree(context, childStructure, [
|
||||||
|
|
Loading…
Add table
Reference in a new issue