diff --git a/src/StorageService.cpp b/src/StorageService.cpp index 1bc1bd2d..2adb993d 100644 --- a/src/StorageService.cpp +++ b/src/StorageService.cpp @@ -22,6 +22,8 @@ namespace OpenWifi { ScriptDB_->Create(); ScriptDB_->Initialize(); + FixDeviceTypeBug(); + return 0; } diff --git a/src/StorageService.h b/src/StorageService.h index d6fbaa89..8be929cc 100644 --- a/src/StorageService.h +++ b/src/StorageService.h @@ -294,6 +294,8 @@ namespace OpenWifi { bool AnalyzeCommands(Types::CountedMap &R); bool AnalyzeDevices(GWObjects::Dashboard &D); + void FixDeviceTypeBug(); + int Start() override; void Stop() override; diff --git a/src/storage/storage_device.cpp b/src/storage/storage_device.cpp index fed60f9f..bdc71448 100644 --- a/src/storage/storage_device.cpp +++ b/src/storage/storage_device.cpp @@ -1115,4 +1115,25 @@ namespace OpenWifi { FieldList.push_back(field); } + void Storage::FixDeviceTypeBug() { + try { + std::vector ScriptLines{ + "update devices set devicetype='ap' where devicetype='AP';", + "update devices set devicetype='switch' where devicetype='SWITCH';", + "update devices set devicetype='ap' where devicetype!='ap' and devicetype!='switch';" + }; + + for (const auto &ScriptLine : ScriptLines) { + try { + Poco::Data::Session Sess = Pool_->get(); + Poco::Data::Statement SqlStatement(Sess); + SqlStatement << ScriptLine, Poco::Data::Keywords::now; + } catch (...) { + } + } + } catch (const Poco::Exception &E) { + Logger().log(E); + } + } + } // namespace OpenWifi