From a5d261bed0324eaea58701c53327d0fa0753a6f7 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Wed, 22 Feb 2023 15:11:17 +0700 Subject: [PATCH] Minor fixes. (#2678) Signed-off-by: Andrey Sobolev --- .../src/components/message/Nodes.svelte | 27 +++--- .../src/components/BitrixConfigure.svelte | 92 +++++++++++++++++-- .../FieldMappingSynchronizer.svelte | 16 +++- plugins/bitrix/src/sync.ts | 30 ++++-- pods/account/src/index.ts | 1 + server/core/src/indexer/indexer.ts | 13 +++ 6 files changed, 150 insertions(+), 29 deletions(-) diff --git a/packages/presentation/src/components/message/Nodes.svelte b/packages/presentation/src/components/message/Nodes.svelte index beba86986e..3b469bb3eb 100644 --- a/packages/presentation/src/components/message/Nodes.svelte +++ b/packages/presentation/src/components/message/Nodes.svelte @@ -86,17 +86,22 @@ {/if} {:else if node.nodeName === 'SPAN'} - + + + {#if node.getAttribute('data-objectclass') !== undefined && node.getAttribute('data-id') !== undefined} + + {/if} + {:else if node.nodeName === 'TABLE'}
{:else if node.nodeName === 'TBODY'} diff --git a/plugins/bitrix-resources/src/components/BitrixConfigure.svelte b/plugins/bitrix-resources/src/components/BitrixConfigure.svelte index e50818c5ca..e1fb713165 100644 --- a/plugins/bitrix-resources/src/components/BitrixConfigure.svelte +++ b/plugins/bitrix-resources/src/components/BitrixConfigure.svelte @@ -15,14 +15,22 @@ // --> {#if profile} -
-
{#each mappings as mapping} {/each}
{/if} - - + +
+
+ +
diff --git a/plugins/bitrix-resources/src/components/FieldMappingSynchronizer.svelte b/plugins/bitrix-resources/src/components/FieldMappingSynchronizer.svelte index e7301e998c..d48784c10e 100644 --- a/plugins/bitrix-resources/src/components/FieldMappingSynchronizer.svelte +++ b/plugins/bitrix-resources/src/components/FieldMappingSynchronizer.svelte @@ -3,6 +3,7 @@ BitrixClient, BitrixEntityMapping, BitrixFieldMapping, + defaultSyncPeriod, Fields, performSynchronization, StatusValue, @@ -34,6 +35,7 @@ let direction: 'ASC' | 'DSC' = 'ASC' let limit = 1 let space: Ref | undefined + let syncPeriod = defaultSyncPeriod export let loading = false let state = '' @@ -67,7 +69,8 @@ docsProcessed++ state = `processed: ${docsProcessed}/${total ?? 1}` }, - extraFilter: filterFields.length === 0 ? undefined : mappedFilter + extraFilter: filterFields.length === 0 ? undefined : mappedFilter, + syncPeriod }) } catch (err: any) { state = err.message @@ -141,6 +144,17 @@ ]} bind:selected={direction} /> + { + if (val) { + syncPeriod = val + } + }} + />
it.bitrixId) } + attachedTo: resultDoc.document._id }) for (const valValue of vals) { - const existing = existingByClass.find( + const existingIdx = existingByClass.findIndex( (it) => hierarchy.as(it, bitrix.mixin.BitrixSyncDoc).bitrixId === valValue.bitrixId ) - await updateAttachedDoc(existing, applyOp, valValue) + if (existingIdx >= 0) { + const existing = existingByClass.splice(existingIdx, 1).shift() + await updateAttachedDoc(existing, applyOp, valValue) + } + } + + // Remove previous merged documents, probable they are deleted in bitrix or wrongly migrated. + for (const doc of existingByClass) { + await client.remove(doc) } } } @@ -355,8 +362,10 @@ export function processComment (comment: string): string { return comment } -// 1 day -const syncPeriod = 1000 * 60 * 60 * 24 +/** + * @public + */ +export const defaultSyncPeriod = 1000 * 60 * 60 * 24 /** * @public @@ -373,6 +382,7 @@ export interface SyncOptions { monitor: (total: number) => void blobProvider?: (blobRef: { file: string, id: string }) => Promise extraFilter?: Record + syncPeriod?: number } interface SyncOptionsExtra { ownerTypeValues: BitrixOwnerType[] @@ -471,7 +481,7 @@ async function doPerformSync (ops: SyncOptions & SyncOptionsExtra): Promise syncTime) { + if (bd.syncTime !== undefined && bd.syncTime + (ops.syncPeriod ?? defaultSyncPeriod) > syncTime) { // No need to sync, sime sync time is not yet arrived. toProcess.splice(0, 1) added++ @@ -694,14 +704,14 @@ async function downloadComments ( for (const comm of cr) { const cummunications = comm.COMMUNICATIONS?.map((it) => it.ENTITY_SETTINGS?.LEAD_TITLE ?? '') let message = `

- e-mail: ${cummunications?.join(',') ?? ''}
\n - Subject: ${comm.SUBJECT}
\n` + e-mail: ${cummunications?.join(',') ?? ''}
\n + Subject: ${comm.SUBJECT}
\n` for (const [k, v] of Object.entries(comm.SETTINGS?.EMAIL_META ?? {}).concat( Object.entries(comm.SETTINGS?.MESSAGE_HEADERS ?? {}) )) { if (v.trim().length > 0) { - message += `

${k}: ${v}

\n` + message += `${k}: ${v}
\n` } } message += '

' + comm.DESCRIPTION diff --git a/pods/account/src/index.ts b/pods/account/src/index.ts index a8da0f7151..001872d378 100644 --- a/pods/account/src/index.ts +++ b/pods/account/src/index.ts @@ -106,6 +106,7 @@ export function serveAccount (methods: Record, productId const close = (): void => { server.close() + process.exit(0) } process.on('uncaughtException', (e) => { diff --git a/server/core/src/indexer/indexer.ts b/server/core/src/indexer/indexer.ts index 649bf60efe..6eae7057b1 100644 --- a/server/core/src/indexer/indexer.ts +++ b/server/core/src/indexer/indexer.ts @@ -516,5 +516,18 @@ export class FullTextIndexPipeline implements FullTextPipeline { .map((it) => it._id) await this.storage.clean(DOMAIN_DOC_INDEX_STATE, docIds) } + + // Clean for non existing clases + + const unknownClasses = ( + await this.storage.findAll( + core.class.DocIndexState, + { objectClass: { $nin: allClasses } }, + { projection: { _id: 1 } } + ) + ).map((it) => it._id) + if (unknownClasses.length > 0) { + await this.storage.clean(DOMAIN_DOC_INDEX_STATE, unknownClasses) + } } }