Пример #1
0
 // The reason to invert the tables is to handle all foreign key constraints nicely.
 $aTables = array_reverse($_TABLES);
 $nTables = count($aTables);
 $_BAR->setMessage('Removing data tables...');
 // Actually run the SQL...
 $nSQLDone = 0;
 $nSQLDonePercentage = 0;
 $nSQLDonePercentagePrev = 0;
 foreach ($aTables as $sTable) {
     $sSQL = 'DROP TABLE IF EXISTS ' . $sTable;
     $q = $_DB->query($sSQL, array(), false);
     if (!$q) {
         // Error when running query. We will use the Div for the form now.
         $sMessage = 'Error during uninstallation while running query.<BR>I ran:<DIV class="err">' . str_replace(array("\r\n", "\r", "\n"), '<BR>', $sSQL) . '</DIV><BR>I got:<DIV class="err">' . str_replace(array("\r\n", "\r", "\n"), '<BR>', $_DB->formatError()) . '</DIV><BR><BR>' . 'A failed uninstallation is most likely caused by a bug in LOVD.<BR>' . 'Please <A href="' . $_SETT['upstream_URL'] . 'bugs/" target="_blank">file a bug</A> and include the above messages to help us solve the problem.';
         $_BAR->setMessage($sMessage, 'done');
         $_BAR->setMessageVisibility('done', true);
         $_DB->query('DROP TABLE IF EXISTS ' . implode(', ', $aTables), array(), false);
         // Try again to remove everything.
         print '</BODY>' . "\n" . '</HTML>' . "\n";
         exit;
     }
     $nSQLDone++;
     $nSQLDonePercentage = round(100 * $nSQLDone / $nTables);
     if ($nSQLDonePercentage == 100 && $nSQLDone != $nTables) {
         // Don't want to show 100% when an error occurs at 99.5%.
         $nSQLDonePercentage = 99;
     }
     if ($nSQLDonePercentage != $nSQLDonePercentagePrev) {
         $_BAR->setProgress($nSQLDonePercentage);
         $nSQLDonePercentagePrev = $nSQLDonePercentage;
     }