protected function validate()
{
$validation = parent::validate();
if ($validation->valid()) {
if (empty($this->Name)) {
return $validation->error('The stack must have a name.');
}
// The name is used to build filepaths so should be restricted
if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9\\-\\_]+$/', $this->Name)) {
return $validation->error('Project name can only contain alphanumeric, hyphens and underscores.');
}
if (empty($this->CVSPath)) {
return $validation->error('You must provide a repository URL.');
}
$existing = DNProject::get()->filter('Name', $this->Name);
if ($this->ID) {
$existing = $existing->exclude('ID', $this->ID);
}
if ($existing->count() > 0) {
return $validation->error('A stack already exists with that name.');
}
}
return $validation;
}