buildPatchList (array ($this, 'callback_unappliedOnly')); } function getAvailableDbPatches () { return $this->buildPatchList (); } public function callback_unappliedOnly ($file) { $last_patch_number = (int) Setting_Model::get (Setting_Model::S_LAST_PATCH_NUMBER); return $file [1] > $last_patch_number; } private function getPatchIterator () { return new RegexIterator (new DirectoryIterator (DATADIR . '/setup'), '~^patch\.(\d+)\.sql$~', RegexIterator::GET_MATCH); } private function buildPatchList ($filter = null) { $patch_numbers = array (); foreach ($this->getPatchIterator () as $file) { if (! isset ($filter) or call_user_func ($filter, $file)) { $patch_numbers [] = $file [1]; } } sort ($patch_numbers); $result = array (); foreach ($patch_numbers as $patch_number) { $filename = DATADIR . '/setup/patch.' . $patch_number . '.sql'; $patch = new Update_Patch_Db ($filename, $patch_number); $precondition_script = DATADIR . '/setup/pre.' . $patch_number . '.php'; if (file_exists ($precondition_script)) { $patch->setPreconditionScript ($precondition_script); } $postcondition_script = DATADIR . '/setup/post.' . $patch_number . '.php'; if (file_exists ($postcondition_script)) { $patch->setPostconditionScript ($postcondition_script); } $result [] = $patch; } return $result; } }