Skip to content

Commit

Permalink
Fixed issue #15195: Expiration date can be set before start date (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljenik committed Nov 10, 2022
1 parent dbc22fc commit 020da64
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions application/models/Survey.php
Expand Up @@ -397,14 +397,29 @@ public function expire($surveyId = null)
$dateTime = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i:s", Yii::app()->getConfig('timeadjust'));
$dateTime = dateShift($dateTime, "Y-m-d H:i:s", '-1 minute');

if (!isset($surveyId)) {
$this->expires = $dateTime;
if ($this->scenario == 'update') {
return $this->save();
}
} else {
self::model()->updateByPk($surveyId, array('expires' => $dateTime));
$model = $this;

// Set model based on surveyId, if given
// If so, set scenario as to be saved later
if (isset($surveyId)) {
$model = self::model()->findByPk($surveyId);
$model->setScenario('update');
}

// Avoid setting expiration date before start date
// If there is a future start date set, set the expiration date to the same date
if (!empty($model->startdate) && $dateTime < $model->startdate) {
$dateTime = $model->startdate;
}

// Set expiration date
$model->expires = $dateTime;

// Save if scenario is update
if ($model->scenario == 'update') {
return $model->save();
}

return null;
}

Expand Down Expand Up @@ -534,7 +549,7 @@ public function rules()
array('expires', 'date','format' => ['yyyy-M-d H:m:s.???','yyyy-M-d H:m:s','yyyy-M-d H:m'],'allowEmpty' => true),
array('startdate', 'date','format' => ['yyyy-M-d H:m:s.???','yyyy-M-d H:m:s','yyyy-M-d H:m'],'allowEmpty' => true),
array('datecreated', 'date','format' => ['yyyy-M-d H:m:s.???','yyyy-M-d H:m:s','yyyy-M-d H:m'],'allowEmpty' => true),
//array('expires', 'checkExpireAfterStart'),
array('expires', 'checkExpireAfterStart'),
);
}

Expand Down

0 comments on commit 020da64

Please sign in to comment.