Skip to content

Commit

Permalink
Merge branch 'EZP-16509_changing_db_default_values' into dev-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
pkamps committed Sep 7, 2020
2 parents 0cdf8a0 + 2ebaf40 commit 7c5772c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 58 deletions.
74 changes: 34 additions & 40 deletions kernel/classes/datatypes/ezinteger/ezintegertype.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute
return eZInputValidator::STATE_ACCEPTED;
}

function fixupObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
{
}

/*!
Sets the default value.
*/
Expand Down Expand Up @@ -236,25 +232,16 @@ function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $
return false;
}

/*!
Does nothing, the data is already present in the attribute.
*/
function storeObjectAttribute( $object_attribute )
{
}

function storeClassAttribute( $attribute, $version )
{
}

function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
{
$returnValue = eZInputValidator::STATE_INVALID;

$minValueName = $base . self::MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" );
$maxValueName = $base . self::MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" );
$defaultValueName = $base . self::DEFAULT_VALUE_VARIABLE . $classAttribute->attribute( "id" );

if ( $http->hasPostVariable( $minValueName ) and
$http->hasPostVariable( $maxValueName ) and
if ( $http->hasPostVariable( $minValueName ) &&
$http->hasPostVariable( $maxValueName ) &&
$http->hasPostVariable( $defaultValueName ) )
{
$minValueValue = $http->postVariable( $minValueName );
Expand All @@ -264,52 +251,54 @@ function validateClassAttributeHTTPInput( $http, $base, $classAttribute )
$defaultValueValue = $http->postVariable( $defaultValueName );
$defaultValueValue = str_replace(" ", "", $defaultValueValue );

if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){
return eZInputValidator::STATE_ACCEPTED;
if ( ( $minValueValue == "" ) && ( $maxValueValue == "") )
{
$returnValue = eZInputValidator::STATE_ACCEPTED;
}
else if ( ( $minValueValue == "" ) && ( $maxValueValue !== "") )
{
$max_state = $this->IntegerValidator->validate( $maxValueValue );
return $max_state;
$returnValue = $this->IntegerValidator->validate( $maxValueValue );
}
else if ( ( $minValueValue !== "" ) && ( $maxValueValue == "") )
{
$min_state = $this->IntegerValidator->validate( $minValueValue );
return $min_state;
$returnValue = $this->IntegerValidator->validate( $minValueValue );
}
else
{
$min_state = $this->IntegerValidator->validate( $minValueValue );
$max_state = $this->IntegerValidator->validate( $maxValueValue );
if ( ( $min_state == eZInputValidator::STATE_ACCEPTED ) and
if ( ( $min_state == eZInputValidator::STATE_ACCEPTED ) &&
( $max_state == eZInputValidator::STATE_ACCEPTED ) )
{
if ($minValueValue <= $maxValueValue)
return eZInputValidator::STATE_ACCEPTED;
if ( $minValueValue <= $maxValueValue )
{
$returnValue = eZInputValidator::STATE_ACCEPTED;
}
else
{
$state = eZInputValidator::STATE_INTERMEDIATE;
eZDebug::writeNotice( "Integer minimum value greater than maximum value.", __METHOD__ );
return $state;
eZDebug::writeNotice( "Integer minimum value great than maximum value.", __METHOD__ );
$returnValue = eZInputValidator::STATE_INTERMEDIATE;
}
}
}

if ($defaultValueValue == ""){
$default_state = eZInputValidator::STATE_ACCEPTED;
if( $returnValue == eZInputValidator::STATE_ACCEPTED )
{
if( $defaultValueValue != "" )
{
$returnValue = $this->IntegerValidator->validate( $defaultValueValue );
}
}
else
$default_state = $this->IntegerValidator->validate( $defaultValueValue );
}

return eZInputValidator::STATE_INVALID;
return $returnValue;
}

function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
{
$minValueName = $base . self::MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" );
$maxValueName = $base . self::MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" );
if ( $http->hasPostVariable( $minValueName ) and $http->hasPostVariable( $maxValueName ) )
if ( $http->hasPostVariable( $minValueName ) && $http->hasPostVariable( $maxValueName ) )
{
$minValueValue = $http->postVariable( $minValueName );
$minValueValue = $this->IntegerValidator->fixup( $minValueValue );
Expand All @@ -328,14 +317,20 @@ function fixupClassAttributeHTTPInput( $http, $base, $classAttribute )
}
}

/**
* @param $http
* @param $base
* @param eZContentClassAttribute $classAttribute
* @return bool|void
*/
function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
{
$minValueName = $base . self::MIN_VALUE_VARIABLE . $classAttribute->attribute( "id" );
$maxValueName = $base . self::MAX_VALUE_VARIABLE . $classAttribute->attribute( "id" );
$defaultValueName = $base . self::DEFAULT_VALUE_VARIABLE . $classAttribute->attribute( "id" );

if ( $http->hasPostVariable( $minValueName ) and
$http->hasPostVariable( $maxValueName ) and
if ( $http->hasPostVariable( $minValueName ) &&
$http->hasPostVariable( $maxValueName ) &&
$http->hasPostVariable( $defaultValueName ) )
{
$minValueValue = $http->postVariable( $minValueName );
Expand All @@ -349,7 +344,8 @@ function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
$classAttribute->setAttribute( self::MAX_VALUE_FIELD, $maxValueValue );
$classAttribute->setAttribute( self::DEFAULT_VALUE_FIELD, $defaultValueValue );

if ( ( $minValueValue == "" ) && ( $maxValueValue == "") ){
if ( ( $minValueValue == "" ) && ( $maxValueValue == "") )
{
$input_state = self::NO_MIN_MAX_VALUE;
$classAttribute->setAttribute( self::INPUT_STATE_FIELD, $input_state );
}
Expand Down Expand Up @@ -381,7 +377,6 @@ function objectAttributeContent( $contentObjectAttribute )
return $contentObjectAttribute->attribute( "data_int" );
}


/*!
Returns the meta data used for storing search indeces.
*/
Expand Down Expand Up @@ -511,4 +506,3 @@ function supportsBatchInitializeObjectAttribute()

eZDataType::register( eZIntegerType::DATA_TYPE_STRING, "eZIntegerType" );

?>
8 changes: 4 additions & 4 deletions kernel/classes/datatypes/ezmatrix/ezmatrixtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $o
else
{
$contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
$numRows = $contentClassAttribute->attribute( 'data_int1' );
$numRows = (int)$contentClassAttribute->attribute( 'data_int1' );
$matrix = new eZMatrix( '', $numRows, $contentClassAttribute->attribute( 'content' ) );
// 'default name' is never used => just a stub
// $matrix->setName( $contentClassAttribute->attribute( 'data_text1' ) );
Expand Down Expand Up @@ -436,7 +436,7 @@ function serializeContentClassAttribute( $classAttribute, $attributeNode, $attri
if ( $content )
{
$defaultName = $classAttribute->attribute( 'data_text1' );
$defaultRowCount = $classAttribute->attribute( 'data_int1' );
$defaultRowCount = (int)$classAttribute->attribute( 'data_int1' );
$columns = $content->attribute( 'columns' );

$dom = $attributeParametersNode->ownerDocument;
Expand Down Expand Up @@ -465,7 +465,7 @@ function unserializeContentClassAttribute( $classAttribute, $attributeNode, $att
$defaultName = $attributeParametersNode->getElementsByTagName( 'default-name' )->item( 0 )->textContent;
$defaultRowCount = $attributeParametersNode->getElementsByTagName( 'default-row-count' )->item( 0 )->textContent;
$classAttribute->setAttribute( 'data_text1', $defaultName );
$classAttribute->setAttribute( 'data_int1', $defaultRowCount );
$classAttribute->setAttribute( 'data_int1', (int)$defaultRowCount );

$matrixDefinition = new eZMatrixDefinition();
$columnsNode = $attributeParametersNode->getElementsByTagName( 'columns' )->item( 0 );
Expand Down Expand Up @@ -506,7 +506,7 @@ function supportsBatchInitializeObjectAttribute()

function batchInitializeObjectAttributeData( $classAttribute )
{
$numRows = $classAttribute->attribute( 'data_int1' );
$numRows = (int)$classAttribute->attribute( 'data_int1' );
$matrix = new eZMatrix( '', $numRows, $classAttribute->attribute( 'content' ) );
$db = eZDB::instance();
return array( 'data_text' => "'" . $db->escapeString( $matrix->xmlString() ) . "'" );
Expand Down
7 changes: 1 addition & 6 deletions kernel/classes/datatypes/ezstring/ezstringtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ function insertSimpleString( $object, $objectVersion, $objectLanguage,
return true;
}

function storeClassAttribute( $attribute, $version )
{
}

function storeDefinedClassAttribute( $attribute )
{
}
Expand Down Expand Up @@ -255,7 +251,7 @@ function fetchClassAttributeHTTPInput( $http, $base, $classAttribute )
$defaultValueName = $base . self::DEFAULT_STRING_VARIABLE . $classAttribute->attribute( 'id' );
if ( $http->hasPostVariable( $maxLenName ) )
{
$maxLenValue = $http->postVariable( $maxLenName );
$maxLenValue = (int) $http->postVariable( $maxLenName );
$classAttribute->setAttribute( self::MAX_LEN_FIELD, $maxLenValue );
}
if ( $http->hasPostVariable( $defaultValueName ) )
Expand Down Expand Up @@ -391,4 +387,3 @@ function batchInitializeObjectAttributeData( $classAttribute )

eZDataType::register( eZStringType::DATA_TYPE_STRING, 'eZStringType' );

?>
16 changes: 8 additions & 8 deletions kernel/classes/ezcontentclassattribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,35 @@ static function definition()
'required' => true ),
'data_int1' => array( 'name' => 'DataInt1',
'datatype' => 'integer',
'default' => 0,
'default' => null,
'required' => true ),
'data_int2' => array( 'name' => 'DataInt2',
'datatype' => 'integer',
'default' => 0,
'default' => null,
'required' => true ),
'data_int3' => array( 'name' => 'DataInt3',
'datatype' => 'integer',
'default' => 0,
'default' => null,
'required' => true ),
'data_int4' => array( 'name' => 'DataInt4',
'datatype' => 'integer',
'default' => 0,
'default' => null,
'required' => true ),
'data_float1' => array( 'name' => 'DataFloat1',
'datatype' => 'float',
'default' => 0,
'default' => null,
'required' => true ),
'data_float2' => array( 'name' => 'DataFloat2',
'datatype' => 'float',
'default' => 0,
'default' => null,
'required' => true ),
'data_float3' => array( 'name' => 'DataFloat3',
'datatype' => 'float',
'default' => 0,
'default' => null,
'required' => true ),
'data_float4' => array( 'name' => 'DataFloat4',
'datatype' => 'float',
'default' => 0,
'default' => null,
'required' => true ),
'data_text1' => array( 'name' => 'DataText1',
'datatype' => 'text',
Expand Down

0 comments on commit 7c5772c

Please sign in to comment.