Moving exceptions to clean method
This commit is contained in:
parent
cc6f2b2ca8
commit
b8c7f906eb
@ -43,14 +43,9 @@ class IDF_Form_ProjectRequest extends Pluf_Form
|
|||||||
$this->user = $extra['user'];
|
$this->user = $extra['user'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clean_shortname()
|
||||||
function save($commit=true)
|
|
||||||
{
|
{
|
||||||
if (!$this->isValid()) {
|
$shortname = mb_strtolower($this->cleaned_data['shortname']);
|
||||||
throw new Exception(__('Cannot save the model from an invalid form.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$shortname = $this->cleaned_data['shortname'];
|
|
||||||
if (preg_match('/[^\-A-Za-z0-9]/', $shortname)) {
|
if (preg_match('/[^\-A-Za-z0-9]/', $shortname)) {
|
||||||
throw new Pluf_Form_Invalid(__('This shortname contains illegal characters, please use only letters, digits and dash (-).'));
|
throw new Pluf_Form_Invalid(__('This shortname contains illegal characters, please use only letters, digits and dash (-).'));
|
||||||
}
|
}
|
||||||
@ -61,6 +56,16 @@ class IDF_Form_ProjectRequest extends Pluf_Form
|
|||||||
throw new Pluf_Form_Invalid(__('The shortname cannot end with the dash (-) character.'));
|
throw new Pluf_Form_Invalid(__('The shortname cannot end with the dash (-) character.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return trim($shortname);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function save($commit=true)
|
||||||
|
{
|
||||||
|
if (!$this->isValid()) {
|
||||||
|
throw new Exception(__('Cannot save the model from an invalid form.'));
|
||||||
|
}
|
||||||
|
|
||||||
$checksql = new Pluf_SQL(sprintf("shortname='%s'", $this->cleaned_data['shortname']));
|
$checksql = new Pluf_SQL(sprintf("shortname='%s'", $this->cleaned_data['shortname']));
|
||||||
$requestcheck = Pluf::factory("IDF_Project")->getCount(array('filter'=>$checksql->gen()));
|
$requestcheck = Pluf::factory("IDF_Project")->getCount(array('filter'=>$checksql->gen()));
|
||||||
if ($requestcheck == 1)
|
if ($requestcheck == 1)
|
||||||
@ -70,7 +75,7 @@ class IDF_Form_ProjectRequest extends Pluf_Form
|
|||||||
$request = new IDF_ProjectRequest();
|
$request = new IDF_ProjectRequest();
|
||||||
|
|
||||||
// The trim really isn't needed - but does ensure that no whitespace will end up in the name
|
// The trim really isn't needed - but does ensure that no whitespace will end up in the name
|
||||||
$request->shortname = trim($shortname);
|
$request->shortname = $this->cleaned_data['shortname'];
|
||||||
$request->repotype = $this->cleaned_data['repotype'];
|
$request->repotype = $this->cleaned_data['repotype'];
|
||||||
$request->desc = $this->cleaned_data['desc'];
|
$request->desc = $this->cleaned_data['desc'];
|
||||||
$request->submitter = $this->user;
|
$request->submitter = $this->user;
|
||||||
|
Loading…
Reference in New Issue
Block a user