|
|
|
@ -25,7 +25,7 @@ QList<IPlugin *> Context::plugins()
|
|
|
|
|
|
|
|
|
|
IPlugin *Context::plugin(const QString &pluginId)
|
|
|
|
|
{
|
|
|
|
|
QList<IPlugin*>::iterator it = std::find_if(m_plugins.begin(), m_plugins.end(), [&pluginId](IPlugin *p) { return p->pluginId() == pluginId; });
|
|
|
|
|
QList<IPlugin*>::iterator it = std::find_if(ALL(m_plugins), [&pluginId](IPlugin *p) { return p->pluginId() == pluginId; });
|
|
|
|
|
if (it != m_plugins.end())
|
|
|
|
|
{
|
|
|
|
|
return *it;
|
|
|
|
@ -100,6 +100,30 @@ void Context::checkDb(const QString &path)
|
|
|
|
|
void Context::checkSchema(const QSqlDatabase &db, const QMap<QString, int> &schemaMap)
|
|
|
|
|
{
|
|
|
|
|
foreach (IPlugin *plugin, m_plugins) {
|
|
|
|
|
solveDep(plugin, db, schemaMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Context::solveDep(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap)
|
|
|
|
|
{
|
|
|
|
|
foreach (QString dep, plugin->dependsOn()) {
|
|
|
|
|
QList<IPlugin*>::iterator it = std::find_if(ALL(m_plugins), [&dep](IPlugin *p) { return p->pluginId() == dep; });
|
|
|
|
|
|
|
|
|
|
if (it != m_plugins.end())
|
|
|
|
|
{
|
|
|
|
|
solveDep(*it, db, schemaMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_solved.contains(plugin->pluginId()))
|
|
|
|
|
{
|
|
|
|
|
createSchema(plugin, db, schemaMap);
|
|
|
|
|
m_solved.append(plugin->pluginId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Context::createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap)
|
|
|
|
|
{
|
|
|
|
|
if (!schemaMap.contains(plugin->pluginId()) || schemaMap[plugin->pluginId()] < plugin->schemaVersion())
|
|
|
|
|
{
|
|
|
|
|
int ver = schemaMap[plugin->pluginId()];
|
|
|
|
@ -112,14 +136,21 @@ void Context::checkSchema(const QSqlDatabase &db, const QMap<QString, int> &sche
|
|
|
|
|
QSqlQuery q(db);
|
|
|
|
|
|
|
|
|
|
QStringList sqlList = sql.split(";");
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
|
|
foreach (QString s, sqlList) {
|
|
|
|
|
if (!q.exec(s))
|
|
|
|
|
{
|
|
|
|
|
qDebug() << q.lastError().text();
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ver == 0)
|
|
|
|
|
{
|
|
|
|
|
sql = "INSERT INTO system(pluginId, schemaVersion) VALUES('" + plugin->pluginId() + "', 1)";
|
|
|
|
@ -132,5 +163,4 @@ void Context::checkSchema(const QSqlDatabase &db, const QMap<QString, int> &sche
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|