/** * @param DBPatcher\PatchFile $patchFile * @param \Doctrine\DBAL\Connection $connection * @return DBPatcher\PatchFile */ function applySqlPatch($patchFile, $connection) { if ($patchFile->extension === 'sql') { $sqlCommands = file_get_contents($patchFile->filename); $connection->beginTransaction(); try { $connection->exec($sqlCommands); } catch (\Doctrine\DBAL\DBALException $e) { $connection->rollBack(); return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR), $e->getMessage()); } $connection->commit(); return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_INSTALLED)); } return array(DBPatcher\PatchFile::copyWithNewStatus($patchFile, DBPatcher\PatchFile::STATUS_ERROR)); }
$actionLabel = $previewStrategy($patchFile) ? 'install' : 'skip'; } catch (\DBPatcher\InputPreview\Exception $e) { $actionLabel = 'interactive'; } $output->out(\DBPatcher\patchText($patchFile) . " - {$actionLabel}"); return $actionLabel !== 'skip'; }; $runPatch = function ($patchFile) use($inputs, $output, $dbConnection, $applyStrategy) { $output->out("=================================="); $output->out(\DBPatcher\patchText($patchFile)); if (!$applyStrategy($patchFile)) { $output->out('Skipping'); return true; } if (\DBPatcher\Cli\getMarkPatchesOption($inputs)) { $patchFile = \DBPatcher\PatchFile::copyWithNewStatus($patchFile, \DBPatcher\PatchFile::STATUS_INSTALLED); } else { list($patchFile, $errorMsg) = array_merge(\DBPatcher\Apply\applyPatch($patchFile, $dbConnection, new \Symfony\Component\Process\Process(''), STDOUT, STDERR), array(null)); if ($patchFile->status === \DBPatcher\PatchFile::STATUS_ERROR) { $output->out("Error!", 'bold_red'); $output->out($errorMsg); } } \DBPatcher\Storage\savePatchFile($dbConnection, $patchFile); if ($patchFile->status === \DBPatcher\PatchFile::STATUS_ERROR) { return false; } $output->out("Success", 'bold_green'); return true; }; // --------------------------------------------------------------------------------------------------------------------
/** * @dataProvider forceAllStrategyTestProvider */ public function testForceAllStrategy($shouldSkip, $status) { $patchFile = p\PatchFile::copyWithNewStatus(p\PatchFile::_createForTest('n1', 'f1', 'm1', 'e1'), $status); $this->assertSame($shouldSkip, forceAllStrategy($patchFile)); }