Skip to content

Commit

Permalink
Supprime le dossier d'un contenu au dernier moment lors d'une mise à …
Browse files Browse the repository at this point in the history
…jour (#6509)

Si le scénario suivant se produit :
- on renomme un contenu déjà publié
- on publie le contenu renommé
- le dossier contenant tous les exports (notamment HTML) est supprimé
- le slug de la version publique existante change, donc on met en place
  une redirection et on dit à ElasticSearch d'oublier cette version
- cependant, ElasticSearch lève une exception qui n'est pas rattrapée
On se retrouve alors avec une version publique du contenu correspondant
à l'ancienne version (donc rien n'a changé pour la version publique), mais
le dossier contenant les exports de cette version a tout de même été
supprimé ! Cela cause des erreurs pour voir le contenu et toutes les pages
qui listent la version publique du contenu (e.g. la page des contenus, la
page de profil de l'auteur, la page d'accueil si le contenu était mis en
avant).

Il faut donc supprimer le dossier des exports au dernier moment, ce que
fait ce commit.
  • Loading branch information
philippemilink authored Jun 18, 2023
1 parent 939746c commit 3460554
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zds/tutorialv2/publication_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def publish_content(db_object, versioned, is_major_update=True):
is_update = False

if db_object.public_version:
is_update, public_version = update_existing_publication(db_object, versioned)
public_version = update_existing_publication(db_object, versioned)
is_update = True
else:
public_version = PublishedContent()

Expand Down Expand Up @@ -136,10 +137,9 @@ def publish_content(db_object, versioned, is_major_update=True):

def update_existing_publication(db_object, versioned):
public_version = db_object.public_version
# the content has been published in the past, so clean up old files!
# the content has been published in the past, so we will clean up old files!
old_path = public_version.get_prod_path()
logging.getLogger(__name__).debug("erase " + old_path)
shutil.rmtree(old_path)

# if the slug has changed, create a new object instead of reusing the old one
# this allows us to handle permanent redirection so that SEO is not impacted.
if versioned.slug != public_version.content_public_slug:
Expand All @@ -151,7 +151,13 @@ def update_existing_publication(db_object, versioned):

# keep the same publication date if the content is already published
public_version.publication_date = publication_date
return True, public_version

# remove old files only if everything succeed so far: if something bad
# happened, we don't want to have a published content without content!
logging.getLogger(__name__).debug("erase " + old_path)
shutil.rmtree(old_path)

return public_version


def write_md_file(md_file_path, parsed_with_local_images, versioned):
Expand Down

0 comments on commit 3460554

Please sign in to comment.