feat(convert): tentative (pour le moment ratée) d importer les révisions

This commit is contained in:
François Poulain 2020-08-05 09:20:52 +02:00
parent 863f885100
commit 1b86fcd78d
2 changed files with 60 additions and 0 deletions

View File

@ -6,6 +6,7 @@ from itertools import groupby
from django.conf import settings
from django.utils.timezone import make_aware, now
import phpserialize
import request
from bs4 import BeautifulSoup as bs
@ -203,3 +204,50 @@ def convert_node(node, options):
spip.MotsLiens.objects.get_or_create(
mot=mot, id_objet=article.pk, objet='article'
)
for numero, revision in enumerate(
node.noderevisions_set.order_by('timestamp'), start=1
):
user_attributes = {
'nom': revision.user.name,
'email': revision.user.mail,
'en_ligne': convert_timestamp(revision.user.access),
'maj': convert_timestamp(revision.user.created),
}
auteur, _ = spip.Auteurs.objects.update_or_create(
login=revision.user.name, defaults=user_attributes
)
if numero == 1:
fragment = phpserialize.dumps({1: revision.body}).decode()
else:
fragment = phpserialize.dumps(
{1: previous.body, 2: revision.body}
).decode()
# fragment = phpserialize.dumps({1: str(numero-1), 2: revision.body}).decode()
spip.VersionsFragments.objects.update_or_create(
id_fragment=numero,
id_objet=article.pk,
objet='article',
version_min_id=numero,
defaults={'fragment': fragment, 'version_max_id': numero,},
)
champs_versionnes = {'texte': numero}
version, _ = spip.Versions.objects.update_or_create(
id_version=numero,
id_objet=article.pk,
objet='article',
defaults={
'auteur': auteur,
'titre_version': 'Version initiale'
if numero == 1 and not revision.log
else revision.log,
'date': convert_timestamp(revision.timestamp),
'permanent': '' if numero == 1 else 'non',
'champs': phpserialize.dumps(champs_versionnes).decode(),
},
)
previous = revision

View File

@ -97,6 +97,13 @@ DB_RELATIONS = {
'mots_liens': {
'id_mot': ('id_mot', 'mots', 'mot'),
},
'versions': {
'id_auteur': ('id_auteur', 'auteurs', 'auteur'),
},
'versions_fragments': {
'version_min': ('id_version', 'versions'),
'version_max': ('id_version', 'versions'),
},
},
}
@ -162,6 +169,11 @@ DB_PARAMS = {
'comite': {'default': 'oui'},
'forum': {'default': 'non'},
},
'versions_fragments': {
'compress': {'default': 0},
'version_min': {'default': 0, 'related_name': '+'},
'version_max': {'default': 0, 'related_name': '+'},
},
'urls': {
'id_parent': {'default': 0},
'langue': {'default': ''},