public function getPatches($branch, $searchPatchNumber = null)
{
$patchDirectory = $this->getPatchDirectory();
if (!is_dir($patchDirectory)) {
$this->writer->error('path ' . $patchDirectory . ' doesn\'t exists');
return array();
}
try {
$iterator = new DirectoryIterator($patchDirectory);
} catch (Exception $e) {
$this->writer->line('Error: ' . $e->getMessage());
return array();
}
$branch = $branch == '' ? $this->getBranch() : $branch;
$patchPrefix = $this->getPatchPrefix();
if ($branch != self::DEFAULT_BRANCH) {
$patchPrefix .= '-' . $branch;
}
$patches = array();
$pattern = '/^' . preg_quote($patchPrefix) . '-(\\d{3,4})\\.(sql|php)$/';
foreach ($iterator as $fileinfo) {
if ($fileinfo->isDot() || substr($fileinfo->getFilename(), 0, 1) == '.') {
continue;
}
if (preg_match($pattern, $fileinfo->getFilename(), $matches)) {
$patchNumber = (int) $matches[1];
if (!is_null($searchPatchNumber) && $searchPatchNumber != '*' && $patchNumber != $searchPatchNumber || is_null($searchPatchNumber) && $this->isPatchApplied($patchNumber, $branch)) {
continue;
}
$filename = $patchDirectory . '/' . $fileinfo->getFilename();
$type = $matches[2];
$patch = DbPatch_Command_Patch::factory($type);
$patch->loadFromArray(array('filename' => $filename, 'basename' => $matches[0], 'patchNumber' => $patchNumber, 'branch' => $branch));
$patches[$patchNumber] = $patch;
}
}
ksort($patches);
return $patches;
}