BUGFIX If the step doesn't exist, don't attempt to delete it

This commit is contained in:
Sean Harvey 2009-04-27 23:13:21 +00:00
parent 3690de6943
commit 04130ad501

View File

@ -1,68 +1,70 @@
<?php
/**
* Serializes one or more {@link MultiFormStep}s into
* a database object.
*
* MultiFormSession also stores the current step, so that
* the {@link MultiForm} and {@link MultiFormStep} classes
* know what the current step is.
*
* @package multiform
*/
class MultiFormSession extends DataObject {
static $db = array(
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
);
static $has_one = array(
'Submitter' => 'Member',
'CurrentStep' => 'MultiFormStep'
);
static $has_many = array(
'FormSteps' => 'MultiFormStep'
);
/**
* Mark this session as completed.
*
* This sets the flag "IsComplete" to true,
* and writes the session back.
*/
public function markCompleted() {
$this->IsComplete = 1;
$this->write();
}
/**
* These actions are performed when write() is called on this object.
*/
public function onBeforeWrite() {
// save submitter if a Member is logged in
$currentMember = Member::currentMember();
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
parent::onBeforeWrite();
}
/**
* These actions are performed when delete() is called on this object.
*/
public function onBeforeDelete() {
// delete dependent form steps and relation
$steps = $this->FormSteps();
if($steps) foreach($steps as $step) {
$steps->remove($step); // @TODO not sure if this is required (does delete() remove the relation too?)
$step->destroy();
$step->delete();
}
parent::onBeforeDelete();
}
/**
* Serializes one or more {@link MultiFormStep}s into
* a database object.
*
* MultiFormSession also stores the current step, so that
* the {@link MultiForm} and {@link MultiFormStep} classes
* know what the current step is.
*
* @package multiform
*/
class MultiFormSession extends DataObject {
static $db = array(
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
);
static $has_one = array(
'Submitter' => 'Member',
'CurrentStep' => 'MultiFormStep'
);
static $has_many = array(
'FormSteps' => 'MultiFormStep'
);
/**
* Mark this session as completed.
*
* This sets the flag "IsComplete" to true,
* and writes the session back.
*/
public function markCompleted() {
$this->IsComplete = 1;
$this->write();
}
/**
* These actions are performed when write() is called on this object.
*/
public function onBeforeWrite() {
// save submitter if a Member is logged in
$currentMember = Member::currentMember();
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
parent::onBeforeWrite();
}
/**
* These actions are performed when delete() is called on this object.
*/
public function onBeforeDelete() {
// delete dependent form steps and relation
$steps = $this->FormSteps();
if($steps) foreach($steps as $step) {
if($step && $step->exists()) {
$steps->remove($step);
$step->delete();
$step->destroy();
}
}
parent::onBeforeDelete();
}
}
?>
?>