mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
BUGFIX If the step doesn't exist, don't attempt to delete it
This commit is contained in:
parent
3690de6943
commit
04130ad501
@ -1,68 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes one or more {@link MultiFormStep}s into
|
* Serializes one or more {@link MultiFormStep}s into
|
||||||
* a database object.
|
* a database object.
|
||||||
*
|
*
|
||||||
* MultiFormSession also stores the current step, so that
|
* MultiFormSession also stores the current step, so that
|
||||||
* the {@link MultiForm} and {@link MultiFormStep} classes
|
* the {@link MultiForm} and {@link MultiFormStep} classes
|
||||||
* know what the current step is.
|
* know what the current step is.
|
||||||
*
|
*
|
||||||
* @package multiform
|
* @package multiform
|
||||||
*/
|
*/
|
||||||
class MultiFormSession extends DataObject {
|
class MultiFormSession extends DataObject {
|
||||||
|
|
||||||
static $db = array(
|
static $db = array(
|
||||||
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
|
'Hash' => 'Varchar(40)', // cryptographic hash identification to this session
|
||||||
'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
|
'IsComplete' => 'Boolean' // flag to determine if this session is marked completed
|
||||||
);
|
);
|
||||||
|
|
||||||
static $has_one = array(
|
static $has_one = array(
|
||||||
'Submitter' => 'Member',
|
'Submitter' => 'Member',
|
||||||
'CurrentStep' => 'MultiFormStep'
|
'CurrentStep' => 'MultiFormStep'
|
||||||
);
|
);
|
||||||
|
|
||||||
static $has_many = array(
|
static $has_many = array(
|
||||||
'FormSteps' => 'MultiFormStep'
|
'FormSteps' => 'MultiFormStep'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark this session as completed.
|
* Mark this session as completed.
|
||||||
*
|
*
|
||||||
* This sets the flag "IsComplete" to true,
|
* This sets the flag "IsComplete" to true,
|
||||||
* and writes the session back.
|
* and writes the session back.
|
||||||
*/
|
*/
|
||||||
public function markCompleted() {
|
public function markCompleted() {
|
||||||
$this->IsComplete = 1;
|
$this->IsComplete = 1;
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These actions are performed when write() is called on this object.
|
* These actions are performed when write() is called on this object.
|
||||||
*/
|
*/
|
||||||
public function onBeforeWrite() {
|
public function onBeforeWrite() {
|
||||||
// save submitter if a Member is logged in
|
// save submitter if a Member is logged in
|
||||||
$currentMember = Member::currentMember();
|
$currentMember = Member::currentMember();
|
||||||
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
|
if(!$this->SubmitterID && $currentMember) $this->SubmitterID = $currentMember->ID;
|
||||||
|
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These actions are performed when delete() is called on this object.
|
* These actions are performed when delete() is called on this object.
|
||||||
*/
|
*/
|
||||||
public function onBeforeDelete() {
|
public function onBeforeDelete() {
|
||||||
// delete dependent form steps and relation
|
// delete dependent form steps and relation
|
||||||
$steps = $this->FormSteps();
|
$steps = $this->FormSteps();
|
||||||
if($steps) foreach($steps as $step) {
|
if($steps) foreach($steps as $step) {
|
||||||
$steps->remove($step); // @TODO not sure if this is required (does delete() remove the relation too?)
|
if($step && $step->exists()) {
|
||||||
$step->destroy();
|
$steps->remove($step);
|
||||||
$step->delete();
|
$step->delete();
|
||||||
}
|
$step->destroy();
|
||||||
|
}
|
||||||
parent::onBeforeDelete();
|
}
|
||||||
}
|
|
||||||
|
parent::onBeforeDelete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user