From 8cf88300db1fb0dc4b86e1589f59c004cbc314d9 Mon Sep 17 00:00:00 2001 From: ucorina Date: Wed, 5 Oct 2011 13:29:37 +0000 Subject: [PATCH] Issue 359 - Secret documents's status changed to public. git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9498 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- .../xml/xmlquery/argument/Argument.class.php | 2 +- .../argument/ConditionArgument.class.php | 13 +++++++++++- .../db/xml_query/mysql/MysqlUpdateTest.php | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php diff --git a/classes/xml/xmlquery/argument/Argument.class.php b/classes/xml/xmlquery/argument/Argument.class.php index 1fe6a7409..d5046763b 100644 --- a/classes/xml/xmlquery/argument/Argument.class.php +++ b/classes/xml/xmlquery/argument/Argument.class.php @@ -67,7 +67,7 @@ return $dbParser->parseExpression($value); } if(!isset($value)) return null; - if(in_array($this->type, array('date', 'varchar', 'char','text', 'bigtext'))){ + if(in_array($this->getType(), array('date', 'varchar', 'char','text', 'bigtext'))){ if(!is_array($value)) $value = $this->_escapeStringValue ($value); else { diff --git a/classes/xml/xmlquery/argument/ConditionArgument.class.php b/classes/xml/xmlquery/argument/ConditionArgument.class.php index 2094d9eeb..e11350aa1 100644 --- a/classes/xml/xmlquery/argument/ConditionArgument.class.php +++ b/classes/xml/xmlquery/argument/ConditionArgument.class.php @@ -40,8 +40,19 @@ } } + /** + * Since ConditionArgument is used in WHERE clause, + * where the argument value is compared to a table column, + * it is assumed that all arguments have type. There are cases though + * where the column does not have any type - if it was removed from + * the XML schema for example - see the is_secret column in xe_documents table. + * In this case, the column type is retrieved according to argument + * value type (using the PHP function is_numeric). + * + * @return type string + */ function getType(){ - return $this->type; + return $this->type ? $this->type : (!is_numeric($this->value) ? "varchar" : ""); } function setColumnType($column_type){ diff --git a/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php b/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php new file mode 100644 index 000000000..e4264945d --- /dev/null +++ b/test-phpUnit/db/xml_query/mysql/MysqlUpdateTest.php @@ -0,0 +1,20 @@ +_testQuery($xml_file, $argsString, $expected, 'getUpdateSql', $columnList); + } + + function test_document_updateDocumentStatus(){ + $xml_file = _XE_PATH_ . "modules/document/queries/updateDocumentStatus.xml"; + $argsString = '$args->is_secret = \'Y\'; + $args->status = \'SECRET\'; + '; + $expected = 'update `xe_documents` set `status` = \'secret\' where `is_secret` = \'y\''; + $this->_test($xml_file, $argsString, $expected); + } + + + } \ No newline at end of file