Commit 4c6939ff authored by jan.koester's avatar jan.koester
Browse files

test

parent cc71da87
Loading
Loading
Loading
Loading
+27 −0
Changes for plugins/survey/survey.cpp: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -273,6 +273,33 @@ namespace blogi {
                }
                tpl.questions.push_back(std::move(q));
            }

            // Auto-migrate old qN-style IDs to UUIDs and fix duplicates
            std::set<std::string> seenIds;
            bool needsMigration = false;
            for (auto &q : tpl.questions) {
                bool isOldStyle = (q.id.size() >= 2 && q.id[0] == 'q' &&
                    std::all_of(q.id.begin() + 1, q.id.end(), ::isdigit));
                if (q.id.empty() || isOldStyle || seenIds.count(q.id)) {
                    uuid::uuid newId;
                    newId.generate();
                    q.id = newId.c_str();
                    needsMigration = true;
                }
                seenIds.insert(q.id);
            }

            // Auto-assign order if all questions have order 0
            bool allZero = true;
            for (const auto &q : tpl.questions) {
                if (q.order != 0) { allZero = false; break; }
            }
            if (allZero) {
                for (size_t i = 0; i < tpl.questions.size(); ++i)
                    tpl.questions[i].order = static_cast<int>(i + 1);
                needsMigration = true;
            }

            return true;
        }