mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-06-13 14:50:28 +02:00
2018-10-16 Patrick Linstruth <patrick@deltecent.com>
* Drop and create empty database before restore * Update "DB Version" label after restore * Prompt to update database (rddbmgr --modify) if not current version
This commit is contained in:
parent
e42df3b8e3
commit
dde248d7ba
@ -63,6 +63,20 @@ Db::~Db()
|
|||||||
QSqlDatabase::removeDatabase("Rivendell");
|
QSqlDatabase::removeDatabase("Rivendell");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Db::clearDatabase(QString name)
|
||||||
|
{
|
||||||
|
QSqlQuery *q;
|
||||||
|
QSqlDatabase db=QSqlDatabase::database("Rivendell");
|
||||||
|
|
||||||
|
if(db.isOpen()){
|
||||||
|
q=new QSqlQuery(QString().sprintf("drop database if exists `%s`",(const char *)name),db);
|
||||||
|
delete q;
|
||||||
|
|
||||||
|
q=new QSqlQuery(QString().sprintf("create database `%s`",(const char *)name),db);
|
||||||
|
delete q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Db::isOpen()
|
bool Db::isOpen()
|
||||||
{
|
{
|
||||||
QSqlDatabase db=QSqlDatabase::database("Rivendell");
|
QSqlDatabase db=QSqlDatabase::database("Rivendell");
|
||||||
|
@ -31,6 +31,7 @@ class Db
|
|||||||
Db(QString *err_str,RDConfig *config);
|
Db(QString *err_str,RDConfig *config);
|
||||||
~Db();
|
~Db();
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
|
void clearDatabase(QString name);
|
||||||
unsigned schema();
|
unsigned schema();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
//
|
//
|
||||||
|
|
||||||
#define LINE fprintf(stderr,"%s:%d\n",__FILE__,__LINE__);
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -31,11 +29,11 @@
|
|||||||
#include <q3filedialog.h>
|
#include <q3filedialog.h>
|
||||||
|
|
||||||
#include <rdconfig.h>
|
#include <rdconfig.h>
|
||||||
|
#include <dbversion.h>
|
||||||
|
|
||||||
#include "../../icons/rivendell-22x22.xpm"
|
#include "../../icons/rivendell-22x22.xpm"
|
||||||
|
|
||||||
#include <rddbconfig.h>
|
#include "rddbconfig.h"
|
||||||
|
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "createdb.h"
|
#include "createdb.h"
|
||||||
#include "mysql_login.h"
|
#include "mysql_login.h"
|
||||||
@ -146,7 +144,15 @@ MainWidget::MainWidget(QWidget *parent)
|
|||||||
db_close_button->setFont(label_font);
|
db_close_button->setFont(label_font);
|
||||||
connect(db_close_button,SIGNAL(clicked()),this,SLOT(closeData()));
|
connect(db_close_button,SIGNAL(clicked()),this,SLOT(closeData()));
|
||||||
|
|
||||||
updateLabels();
|
//
|
||||||
|
// Signals
|
||||||
|
//
|
||||||
|
connect(this,SIGNAL(dbChanged()),this,SLOT(updateLabels()));
|
||||||
|
connect(this,SIGNAL(dbMismatch()),this,SLOT(mismatchData()));
|
||||||
|
|
||||||
|
this->show();
|
||||||
|
|
||||||
|
emit dbChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -166,6 +172,36 @@ QSizePolicy MainWidget::sizePolicy() const
|
|||||||
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWidget::mismatchData()
|
||||||
|
{
|
||||||
|
if (!db->schema()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QMessageBox::question(this,tr("Database Mismatch"),QString().sprintf("Your database is version %d. Your Rivendell %s installation requires version %d. Would you like to modify your database to the current version?",db->schema(),VERSION,RD_VERSION_DATABASE),(QMessageBox::No|QMessageBox::Yes)) != QMessageBox::Yes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcess modifyProcess(this);
|
||||||
|
QStringList args;
|
||||||
|
args << QString("--modify");
|
||||||
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
|
modifyProcess.start("rddbmgr", args);
|
||||||
|
modifyProcess.waitForFinished(-1);
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
if (modifyProcess.exitCode()) {
|
||||||
|
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||||
|
QString(modifyProcess.readAllStandardError()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QMessageBox::information(this,"Database Modified Successfully",
|
||||||
|
QString().sprintf("Modified database to version %d", RD_VERSION_DATABASE));
|
||||||
|
rd_config->log("rddbconfig",RDConfig::LogInfo,QString().sprintf("Modified database to version %d", RD_VERSION_DATABASE));
|
||||||
|
|
||||||
|
emit dbChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWidget::updateLabels()
|
void MainWidget::updateLabels()
|
||||||
{
|
{
|
||||||
QString err_msg="";
|
QString err_msg="";
|
||||||
@ -184,6 +220,10 @@ void MainWidget::updateLabels()
|
|||||||
label_schema->setText(QString().sprintf("DB Version: %d",db->schema()));
|
label_schema->setText(QString().sprintf("DB Version: %d",db->schema()));
|
||||||
db_backup_button->setEnabled(true);
|
db_backup_button->setEnabled(true);
|
||||||
db_restore_button->setEnabled(true);
|
db_restore_button->setEnabled(true);
|
||||||
|
|
||||||
|
if(db->schema()!=RD_VERSION_DATABASE) {
|
||||||
|
emit dbMismatch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +274,7 @@ void MainWidget::createData()
|
|||||||
|
|
||||||
startDaemons();
|
startDaemons();
|
||||||
|
|
||||||
updateLabels();
|
emit updateLabels();
|
||||||
|
|
||||||
delete db_create;
|
delete db_create;
|
||||||
}
|
}
|
||||||
@ -264,10 +304,9 @@ void MainWidget::backupData()
|
|||||||
backupProcess.setStandardOutputFile(filename);
|
backupProcess.setStandardOutputFile(filename);
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
backupProcess.start("mysqldump", args);
|
backupProcess.start("mysqldump", args);
|
||||||
backupProcess.waitForFinished();
|
backupProcess.waitForFinished(-1);
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
if (backupProcess.exitCode()) {
|
if (backupProcess.exitCode()) {
|
||||||
fprintf(stderr,"Exit Code=%d\n",backupProcess.exitCode());
|
|
||||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||||
QString(backupProcess.readAllStandardError()));
|
QString(backupProcess.readAllStandardError()));
|
||||||
}
|
}
|
||||||
@ -303,6 +342,9 @@ void MainWidget::restoreData()
|
|||||||
if (QMessageBox::question(this,tr("Restore Entire Database"),tr("Are you sure you want to restore your entire Rivendell database?"),(QMessageBox::No|QMessageBox::Yes)) != QMessageBox::Yes) {
|
if (QMessageBox::question(this,tr("Restore Entire Database"),tr("Are you sure you want to restore your entire Rivendell database?"),(QMessageBox::No|QMessageBox::Yes)) != QMessageBox::Yes) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db->clearDatabase(rd_config->mysqlDbname());
|
||||||
|
|
||||||
QProcess restoreProcess(this);
|
QProcess restoreProcess(this);
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << QString().sprintf("--user=%s",(const char *)rd_config->mysqlUsername())
|
args << QString().sprintf("--user=%s",(const char *)rd_config->mysqlUsername())
|
||||||
@ -313,7 +355,7 @@ void MainWidget::restoreData()
|
|||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
stopDaemons();
|
stopDaemons();
|
||||||
restoreProcess.start("mysql", args);
|
restoreProcess.start("mysql", args);
|
||||||
restoreProcess.waitForFinished();
|
restoreProcess.waitForFinished(-1);
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
if (restoreProcess.exitCode()) {
|
if (restoreProcess.exitCode()) {
|
||||||
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
QMessageBox::critical(this,tr("RDDbConfig Error"),
|
||||||
@ -329,7 +371,7 @@ void MainWidget::restoreData()
|
|||||||
(const char *)rd_config->mysqlDbname(),
|
(const char *)rd_config->mysqlDbname(),
|
||||||
(const char *)filename));
|
(const char *)filename));
|
||||||
}
|
}
|
||||||
updateLabels();
|
emit updateLabels();
|
||||||
startDaemons();
|
startDaemons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -372,14 +414,6 @@ void MainWidget::stopDaemons()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
#if 0
|
|
||||||
if(system("/usr/bin/systemctl status rivendell")==0) {
|
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
||||||
system("/usr/bin/systemctl stop rivendell");
|
|
||||||
QApplication::restoreOverrideCursor();
|
|
||||||
db_daemon_start_needed=true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -406,8 +440,5 @@ int main(int argc,char *argv[])
|
|||||||
QApplication a(argc,argv);
|
QApplication a(argc,argv);
|
||||||
MainWidget *w=new MainWidget();
|
MainWidget *w=new MainWidget();
|
||||||
a.setMainWidget(w);
|
a.setMainWidget(w);
|
||||||
w->setGeometry(QRect(QPoint(0,0),w->sizeHint()));
|
|
||||||
w->move(250,250);
|
|
||||||
w->show();
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
class MainWidget : public QWidget
|
class MainWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWidget(QWidget *parent=0);
|
MainWidget(QWidget *parent=0);
|
||||||
~MainWidget();
|
~MainWidget();
|
||||||
@ -53,12 +54,17 @@ class MainWidget : public QWidget
|
|||||||
void backupData();
|
void backupData();
|
||||||
void restoreData();
|
void restoreData();
|
||||||
void closeData();
|
void closeData();
|
||||||
|
void mismatchData();
|
||||||
|
void updateLabels();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dbMismatch();
|
||||||
|
void dbChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateLabels();
|
|
||||||
RDConfig *rd_config;
|
RDConfig *rd_config;
|
||||||
bool db_manage_daemons;
|
bool db_manage_daemons;
|
||||||
bool db_daemon_start_needed;
|
bool db_daemon_start_needed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user