diff --git a/dashboard/src/components/DataMigrator.js b/dashboard/src/components/DataMigrator.js index 7cb181881..d4def56e2 100644 --- a/dashboard/src/components/DataMigrator.js +++ b/dashboard/src/components/DataMigrator.js @@ -9,6 +9,7 @@ import { loadingTextState } from './DataLoader'; import { looseUuidRegex } from '../utils'; import { prepareCommentForEncryption } from '../recoil/comments'; import { prepareGroupForEncryption } from '../recoil/groups'; +import { capture } from '../services/sentry'; const LOADING_TEXT = 'Mise à jour des données de votre organisation…'; @@ -460,6 +461,49 @@ export default function useDataMigrator() { migrationLastUpdateAt = response.organisation.migrationLastUpdateAt; } } + + if (!organisation.migrations?.includes('evaluate-comments-in-persons-history')) { + setLoadingText(LOADING_TEXT); + const comments = await API.get({ + path: '/comment', + query: { organisation: organisationId, after: 0, withDeleted: false }, + }).then((res) => res.decryptedData || []); + + const persons = await API.get({ + path: '/person', + query: { organisation: organisationId, after: 0, withDeleted: false }, + }).then((res) => res.decryptedData || []); + + const personHistoryComments = comments.filter((c) => { + if (!c.comment.includes('Changement de')) return false; + if (!c.comment.includes('Avant:')) return false; + if (!c.comment.includes('Désormais:')) return false; + return true; + }); + + capture( + `Evaluate comments in persons history: ${organisation.name} - ${comments.length} coms - ${personHistoryComments.length} hist - ${persons.length} persons`, + { + extra: { + organisationId, + 'total-comments': comments.length, + 'total-history-comments': personHistoryComments.length, + 'total-persons': persons.length, + 'earliest-comment': personHistoryComments[personHistoryComments.length - 1]?.createdAt, + 'latest-comment': personHistoryComments[0]?.createdAt, + }, + } + ); + + const response = await API.put({ + path: `/migration/evaluate-comments-in-persons-history`, + query: { migrationLastUpdateAt }, + }); + if (response.ok) { + setOrganisation(response.organisation); + migrationLastUpdateAt = response.organisation.migrationLastUpdateAt; + } + } }, }; }