mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 05:45:33 +08:00
Merge branch 'master' of git://github.com/yiisoft/yii2 into 9562-add-char-datatype
This commit is contained in:
@@ -10,6 +10,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #10946: Fixed parameters binding to the SQL query in `yii\db\mysqlSchema::findConstraints()` (silverfire)
|
||||
- Bug: SQlite querybuilder did not create primary key with bigint for `TYPE_BIGPK` (cebe)
|
||||
- Enh #5469: Add mimetype validation by mask in FileValidator (kirsenn, samdark, silverfire)
|
||||
- Enh #8602: `yii\validators\DateValidator` skip validation for `timestampAttribute`, if it is already in correct format (klimov-paul)
|
||||
- Enh #9893: `yii.js` handleAction enhanced to support for data-form attribute, so links can trigger specific forms (SamMousa)
|
||||
- Enh #10487: `yii\helpers\BaseArrayHelper::index()` got a third parameter `$groupBy` to group the input array by the key in one or more dimensions (quantum13, silverfire, samdark)
|
||||
- Enh #8639: Improve ActiveRecord to not create new instances of classes when objects are available (cebe)
|
||||
|
||||
@@ -324,7 +324,7 @@ yii = (function ($) {
|
||||
function initRedirectHandler() {
|
||||
// handle AJAX redirection
|
||||
$(document).ajaxComplete(function (event, xhr, settings) {
|
||||
var url = xhr.getResponseHeader('X-Redirect');
|
||||
var url = xhr && xhr.getResponseHeader('X-Redirect');
|
||||
if (url) {
|
||||
window.location = url;
|
||||
}
|
||||
|
||||
@@ -209,6 +209,17 @@ class DateValidator extends Validator
|
||||
$value = $model->$attribute;
|
||||
$timestamp = $this->parseDateValue($value);
|
||||
if ($timestamp === false) {
|
||||
if ($this->timestampAttribute === $attribute) {
|
||||
if ($this->timestampAttributeFormat === null) {
|
||||
if (ctype_digit($value)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ($this->parseDateValueFormat($value, $this->timestampAttributeFormat) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->addError($model, $attribute, $this->message, []);
|
||||
} elseif ($this->min !== null && $timestamp < $this->min) {
|
||||
$this->addError($model, $attribute, $this->tooSmall, ['min' => $this->minString]);
|
||||
@@ -247,12 +258,24 @@ class DateValidator extends Validator
|
||||
* @return integer|false a UNIX timestamp or `false` on failure.
|
||||
*/
|
||||
protected function parseDateValue($value)
|
||||
{
|
||||
// TODO consider merging these methods into single one at 2.1
|
||||
return $this->parseDateValueFormat($value, $this->format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses date string into UNIX timestamp
|
||||
*
|
||||
* @param string $value string representing date
|
||||
* @param string $format expected date format
|
||||
* @return integer|false a UNIX timestamp or `false` on failure.
|
||||
*/
|
||||
private function parseDateValueFormat($value, $format)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return false;
|
||||
}
|
||||
$format = $this->format;
|
||||
if (strncmp($this->format, 'php:', 4) === 0) {
|
||||
if (strncmp($format, 'php:', 4) === 0) {
|
||||
$format = substr($format, 4);
|
||||
} else {
|
||||
if (extension_loaded('intl')) {
|
||||
|
||||
@@ -539,4 +539,36 @@ class DateValidatorTest extends TestCase
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testValidateAttributePHPFormat
|
||||
*/
|
||||
public function testTimestampAttributeSkipValidation()
|
||||
{
|
||||
// timestamp as integer
|
||||
$val = new DateValidator(['format' => 'php:Y/m/d', 'timestampAttribute' => 'attr_date']);
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_date = 1379030400;
|
||||
$val->validateAttribute($model, 'attr_date');
|
||||
$this->assertFalse($model->hasErrors('attr_date'));
|
||||
|
||||
$val = new DateValidator(['format' => 'php:Y/m/d', 'timestampAttribute' => 'attr_date']);
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_date = 'invalid';
|
||||
$val->validateAttribute($model, 'attr_date');
|
||||
$this->assertTrue($model->hasErrors('attr_date'));
|
||||
|
||||
// timestamp as formatted date
|
||||
$val = new DateValidator(['format' => 'php:Y/m/d', 'timestampAttribute' => 'attr_date', 'timestampAttributeFormat' => 'php:Y-m-d']);
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_date = '2013-09-13';
|
||||
$val->validateAttribute($model, 'attr_date');
|
||||
$this->assertFalse($model->hasErrors('attr_date'));
|
||||
|
||||
$val = new DateValidator(['format' => 'php:Y/m/d', 'timestampAttribute' => 'attr_date', 'timestampAttributeFormat' => 'php:Y-m-d']);
|
||||
$model = new FakedValidationModel();
|
||||
$model->attr_date = '2013-09-2013';
|
||||
$val->validateAttribute($model, 'attr_date');
|
||||
$this->assertTrue($model->hasErrors('attr_date'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user