project = $extra['project']; $this->user = $extra['user']; $this->fields['code'] = new Pluf_Form_Field_Varchar( array('required' => true, 'label' => __('Confirmation code'), 'initial' => '', )); $this->fields['agree'] = new Pluf_Form_Field_Boolean( array('required' => true, 'label' => __('I have made a backup of all the important data of this project.'), 'initial' => '', )); } public function clean_code() { $code = $this->cleaned_data['code']; if ($code != $this->getCode()) { throw new Pluf_Form_Invalid(__('The confirmation code does not match. Please provide a valid confirmation code to delete the project.')); } return $code; } public function clean_agree() { if (!$this->cleaned_data['agree']) { throw new Pluf_Form_Invalid(__('Sorry, you really need to backup your data before deletion.')); } return $this->cleaned_data['agree']; } public function getCode() { return substr(md5(Pluf::f('secret_key').$this->user->id.'.'.$this->project->id), 0, 8); } public function save($commit=true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } // So, we drop the project, it will cascade and delete all the // elements of the project. For large projects, this may use // quite some memory. $this->project->delete(); return true; } }