Adds immediate migration results in progress
This commit is contained in:
2102 files changed
+17482
-15071
No files matched your search
+38
-38
@@ -31,7 +31,7 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
m_vecData.clear();
|
||||
|
||||
QVector <int> localExercises;
|
||||
DEBUG_LOG() << "ExportedScriptsModel::init rootDirectoryToScan=" << rootDirectoryToScan
|
||||
DEBUG_LOG(m_logger) << "ExportedScriptsModel::init rootDirectoryToScan=" << rootDirectoryToScan
|
||||
;
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
|
||||
|
||||
{
|
||||
DEBUG_LOG() << "Get all local exercises rootDirectoryToScan=" << rootDirectoryToScan ;
|
||||
DEBUG_LOG(m_logger) << "Get all local exercises rootDirectoryToScan=" << rootDirectoryToScan ;
|
||||
QFile file(rootDirectoryToScan + QDir::separator() + QStringLiteral("exercises.json"));
|
||||
if (!file.open(QFile::ReadOnly))
|
||||
WARNING_LOG() << "Cannot open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
WARNING_LOG(m_logger) << "Cannot open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
|
||||
const QJsonDocument doc(QJsonDocument::fromJson(file.readAll()));
|
||||
const QJsonObject obj = doc.object();
|
||||
@@ -52,7 +52,7 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
localExercises.append(ele.toInt());
|
||||
}
|
||||
|
||||
WARNING_LOG() << "local exericses: " << localExercises.count();
|
||||
WARNING_LOG(m_logger) << "local exericses: " << localExercises.count();
|
||||
|
||||
|
||||
for (const int exId : std::as_const(localExercises))
|
||||
@@ -62,7 +62,7 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
WARNING_LOG() << "Cannot open " << file.fileName() << " for reading: " << file.errorString() << " - not critical";
|
||||
WARNING_LOG(m_logger) << "Cannot open " << file.fileName() << " for reading: " << file.errorString() << " - not critical";
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -71,14 +71,14 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
const QJsonObject obj = doc.object();
|
||||
const QJsonArray presentations = obj[QStringLiteral("presentations")].toArray();
|
||||
|
||||
DEBUG_LOG() << "exercise: " << exId << ", presentations: " << presentations.size();
|
||||
DEBUG_LOG(m_logger) << "exercise: " << exId << ", presentations: " << presentations.size();
|
||||
|
||||
for (const QJsonValue &val : presentations)
|
||||
{
|
||||
ExportedScriptInformation esi = ExportedScriptInformation::fromJson(val);
|
||||
DEBUG_LOG() << "obj=" << QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
DEBUG_LOG(m_logger) << "obj=" << QJsonDocument(obj).toJson(QJsonDocument::Compact);
|
||||
const QJsonObject presentationObj = val.toObject();
|
||||
DEBUG_LOG() << "presentationObj=" << QJsonDocument(presentationObj).toJson(QJsonDocument::Compact);
|
||||
DEBUG_LOG(m_logger) << "presentationObj=" << QJsonDocument(presentationObj).toJson(QJsonDocument::Compact);
|
||||
if (obj.contains(QStringLiteral("exerciseId")))
|
||||
{
|
||||
esi.exerciseId = obj[QStringLiteral("exerciseId")].toInt();
|
||||
@@ -90,7 +90,7 @@ bool ExportedScriptsModel::init(const QString &rootDirectoryToScan)
|
||||
}
|
||||
|
||||
esi.local = true;
|
||||
DEBUG_LOG() << "push_back "
|
||||
DEBUG_LOG(m_logger) << "push_back "
|
||||
<< " exportTime=" << esi.exportTime
|
||||
<< " scriptId=" << esi.scriptId
|
||||
<< " scriptName=" << esi.scriptName
|
||||
@@ -120,14 +120,14 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
QMap<int, QVector<int>> exerciseContentScriptIds;
|
||||
QMap<int, QVector<int>> exerciseScriptIds;
|
||||
|
||||
DEBUG_LOG() << "ExportedScriptsModel::setServerContent jsonArray =" << jsonArray;
|
||||
DEBUG_LOG(m_logger) << "ExportedScriptsModel::setServerContent jsonArray =" << jsonArray;
|
||||
QJsonParseError err;
|
||||
const QJsonArray presentations = QJsonDocument::fromJson(jsonArray.toUtf8(), &err).array();
|
||||
DEBUG_LOG() << "presentations.size() =" << presentations.size();
|
||||
DEBUG_LOG(m_logger) << "presentations.size() =" << presentations.size();
|
||||
|
||||
if (err.error != QJsonParseError::NoError)
|
||||
{
|
||||
ERROR_LOG() << "json array invalid at offset " << err.offset << ": " << err.errorString();
|
||||
ERROR_LOG(m_logger) << "json array invalid at offset " << err.offset << ": " << err.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
for (const auto &data : std::as_const(m_vecData))
|
||||
{
|
||||
exerciseScriptIds[data.exerciseId].append(data.scriptId);
|
||||
DEBUG_LOG() << "exerciseId=" << data.exerciseId
|
||||
DEBUG_LOG(m_logger) << "exerciseId=" << data.exerciseId
|
||||
<< " modelScriptIds.append: " << data.scriptId;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
{
|
||||
const auto &rowData = m_vecData[i];
|
||||
const QVector<int> contentScriptIds = exerciseContentScriptIds.value(rowData.exerciseId);
|
||||
DEBUG_LOG() << "m_vecData.at(" << i << ").scriptId=" << rowData.scriptId
|
||||
DEBUG_LOG(m_logger) << "m_vecData.at(" << i << ").scriptId=" << rowData.scriptId
|
||||
<< " exerciseId=" << rowData.exerciseId
|
||||
<< " contentScriptIds.contains=" << contentScriptIds.contains(rowData.scriptId)
|
||||
<< " rowData.local=" << rowData.local
|
||||
@@ -165,7 +165,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
{
|
||||
|
||||
|
||||
DEBUG_LOG() << "removeRow(" << i << ")"
|
||||
DEBUG_LOG(m_logger) << "removeRow(" << i << ")"
|
||||
<< " ScriptId=" << rowData.scriptId
|
||||
<< " ExerciseId=" << rowData.exerciseId;
|
||||
removeRow(i);
|
||||
@@ -185,7 +185,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
{
|
||||
ExportedScriptInformation esi = ExportedScriptInformation::fromJson(val, false, ThpAlreadyUploaded);
|
||||
QVector<int> modelScriptIds = exerciseScriptIds.value(esi.exerciseId);
|
||||
DEBUG_LOG() << " exportTime=" << esi.exportTime
|
||||
DEBUG_LOG(m_logger) << " exportTime=" << esi.exportTime
|
||||
<< " scriptId=" << esi.scriptId
|
||||
<< " exerciseId=" << esi.exerciseId
|
||||
<< " exerciseName=" << esi.exerciseName
|
||||
@@ -196,7 +196,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
|
||||
if (!modelScriptIds.contains(esi.scriptId))
|
||||
{
|
||||
DEBUG_LOG() << "insertRow()";
|
||||
DEBUG_LOG(m_logger) << "insertRow()";
|
||||
insertRow(esi);
|
||||
continue;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ void ExportedScriptsModel::setServerContent(const QString &jsonArray)
|
||||
if (rowData.scriptId == esi.scriptId &&
|
||||
rowData.exerciseId == esi.exerciseId)
|
||||
{
|
||||
DEBUG_LOG() << "setUploadState i=" << i
|
||||
DEBUG_LOG(m_logger) << "setUploadState i=" << i
|
||||
<< " esi.scriptId=" << esi.scriptId
|
||||
<< " esi.exerciseId=" << esi.exerciseId
|
||||
<< " esi.fileSize=" << esi.fileSize
|
||||
@@ -230,7 +230,7 @@ qint64 ExportedScriptsModel::downloadTime(const ExportedScriptInformation &val)
|
||||
return 0;
|
||||
|
||||
QString filename(QStringLiteral("%1/THP-Download/Exercise_%2/%3/index.html").arg(QDir::tempPath()).arg(val.exerciseId).arg(val.scriptId));
|
||||
DEBUG_LOG() << "downloadTime: filename " << filename;
|
||||
DEBUG_LOG(m_logger) << "downloadTime: filename " << filename;
|
||||
|
||||
QFileInfo fi(filename);
|
||||
if (!fi.exists())
|
||||
@@ -334,16 +334,16 @@ bool ExportedScriptsModel::createDataJson(const QString &rootDirectory,
|
||||
|
||||
if (!QDir().mkpath(baseDir))
|
||||
{
|
||||
ERROR_LOG() << "Failed to create path " << baseDir;
|
||||
ERROR_LOG(m_logger) << "Failed to create path " << baseDir;
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(baseDir + QStringLiteral("data.json"));
|
||||
DEBUG_LOG() << "createDataJson=" << file.fileName();
|
||||
DEBUG_LOG(m_logger) << "createDataJson=" << file.fileName();
|
||||
if (!file.open(QFile::ReadWrite))
|
||||
{
|
||||
QString msg(tr("Could not open data file in script directory: %1").arg(file.errorString()));
|
||||
ERROR_LOG() << msg << " - " << file.fileName();
|
||||
ERROR_LOG(m_logger) << msg << " - " << file.fileName();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ bool ExportedScriptsModel::createDataJson(const QString &rootDirectory,
|
||||
QJsonObject obj = doc.object();
|
||||
if (obj[QStringLiteral("exerciseId")].toInt() == exerciseId)
|
||||
{
|
||||
DEBUG_LOG() << baseDir << " exists for exerciseId " << QString::number(exerciseId);
|
||||
DEBUG_LOG(m_logger) << baseDir << " exists for exerciseId " << QString::number(exerciseId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -381,18 +381,18 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
|
||||
{
|
||||
|
||||
DEBUG_LOG() << "Add exercise to ExportRootPath";
|
||||
DEBUG_LOG(m_logger) << "Add exercise to ExportRootPath";
|
||||
|
||||
if (!QDir(esi.rootDirectory).exists())
|
||||
{
|
||||
ERROR_LOG() << "Cannot modify exercises.json as the info's root directory '"<<esi.rootDirectory<<"' does not exist!";
|
||||
ERROR_LOG(m_logger) << "Cannot modify exercises.json as the info's root directory '"<<esi.rootDirectory<<"' does not exist!";
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(esi.rootDirectory + QDir::separator() + QStringLiteral("exercises.json"));
|
||||
if (!file.open(QFile::ReadWrite))
|
||||
{
|
||||
WARNING_LOG() << "Can not open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
WARNING_LOG(m_logger) << "Can not open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -403,14 +403,14 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
|
||||
if (!arr.contains(esi.exerciseId))
|
||||
{
|
||||
DEBUG_LOG() << "arr.append Exercise=" << esi.exerciseId;
|
||||
DEBUG_LOG(m_logger) << "arr.append Exercise=" << esi.exerciseId;
|
||||
arr.append(esi.exerciseId);
|
||||
}
|
||||
|
||||
obj.insert(key, arr);
|
||||
file.resize(0);
|
||||
file.write(QJsonDocument(obj).toJson());
|
||||
INFO_LOG() << " file.write " << QJsonDocument(obj).toJson();
|
||||
INFO_LOG(m_logger) << " file.write " << QJsonDocument(obj).toJson();
|
||||
file.close();
|
||||
}
|
||||
|
||||
@@ -419,17 +419,17 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
const QString baseDir = exercisePath(esi.rootDirectory, esi.exerciseId);
|
||||
if (!QDir().mkpath(baseDir))
|
||||
{
|
||||
ERROR_LOG() << "Cannot create destination path " << baseDir;
|
||||
ERROR_LOG(m_logger) << "Cannot create destination path " << baseDir;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QFile file(baseDir + QDir::separator() + QStringLiteral("data.json"));
|
||||
DEBUG_LOG() << "File= " << file.fileName();
|
||||
DEBUG_LOG(m_logger) << "File= " << file.fileName();
|
||||
if (!file.open(QFile::ReadWrite))
|
||||
{
|
||||
WARNING_LOG() << "Can not open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
WARNING_LOG(m_logger) << "Can not open " << file.fileName() << " for read/write: " << file.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
QJsonObject obj = doc.object();
|
||||
QJsonArray arr = obj.value(keyArray).toArray();
|
||||
bool exported = false;
|
||||
DEBUG_LOG() << "arr.size=" << arr.size();
|
||||
DEBUG_LOG(m_logger) << "arr.size=" << arr.size();
|
||||
|
||||
for (int i = 0; i < arr.size(); ++i)
|
||||
{
|
||||
@@ -454,7 +454,7 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
|
||||
if (!exported)
|
||||
{
|
||||
DEBUG_LOG() << "info scriptId=" << esi.scriptId
|
||||
DEBUG_LOG(m_logger) << "info scriptId=" << esi.scriptId
|
||||
<< " Name=" << esi.scriptName
|
||||
<< " Exercise=" << esi.exerciseName;
|
||||
arr.append(esi.toJson());
|
||||
@@ -463,7 +463,7 @@ void ExportedScriptsModel::addDownloadData(const ExportedScriptInformation &esi)
|
||||
obj.insert(keyArray, arr);
|
||||
auto content = QJsonDocument(obj).toJson();
|
||||
|
||||
DEBUG_LOG() << "content =" << content;
|
||||
DEBUG_LOG(m_logger) << "content =" << content;
|
||||
|
||||
file.resize(0);
|
||||
file.write(content);
|
||||
@@ -478,7 +478,7 @@ bool ExportedScriptsModel::setLocalState(const int row, const bool localHost)
|
||||
data.local = localHost;
|
||||
|
||||
|
||||
DEBUG_LOG() << "setLocalState row=" << row
|
||||
DEBUG_LOG(m_logger) << "setLocalState row=" << row
|
||||
<< " scriptId=" << data.scriptId
|
||||
<< " data.scriptName=" << data.scriptName
|
||||
<< " Exercise=" << data.exerciseName;
|
||||
@@ -515,12 +515,12 @@ bool ExportedScriptsModel::removeRow(int row)
|
||||
|
||||
QString baseDir = exercisePath(data.rootDirectory, data.exerciseId);
|
||||
QString filename = baseDir + QStringLiteral("data.json");
|
||||
DEBUG_LOG() << "filename= '" << filename << "'";
|
||||
DEBUG_LOG(m_logger) << "filename= '" << filename << "'";
|
||||
QFile file(baseDir + QStringLiteral("data.json"));
|
||||
|
||||
if (!file.open(QIODevice::ReadWrite))
|
||||
{
|
||||
DEBUG_LOG() << "!file.open '" << filename << "'"
|
||||
DEBUG_LOG(m_logger) << "!file.open '" << filename << "'"
|
||||
<< " no local scripts";
|
||||
return true;
|
||||
}
|
||||
@@ -539,7 +539,7 @@ bool ExportedScriptsModel::removeRow(int row)
|
||||
obj[QStringLiteral("presentations")] = arr;
|
||||
file.resize(0);
|
||||
auto content = QJsonDocument(obj).toJson();
|
||||
DEBUG_LOG() << "content =" << content;
|
||||
DEBUG_LOG(m_logger) << "content =" << content;
|
||||
|
||||
return file.write(QJsonDocument(obj).toJson());
|
||||
}
|
||||
|
||||
+2
@@ -81,6 +81,8 @@ public:
|
||||
void addDownloadData(const ExportedScriptInformation &esi);
|
||||
|
||||
private:
|
||||
|
||||
NGL::INGLLogger &m_logger;
|
||||
QString exercisePath(const QString &rootDirectory, const int exerciseId) const;
|
||||
qint64 downloadTime(const ExportedScriptInformation &val) const;
|
||||
|
||||
|
||||
Reference in new issue
Block a user