Ensure that cidtexte of objects match CID of LEGI texte
This commit is contained in:
parent
acfd911841
commit
bd0fce4eda
1 changed files with 12 additions and 19 deletions
|
@ -32,6 +32,7 @@ interface Context {
|
||||||
string,
|
string,
|
||||||
Partial<Record<Action, Set<string>>>
|
Partial<Record<Action, Set<string>>>
|
||||||
>
|
>
|
||||||
|
legiTexteCid: string
|
||||||
legiTexteInternalIds: Set<string>
|
legiTexteInternalIds: Set<string>
|
||||||
sectionTaById: Record<string, LegiSectionTa>
|
sectionTaById: Record<string, LegiSectionTa>
|
||||||
targetDir: string
|
targetDir: string
|
||||||
|
@ -189,19 +190,22 @@ async function exportLegiTexteToMarkdown(
|
||||||
articleModificateurIdByActionById: {},
|
articleModificateurIdByActionById: {},
|
||||||
currentInternalIds: new Set(),
|
currentInternalIds: new Set(),
|
||||||
idsByActionByTexteMoficateurId: {},
|
idsByActionByTexteMoficateurId: {},
|
||||||
legiTexteInternalIds: new Set(),
|
legiTexteCid: legiTexteId, // Temporary value, overrided below
|
||||||
|
legiTexteInternalIds: new Set([legiTexteId]),
|
||||||
sectionTaById: {},
|
sectionTaById: {},
|
||||||
targetDir,
|
targetDir,
|
||||||
texteManquantById: {},
|
texteManquantById: {},
|
||||||
texteModificateurIdByActionById: {},
|
texteModificateurIdByActionById: {},
|
||||||
texteVersionById: {},
|
texteVersionById: {},
|
||||||
}
|
}
|
||||||
context.legiTexteInternalIds.add(legiTexteId)
|
|
||||||
|
|
||||||
const texteVersion = (await getOrLoadTexteVersion(context, legiTexteId)) as
|
const texteVersion = (await getOrLoadTexteVersion(context, legiTexteId)) as
|
||||||
| JorfTexteVersion
|
| JorfTexteVersion
|
||||||
| LegiTexteVersion
|
| LegiTexteVersion
|
||||||
assert.notStrictEqual(texteVersion, null)
|
assert.notStrictEqual(texteVersion, null)
|
||||||
|
const meta = texteVersion.META
|
||||||
|
// Most of the times the CID of a LEGI text is its ID.
|
||||||
|
// But for the Constitution, for example, the CID is the ID of the JORF text.
|
||||||
|
context.legiTexteCid = meta.META_SPEC.META_TEXTE_CHRONICLE.CID
|
||||||
|
|
||||||
const textelr = (
|
const textelr = (
|
||||||
await db<{ data: LegiTextelr }[]>`
|
await db<{ data: LegiTextelr }[]>`
|
||||||
|
@ -210,7 +214,6 @@ async function exportLegiTexteToMarkdown(
|
||||||
)[0]?.data
|
)[0]?.data
|
||||||
assert.notStrictEqual(textelr, undefined)
|
assert.notStrictEqual(textelr, undefined)
|
||||||
|
|
||||||
const meta = texteVersion.META
|
|
||||||
const metaTexteVersion = meta.META_SPEC.META_TEXTE_VERSION
|
const metaTexteVersion = meta.META_SPEC.META_TEXTE_VERSION
|
||||||
console.log(
|
console.log(
|
||||||
`${meta.META_COMMUN.ID} ${metaTexteVersion.TITREFULL ?? metaTexteVersion.TITRE ?? meta.META_COMMUN.ID} (${metaTexteVersion.DATE_DEBUT ?? ""} — ${metaTexteVersion.DATE_FIN === "2999-01-01" ? "…" : (metaTexteVersion.DATE_FIN ?? "")}, ${metaTexteVersion.ETAT})`,
|
`${meta.META_COMMUN.ID} ${metaTexteVersion.TITREFULL ?? metaTexteVersion.TITRE ?? meta.META_COMMUN.ID} (${metaTexteVersion.DATE_DEBUT ?? ""} — ${metaTexteVersion.DATE_FIN === "2999-01-01" ? "…" : (metaTexteVersion.DATE_FIN ?? "")}, ${metaTexteVersion.ETAT})`,
|
||||||
|
@ -246,13 +249,7 @@ async function exportLegiTexteToMarkdown(
|
||||||
context,
|
context,
|
||||||
lienArticle["@id"],
|
lienArticle["@id"],
|
||||||
)) as LegiArticle
|
)) as LegiArticle
|
||||||
await registerLegiArticleModifiers(
|
await registerLegiArticleModifiers(context, 0, lienArticle, article)
|
||||||
context,
|
|
||||||
legiTexteId,
|
|
||||||
0,
|
|
||||||
lienArticle,
|
|
||||||
article,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +260,6 @@ async function exportLegiTexteToMarkdown(
|
||||||
} of walkStructureTree(context, textelrStructure as LegiSectionTaStructure)) {
|
} of walkStructureTree(context, textelrStructure as LegiSectionTaStructure)) {
|
||||||
await registerLegiSectionTaModifiers(
|
await registerLegiSectionTaModifiers(
|
||||||
context,
|
context,
|
||||||
legiTexteId,
|
|
||||||
parentsSectionTa.length + 1,
|
parentsSectionTa.length + 1,
|
||||||
lienSectionTa,
|
lienSectionTa,
|
||||||
sectionTa,
|
sectionTa,
|
||||||
|
@ -278,7 +274,6 @@ async function exportLegiTexteToMarkdown(
|
||||||
)) as LegiArticle
|
)) as LegiArticle
|
||||||
await registerLegiArticleModifiers(
|
await registerLegiArticleModifiers(
|
||||||
context,
|
context,
|
||||||
legiTexteId,
|
|
||||||
parentsSectionTa.length + 2,
|
parentsSectionTa.length + 2,
|
||||||
lienArticle,
|
lienArticle,
|
||||||
article,
|
article,
|
||||||
|
@ -871,7 +866,6 @@ async function getOrLoadTexteVersion(
|
||||||
|
|
||||||
async function registerLegiArticleModifiers(
|
async function registerLegiArticleModifiers(
|
||||||
context: Context,
|
context: Context,
|
||||||
legiTexteId: string,
|
|
||||||
depth: number,
|
depth: number,
|
||||||
lienArticle: LegiSectionTaLienArt,
|
lienArticle: LegiSectionTaLienArt,
|
||||||
article: LegiArticle,
|
article: LegiArticle,
|
||||||
|
@ -886,7 +880,7 @@ async function registerLegiArticleModifiers(
|
||||||
for (const articleLien of await db<ArticleLienDb[]>`
|
for (const articleLien of await db<ArticleLienDb[]>`
|
||||||
SELECT * FROM article_lien WHERE id = ${lienArticle["@id"]}
|
SELECT * FROM article_lien WHERE id = ${lienArticle["@id"]}
|
||||||
`) {
|
`) {
|
||||||
assert.strictEqual(articleLien.cidtexte, legiTexteId)
|
assert.strictEqual(articleLien.cidtexte, context.legiTexteCid)
|
||||||
if (articleLien.article_id in context.legiTexteInternalIds) {
|
if (articleLien.article_id in context.legiTexteInternalIds) {
|
||||||
// Ignore internal links because a LEGI texte can't modify itself.
|
// Ignore internal links because a LEGI texte can't modify itself.
|
||||||
continue
|
continue
|
||||||
|
@ -960,7 +954,7 @@ async function registerLegiArticleModifiers(
|
||||||
for (const texteVersionLien of await db<TexteVersionLienDb[]>`
|
for (const texteVersionLien of await db<TexteVersionLienDb[]>`
|
||||||
SELECT * FROM texte_version_lien WHERE id = ${lienArticle["@id"]}
|
SELECT * FROM texte_version_lien WHERE id = ${lienArticle["@id"]}
|
||||||
`) {
|
`) {
|
||||||
assert.strictEqual(texteVersionLien.cidtexte, legiTexteId)
|
assert.strictEqual(texteVersionLien.cidtexte, context.legiTexteCid)
|
||||||
if (texteVersionLien.texte_version_id in context.legiTexteInternalIds) {
|
if (texteVersionLien.texte_version_id in context.legiTexteInternalIds) {
|
||||||
// Ignore internal links because a LEGI texte can't modify itself.
|
// Ignore internal links because a LEGI texte can't modify itself.
|
||||||
continue
|
continue
|
||||||
|
@ -1139,7 +1133,6 @@ async function registerLegiArticleModifiers(
|
||||||
|
|
||||||
async function registerLegiSectionTaModifiers(
|
async function registerLegiSectionTaModifiers(
|
||||||
context: Context,
|
context: Context,
|
||||||
legiTexteId: string,
|
|
||||||
depth: number,
|
depth: number,
|
||||||
lienSectionTa: LegiSectionTaLienSectionTa,
|
lienSectionTa: LegiSectionTaLienSectionTa,
|
||||||
sectionTa: LegiSectionTa,
|
sectionTa: LegiSectionTa,
|
||||||
|
@ -1154,7 +1147,7 @@ async function registerLegiSectionTaModifiers(
|
||||||
for (const articleLien of await db<ArticleLienDb[]>`
|
for (const articleLien of await db<ArticleLienDb[]>`
|
||||||
SELECT * FROM article_lien WHERE id = ${lienSectionTa["@id"]}
|
SELECT * FROM article_lien WHERE id = ${lienSectionTa["@id"]}
|
||||||
`) {
|
`) {
|
||||||
assert.strictEqual(articleLien.cidtexte, legiTexteId)
|
assert.strictEqual(articleLien.cidtexte, context.legiTexteCid)
|
||||||
if (articleLien.article_id in context.legiTexteInternalIds) {
|
if (articleLien.article_id in context.legiTexteInternalIds) {
|
||||||
// Ignore internal links because a LEGI texte can't modify itself.
|
// Ignore internal links because a LEGI texte can't modify itself.
|
||||||
continue
|
continue
|
||||||
|
@ -1206,7 +1199,7 @@ async function registerLegiSectionTaModifiers(
|
||||||
for (const texteVersionLien of await db<TexteVersionLienDb[]>`
|
for (const texteVersionLien of await db<TexteVersionLienDb[]>`
|
||||||
SELECT * FROM texte_version_lien WHERE id = ${lienSectionTa["@id"]}
|
SELECT * FROM texte_version_lien WHERE id = ${lienSectionTa["@id"]}
|
||||||
`) {
|
`) {
|
||||||
assert.strictEqual(texteVersionLien.cidtexte, legiTexteId)
|
assert.strictEqual(texteVersionLien.cidtexte, context.legiTexteCid)
|
||||||
if (texteVersionLien.texte_version_id in context.legiTexteInternalIds) {
|
if (texteVersionLien.texte_version_id in context.legiTexteInternalIds) {
|
||||||
// Ignore internal links because a LEGI texte can't modify itself.
|
// Ignore internal links because a LEGI texte can't modify itself.
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Reference in a new issue