public function validate()
{
$isNewModel = $this->isNewModel();
$this->validationMessages = ['version.regex' => Lang::get('rainlab.builder::lang.migration.error_version_invalid'), 'version.unique_version' => Lang::get('rainlab.builder::lang.migration.error_version_exists'), 'scriptFileName.regex' => Lang::get('rainlab.builder::lang.migration.error_script_filename_invalid')];
$versionInformation = $this->getPluginVersionInformation();
Validator::extend('uniqueVersion', function ($attribute, $value, $parameters) use($versionInformation, $isNewModel) {
if ($isNewModel || $this->version != $this->originalVersion) {
return !array_key_exists($value, $versionInformation);
}
return true;
});
if (!$isNewModel && $this->version != $this->originalVersion && $this->isApplied()) {
throw new ValidationException(['version' => Lang::get('rainlab.builder::lang.migration.error_cannot_change_version_number')]);
}
return parent::validate();
}