function executeUpgradeBatch($batchid) { global $dbxlink; $query = getUpgradeBatch($batchid); if ($query === NULL) { showError("unknown batch '{$batchid}'", __FUNCTION__); die; } $failures = array(); echo "<tr><th>Executing batch '{$batchid}'</th><td>"; foreach ($query as $q) { try { $result = $dbxlink->query($q); } catch (PDOException $e) { $errorInfo = $dbxlink->errorInfo(); $failures[] = array($q, $errorInfo[2]); } } if (!count($failures)) { echo "<strong><font color=green>done</font></strong>"; } else { echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>"; foreach ($failures as $f) { list($q, $i) = $f; echo "{$q} -- {$i}\n"; } echo "</pre>"; } echo '</td></tr>'; }
protected function upgrade($from, $to, InputInterface $input, OutputInterface $output) { global $dbxlink; $dry = $input->getOption('dry-run'); if ($from == $to) { $output->writeln('<info>Database is up-to-date. Nothing to do here.</info>'); return 0; } $failures = 0; $path = getDBUpgradePath($from, $to); $output->writeln('<comment>Upgrading database [' . $from . '] -> ' . join(' -> ', $path) . '</comment>'); $path[] = 'dictionary'; foreach ($path as $version) { $batch = getUpgradeBatch($version); if ($version == 'dictionary') { $output->writeln('<info>Updating Dictionary</info>'); } else { $output->writeln('<info>Upgrading to Version ' . $version . '</info>'); } $output->writeln(''); foreach ($batch as $query) { try { if ($output->getVerbosity() == OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("<comment> {$query}</comment>"); } else { $output->write("."); } if (!$dry) { $dbxlink->query($query); } } catch (PDOException $e) { $errorInfo = $dbxlink->errorInfo(); if ($output->getVerbosity() != OutputInterface::VERBOSITY_VERBOSE) { $output->writeln(''); $output->writeln("<error>QUERY FAILED:\t{$query}</error>"); } $output->writeln("<error>REASON: {$errorInfo[2]}</error>"); $failures++; } } $output->writeln(""); } return $failures; }