]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/qt-console/restore/restoretree.cpp
This is an example of where I would like to go with offering the user the ability
[bacula/bacula] / bacula / src / qt-console / restore / restoretree.cpp
index 4f3df08ba8ada8a11fd58c1741e6daf0466178bd..a3f12108524252b8864ac173652d85f1d75667c3 100644 (file)
@@ -38,6 +38,7 @@
 #include "bat.h"
 #include "restoretree.h"
 #include "pages.h"
+#include "restoretreerun.h"
 
 restoreTree::restoreTree()
 {
@@ -148,11 +149,12 @@ void restoreTree::populateDirectoryTree()
    }
 
    QString cmd =
-      "SELECT DISTINCT Path.Path"
+      "SELECT DISTINCT Path.Path AS Path"
       " FROM Path"
       " LEFT OUTER JOIN File ON (File.PathId=Path.PathId)"
       " LEFT OUTER JOIN Job ON (File.JobId=Job.JobId)"
-      " WHERE Job.Jobid IN (" + m_jobQuery + ")";
+      " WHERE Job.Jobid IN (" + m_jobQuery + ")"
+      " ORDER BY Path";
    if (mainWin->m_sqlDebug) {
       Pmsg1(000, "Query cmd : %s\n", cmd.toUtf8().data());
    }
@@ -1264,7 +1266,7 @@ void restoreTree::testButtonPushed()
 {
    QMultiHash<int, QString> versionFilesMulti;
    QHash <QString, bool> fullPathDone;
-   QHash <QString, int> fileIdHash;
+   QHash <QString, int> fileIndexHash;
    if ((mainWin->m_rtRestore1Debug) || (mainWin->m_rtRestore2Debug) || (mainWin->m_rtRestore3Debug))
       Pmsg0(000, "In restoreTree::testButtonPushed\n");
    /* Use a tree widget item iterator filtering for Checked Items */
@@ -1276,7 +1278,7 @@ void restoreTree::testButtonPushed()
       /* With a checked directory, query for the files in the directory */
 
       QString cmd =
-         "SELECT t1.Filename AS Filename, t1.JobId AS JobId, File.Fileid AS Fileid"
+         "SELECT t1.Filename AS Filename, t1.JobId AS JobId, File.FileIndex AS FileIndex"
          " FROM"
          " ( SELECT Filename.Name AS Filename, MAX(Job.JobId) AS JobId"
            " FROM File"
@@ -1291,7 +1293,7 @@ void restoreTree::testButtonPushed()
            " LEFT OUTER JOIN Path ON (Path.PathId=File.PathId)"
            " LEFT OUTER JOIN Job ON (Job.JobId=File.JobId)"
          " WHERE"
-           " Path.Path='/etc/bacula/'"
+           " Path.Path='" + directory + "'"
            " AND Filename.Name=t1.Filename"
            " AND Job.Jobid=t1.JobId"
          " ORDER BY Filename";
@@ -1311,7 +1313,7 @@ void restoreTree::testButtonPushed()
             Qt::CheckState fileExcpState = (Qt::CheckState)4;
             fieldlist = resultline.split("\t");
             int version = 0;
-            int fileId = 0;
+            int fileIndex = 0;
             foreach (QString field, fieldlist) {
                if (column == 0) {
                   fullPath = directory + field;
@@ -1320,7 +1322,7 @@ void restoreTree::testButtonPushed()
                   version = field.toInt();
                }
                if (column == 2) {
-                  fileId = field.toInt();
+                  fileIndex = field.toInt();
                }
                column++;
             }
@@ -1332,13 +1334,13 @@ void restoreTree::testButtonPushed()
                if (excpVersion != 0) {
                   debugtext = QString("*E* version=%1").arg(excpVersion);
                   version = excpVersion;
-                  fileId = queryFileId(fullPath, excpVersion);
+                  fileIndex = queryFileIndex(fullPath, excpVersion);
                } else
                   debugtext = QString("___ version=%1").arg(version);
                if (mainWin->m_rtRestore1Debug)
                   Pmsg2(000, "Restoring %s File %s\n", debugtext.toUtf8().data(), fullPath.toUtf8().data());
                fullPathDone.insert(fullPath, 1);
-               fileIdHash.insert(fullPath, fileId);
+               fileIndexHash.insert(fullPath, fileIndex);
                versionFilesMulti.insert(version, fullPath);
             }
             row++;
@@ -1357,92 +1359,72 @@ void restoreTree::testButtonPushed()
          /* now we don't want the ones already done */
          if (fullPathDone.value(fullPath, 0) == 0) {
             int version = m_versionExceptionHash.value(fullPath, 0);
-            int fileId = 0;
+            int fileIndex = 0;
             QString debugtext = "";
             if (version != 0) {
-               fileId = queryFileId(fullPath, version);
-               debugtext = QString("E1* version=%1 fileid=%2").arg(version).arg(fileId);
+               fileIndex = queryFileIndex(fullPath, version);
+               debugtext = QString("E1* version=%1 fileid=%2").arg(version).arg(fileIndex);
             } else {
                version = mostRecentVersionfromFullPath(fullPath);
                if (version) {
-                  fileId = queryFileId(fullPath, version);
-                  debugtext = QString("E2* version=%1 fileid=%2").arg(version).arg(fileId);
+                  fileIndex = queryFileIndex(fullPath, version);
+                  debugtext = QString("E2* version=%1 fileid=%2").arg(version).arg(fileIndex);
                } else
                   debugtext = QString("Error det vers").arg(version);
             }
             if (mainWin->m_rtRestore1Debug)
                Pmsg2(000, "Restoring %s file %s\n", debugtext.toUtf8().data(), fullPath.toUtf8().data());
             versionFilesMulti.insert(version, fullPath);
-            fileIdHash.insert(fullPath, fileId);
+            fileIndexHash.insert(fullPath, fileIndex);
          } /* if fullPathDone.value(fullPath, 0) == 0 */
       } /* if state != 0 */
    } /* while ftera.hasNext */
 
    /* now for the final spit out of the versions and lists of files for each version */
    QHash<int, int> doneKeys;
-   QHashIterator<int, QString> miter(versionFilesMulti);
-   while (miter.hasNext()) {
-      miter.next();
-      int fversion = miter.key();
+   QHashIterator<int, QString> vFMiter(versionFilesMulti);
+   QString tempTable = "";
+   QList<int> jobList;
+   while (vFMiter.hasNext()) {
+      vFMiter.next();
+      int fversion = vFMiter.key();
       /* did not succeed in getting an iterator to work as expected on versionFilesMulti so use doneKeys */
       if (doneKeys.value(fversion, 0) == 0) {
-         QString tempTable = "restoretest" + QString("%1").arg(fversion);
-         //if (mainWin->m_sqlDebug)
-         QString sqlcmd = "CREATE TEMPORARY TABLE " + tempTable + " (JobId INTEGER, FileIndex INTEGER)";
-         QStringList results;
-         Pmsg1(000, "Query cmd : %s\n", sqlcmd.toUtf8().data());
-         /*if (m_console->sql_cmd(sqlcmd, results)) {
-            QStringList fieldlist;
-            int row = 0;
-            foreach (QString resultline, results) {
-               int column = 0;
-               fieldlist = resultline.split("\t");
-               foreach (QString field, fieldlist) {
-                  if (column == 0) {
-                     Pmsg1(000, "Returned from create table command %s\n", field.toUtf8().data());
-                  }
-                  column++;
-               }
-               row++;
-            }
-         }*/
+         if (tempTable == "") {
+            QSettings settings("www.bacula.org", "bat");
+            settings.beginGroup("Restore");
+            int counter = settings.value("Counter", 1).toInt();
+            settings.setValue("Counter", counter+1);
+            settings.endGroup();
+            tempTable = "restore_" + QString("%1").arg(qrand()) + "_" + QString("%1").arg(counter);
+            QString sqlcmd = "CREATE TEMPORARY TABLE " + tempTable + " (JobId INTEGER, FileIndex INTEGER)";
+            if (mainWin->m_sqlDebug)
+               Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
+            QStringList results;
+            if (!m_console->sql_cmd(sqlcmd, results))
+               Pmsg1(000, "CREATE TABLE FAILED!!!! %s\n", sqlcmd.toUtf8().data());
+         }
 
          if (mainWin->m_rtRestore2Debug) Pmsg1(000, "Version->%i\n", fversion);
          QStringList fullPathList = versionFilesMulti.values(fversion);
          /* create the command to perform the restore */
          foreach(QString ffullPath, fullPathList) {
-            int fileId = fileIdHash.value(ffullPath);
-            if (mainWin->m_rtRestore2Debug) Pmsg2(000, "  file->%s id %i\n", ffullPath.toUtf8().data(), fileId);
-            //cmd += " file=\"" + ffullPath + "\"";
-            sqlcmd = "INSERT INTO " + tempTable + " (JobId, FileIndex) VALUES (" + QString("%1").arg(fversion) + "," + QString("%1").arg(fileId) + ")";
-            results.clear();
-            Pmsg1(000, "Query cmd : %s\n", sqlcmd.toUtf8().data());
-            /*if (m_console->sql_cmd(sqlcmd, results)) {
-               QStringList fieldlist;
-               int row = 0;
-               foreach (QString resultline, results) {
-                  int column = 0;
-                  fieldlist = resultline.split("\t");
-                  foreach (QString field, fieldlist) {
-                     if (column == 0) {
-                        Pmsg1(000, "Returned from create table command %s\n", field.toUtf8().data());
-                     }
-                     column++;
-                  }
-                  row++;
-               }
-            }*/
-         }
-         QString cmd = QString("restore");
-         cmd += " client=\"" + m_prevClientCombo + "\""
-                " jobid=\"" + QString("%1").arg(fversion) + "\""
-                " file=\"?" + tempTable + "\" yes";
-         if (mainWin->m_commandDebug)
-            Pmsg1(000, "preRestore command \'%s\'\n", cmd.toUtf8().data());
-         //consoleCommand(cmd);
-         mainWin->resetFocus();
+            int fileIndex = fileIndexHash.value(ffullPath);
+            if (mainWin->m_rtRestore2Debug) Pmsg2(000, "  file->%s id %i\n", ffullPath.toUtf8().data(), fileIndex);
+            QString sqlcmd = "INSERT INTO " + tempTable + " (JobId, FileIndex) VALUES (" + QString("%1").arg(fversion) + ", " + QString("%1").arg(fileIndex) + ")";
+            if (mainWin->m_sqlDebug)
+               Pmsg1(000, "Query cmd : %s ;\n", sqlcmd.toUtf8().data());
+            QStringList results;
+            if (!m_console->sql_cmd(sqlcmd, results))
+               Pmsg1(000, "INSERT INTO FAILED!!!! %s\n", sqlcmd.toUtf8().data());
+         } /* foreach fullPathList */
          doneKeys.insert(fversion,1);
-      }
+         jobList.append(fversion);
+      } /*  if (doneKeys.value(fversion, 0) == 0) */
+   } /* while (vFMiter.hasNext()) */
+   if (tempTable != "") {
+      QTreeWidgetItem* pageSelectorTreeWidgetItem = mainWin->getFromHash(this);
+      new restoreTreeRunPage(tempTable, m_prevClientCombo, jobList, pageSelectorTreeWidgetItem);
    }
 }
 
@@ -1496,9 +1478,9 @@ int restoreTree::mostRecentVersionfromFullPath(QString &fullPath)
 }
 
 
-int restoreTree::queryFileId(QString &fullPath, int jobId)
+int restoreTree::queryFileIndex(QString &fullPath, int jobId)
 {
-   int qfileId = 0;
+   int qfileIndex = 0;
    QString directory, fileName;
    int index = m_slashregex.lastIndexIn(fullPath, -2);
    if (index != -1) {
@@ -1513,7 +1495,7 @@ int restoreTree::queryFileId(QString &fullPath, int jobId)
       /* so now we need the latest version from the database */
       QString cmd =
          "SELECT"
-          " File.Fileid"
+          " File.FileIndex"
          " FROM File"
           " LEFT OUTER JOIN Filename on (Filename.FilenameId=File.FilenameId)"
           " LEFT OUTER JOIN Path ON (Path.PathId=File.PathId)"
@@ -1522,7 +1504,7 @@ int restoreTree::queryFileId(QString &fullPath, int jobId)
           " Path.Path='" + directory + "'"
           " AND Filename.Name='" + fileName + "'"
           " AND Job.Jobid='" + QString("%1").arg(jobId) + "'"
-         " GROUP BY File.Fileid";
+         " GROUP BY File.FileIndex";
  
       if (mainWin->m_sqlDebug) Pmsg1(000, "Query cmd : %s\n", cmd.toUtf8().data());
       QStringList results;
@@ -1536,7 +1518,7 @@ int restoreTree::queryFileId(QString &fullPath, int jobId)
             fieldlist = resultline.split("\t");
             foreach (QString field, fieldlist) {
                if (column == 0) {
-                  qfileId = field.toInt();
+                  qfileIndex = field.toInt();
                }
                column++;
             }
@@ -1544,5 +1526,5 @@ int restoreTree::queryFileId(QString &fullPath, int jobId)
          }
       }
    } /* if (index != -1) */
-   return qfileId;
+   return qfileIndex;
 }