The ID of an event is checked now when importing the XML file.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 27 Sep 2017 20:35:59 +0000 (22:35 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 27 Sep 2017 20:36:57 +0000 (22:36 +0200)
src/sql/schedulexmlparser.cpp

index 15e3861..bba8626 100644 (file)
@@ -38,6 +38,15 @@ public:
 };
 
 
+void checkEvent(QHash<QString,QString>& event) {
+    QString event_id = event["id"];
+    if (event_id.trimmed().isEmpty()) throw ParseException(QObject::tr("The ID of event '%1' is missing.").arg(event["title"]));
+    bool ok;
+    event_id.toInt(&ok);
+    if (!ok) throw ParseException(QObject::tr("The ID '%2' of event '%1' is not numeric.").arg(event["title"]).arg(event_id));
+}
+
+
 void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& url, int conferenceId) {
     QDomDocument document;
     QString xml_error;
@@ -115,7 +124,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
 
                         // process event's nodes
                         QHash<QString,QString> event;
-                        event["id"] = eventElement.attribute("id");;
+                        event["id"] = eventElement.attribute("id");
                         event["conference_id"] = QString::number(conferenceId, 10);
                         QTime event_start = QTime::fromString(eventElement.firstChildElement("start").text(), sqlEngine->TIME_FORMAT);
                         event["start"] = event_start.toString(sqlEngine->TIME_FORMAT); // time eg. 10:00
@@ -139,6 +148,7 @@ void ScheduleXmlParser::parseDataImpl(const QByteArray &aData, const QString& ur
                         event["language"] = eventElement.firstChildElement("language").text(); // language eg. "English"
                         event["abstract"] = eventElement.firstChildElement("abstract").text(); // string
                         event["description"] = eventElement.firstChildElement("description").text(); // string
+                        checkEvent(event);
                         sqlEngine->addEventToDB(event);
                         // process persons' nodes
                         QDomElement personsElement = eventElement.firstChildElement("persons");