| 12 | }; |
| 13 | |
| 14 | QString MetaTable::getUUID() const |
| 15 | { |
| 16 | QVector<QVariantMap> results; |
| 17 | getRecords(results, QStringList() << "uuid"); |
| 18 | |
| 19 | for (const auto& entry : results) |
| 20 | { |
| 21 | if (!entry["uuid"].toString().isEmpty()) |
| 22 | return entry["uuid"].toString(); |
| 23 | } |
| 24 | |
| 25 | // create new uuidv5 based on net adapter MAC, save to db and return |
| 26 | QString hash; |
| 27 | foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) |
| 28 | { |
| 29 | if (!(interface.flags() & QNetworkInterface::IsLoopBack)) |
| 30 | { |
| 31 | hash = QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(), QCryptographicHash::Sha1).toHex(); |
| 32 | break; |
| 33 | } |
| 34 | } |
| 35 | const QString newUuid = QUuid::createUuidV5(QUuid(), hash).toString().mid(1, 36); |
| 36 | VectorPair cond; |
| 37 | cond.append(CPair("uuid", newUuid)); |
| 38 | QVariantMap map; |
| 39 | map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate); |
| 40 | createRecord(cond, map); |
| 41 | |
| 42 | return newUuid; |
| 43 | } |
| 44 |
no test coverage detected