diff --git a/change/@itwin-imodel-transformer-65f20003-2531-4208-a318-5b5a9fbc5ee1.json b/change/@itwin-imodel-transformer-65f20003-2531-4208-a318-5b5a9fbc5ee1.json new file mode 100644 index 00000000..2e738e94 --- /dev/null +++ b/change/@itwin-imodel-transformer-65f20003-2531-4208-a318-5b5a9fbc5ee1.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "In itwinjs versions 4.6.0 and greater DefinitionContainers are now deleted as if they were DefinitionPartitions. Made a change to onDeleteModel to treat definitinocontainers as if they were definitionpartitions", + "packageName": "@itwin/imodel-transformer", + "email": "22119573+nick4598@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/transformer/src/IModelTransformer.ts b/packages/transformer/src/IModelTransformer.ts index 89ae9758..d9176f07 100644 --- a/packages/transformer/src/IModelTransformer.ts +++ b/packages/transformer/src/IModelTransformer.ts @@ -24,6 +24,7 @@ import { } from "@itwin/core-bentley"; import * as ECSchemaMetaData from "@itwin/ecschema-metadata"; import { Point3d, Transform } from "@itwin/core-geometry"; +import * as coreBackendPkgJson from "@itwin/core-backend/package.json"; import { BriefcaseManager, ChangedECInstance, @@ -448,6 +449,9 @@ export class IModelTransformer extends IModelExportHandler { "targetScopeElementId" | "danglingReferencesBehavior" >; + /** @see hasDefinitionContainerDeletionFeature */ + private _hasDefinitionContainerDeletionFeature?: boolean; + private _isSynchronization = false; /** @@ -779,7 +783,9 @@ export class IModelTransformer extends IModelExportHandler { ); Logger.logInfo( TransformerLoggerCategory.IModelImporter, - `this.importer.autoExtendProjectExtents=${JSON.stringify(this.importer.options.autoExtendProjectExtents)}` + `this.importer.autoExtendProjectExtents=${JSON.stringify( + this.importer.options.autoExtendProjectExtents + )}` ); Logger.logInfo( TransformerLoggerCategory.IModelImporter, @@ -982,6 +988,20 @@ export class IModelTransformer extends IModelExportHandler { return this._cachedSynchronizationVersion; } + /** + * As of itwinjs 4.6.0, definitionContainers are now deleted as if they were DefinitionPartitions as opposed to Definitions. + * This variable being true will be used to special case the deletion of DefinitionContainers the same way DefinitionPartitions are deleted. + */ + protected get hasDefinitionContainerDeletionFeature(): boolean { + if (this._hasDefinitionContainerDeletionFeature === undefined) { + this._hasDefinitionContainerDeletionFeature = Semver.satisfies( + coreBackendPkgJson.version, + "^4.6.0" + ); + } + return this._hasDefinitionContainerDeletionFeature; + } + /** the changeset in the scoping element's source version found for this transformation * @note: the version depends on whether this is a reverse synchronization or not, as * it is stored separately for both synchronization directions. @@ -1999,15 +2019,30 @@ export class IModelTransformer extends IModelExportHandler { if (!Id64.isValidId64(targetModelId)) return; + let sql: string; + if (this.hasDefinitionContainerDeletionFeature) { + sql = ` + SELECT 1 + FROM bis.DefinitionPartition + WHERE ECInstanceId=:targetModelId + UNION + SELECT 1 + FROM bis.DefinitionContainer + WHERE ECInstanceId=:targetModelId + `; + } else { + sql = ` + SELECT 1 + FROM bis.DefinitionPartition + WHERE ECInstanceId=:targetModelId + `; + } + if (this.exporter.sourceDbChanges?.element.deleteIds.has(sourceModelId)) { const isDefinitionPartition = this.targetDb.withPreparedStatement( - ` - SELECT 1 - FROM bis.DefinitionPartition - WHERE ECInstanceId=? - `, + sql, (stmt) => { - stmt.bindId(1, targetModelId); + stmt.bindId("targetModelId", targetModelId); const val: DbResult = stmt.step(); switch (val) { case DbResult.BE_SQLITE_ROW: