Reset Car Catalogs Hash/ keep old image thumb
MODIFY
src/integration/car/CarIntegration.ts
src/integration/car/CarIntegration.ts
@@ -18,7 +18,7 @@ export default abstract class CarIntegration {
const externalCars = await this.getCarCatalogs();
for (const externalCar of externalCars) {
try {
- const internalCar = await CarStorage.getCarCatalog(externalCar.id, { withImage: true });
+ const internalCar = await CarStorage.getCarCatalog(externalCar.id);
if (!internalCar) {
// New Car: Create it
externalCar.hash = Cypher.hash(JSON.stringify(externalCar));

MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -38,6 +38,7 @@ import RenameChargingStationPropertiesTask from './tasks/RenameChargingStationPr
import RenameSMTPAuthErrorTask from './tasks/RenameSMTPAuthErrorTask';
import RenameTagPropertiesTask from './tasks/RenameTagPropertiesTask';
import RenameTransactionsAndConsumptionsTask from './tasks/RenameTransactionsAndConsumptionsTask';
+import ResetCarCatalogsHashTask from './tasks/ResetCarCatalogsHashTask';
import { ServerAction } from '../types/Server';
import SetDefaultTagToUserTask from './tasks/SetDefaultTagToUserTask';
import SiteUsersHashIDsTask from './tasks/SiteUsersHashIDsTask';
@@ -111,6 +112,7 @@ export default class MigrationHandler {
currentMigrationTasks.push(new AddLastChangedOnToCarCatalogTask());
currentMigrationTasks.push(new MigrateUserSettingsTask());
currentMigrationTasks.push(new RenameSMTPAuthErrorTask());
+ currentMigrationTasks.push(new ResetCarCatalogsHashTask());
// Get the already done migrations from the DB
const migrationTasksDone = await MigrationStorage.getMigrations();
// Check

ADD
src/migration/tasks/ResetCarCatalogsHashTask.ts
+import Constants from '../../utils/Constants';
+import Logging from '../../utils/Logging';
+import MigrationTask from '../MigrationTask';
+import { ServerAction } from '../../types/Server';
+import global from '../../types/GlobalType';
+
+const MODULE_NAME = 'ResetCarCatalogsHashTask';
+
+export default class ResetCarCatalogsHashTask extends MigrationTask {
+ async migrate(): Promise<void> {
+ try {
+ const result = await global.database.getCollection<any>(Constants.DEFAULT_TENANT, 'carcatalogs').updateMany({
+ },
+ [
+ { '$set': { 'hash': null } }
+ ]);
+ if (result.modifiedCount > 0) {
+ Logging.logDebug({
+ tenantID: Constants.DEFAULT_TENANT,
+ action: ServerAction.MIGRATION,
+ module: MODULE_NAME, method: 'migrate',
+ message: `${result.modifiedCount} Car(s) catalog(s) have been updated in the default tenant`
+ });
+ }
+ } catch (error) {
+ Logging.logError({
+ tenantID: Constants.DEFAULT_TENANT,
+ module: MODULE_NAME, method: 'migrate',
+ action: ServerAction.MIGRATION,
+ message: `Error while updating the Cars catalog: ${error.message}`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
+ }
+
+ getVersion(): string {
+ return '1.0';
+ }
+
+ isAsynchronous(): boolean {
+ return true;
+ }
+
+ getName(): string {
+ return 'ResetCarCatalogsHashTask';
+ }
+}

Reset Car Catalogs Hash/ keep old image thumb