Merge lp:~quam-plures-core/quam-plures/dataobject-set_param-integer-fix into lp:quam-plures

Proposed by Tilman Blumenbach
Status: Merged
Merged at revision: not available
Proposed branch: lp:~quam-plures-core/quam-plures/dataobject-set_param-integer-fix
Merge into: lp:quam-plures
Diff against target: 58 lines (+33/-2)
1 file modified
inc/_core/model/dataobjects/_dataobject.class.php (+33/-2)
To merge this branch: bzr merge lp:~quam-plures-core/quam-plures/dataobject-set_param-integer-fix
Reviewer Review Type Date Requested Status
EdB Approve
Review via email: mp+19516@code.launchpad.net
To post a comment you must log in.
Revision history for this message
EdB (edb) wrote :

Since you're way ahead of me with this smarts stuff all I can say on a quick look is "wow that's a pretty big comment block ya got there" ;)

I'll d/l the branch and do a localhost test then say okay or it failed, but wow I gotta go sit in a smelly room on a plastic chair for a few hours so the state will love me at this particular moment. Half a day or so, please.

Revision history for this message
Tilman Blumenbach (tblue) wrote :

Of course, take your time.

This is just a merge from b2evolution trunk.

Revision history for this message
EdB (edb) wrote :

Tested on localhost, can't find nothing wrong, so ... merge away!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'inc/_core/model/dataobjects/_dataobject.class.php'
2--- inc/_core/model/dataobjects/_dataobject.class.php 2009-12-19 19:51:52 +0000
3+++ inc/_core/model/dataobjects/_dataobject.class.php 2010-02-17 18:27:17 +0000
4@@ -532,6 +532,34 @@
5 // i-e: transform 0 to ''
6 $new_value = ($make_null && ($parvalue === '')) ? NULL : $parvalue;
7
8+ /* Tblue> Problem: All class member variables originating from the
9+ * DB are strings (unless they were NULL in the DB,
10+ * then they are set to NULL by the PHP MySQL
11+ * extension).
12+ * If we pass an integer or a double to this function,
13+ * the corresponding member variable gets changed
14+ * on every call, because its type is 'string' and
15+ * we compare using the === operator. Using the
16+ * == operator would be a bad idea, though, because
17+ * somebody could pass a NULL value to this function.
18+ * If the member variable then is set to 0, then
19+ * 0 equals NULL and the member variable does not
20+ * get updated at all!
21+ * Thus, using the === operator is correct.
22+ * Solution: If $fieldtype is 'number' and the type of the
23+ * passed value is either integer or double, we
24+ * convert it to a string (no data loss). The
25+ * member variable and the passed value can then
26+ * be correctly compared using the === operator.
27+ * fp> It would be nicer to convert numeric values to ints & floats at load time in class constructor x=(int)$y->value or sth.
28+ * THIS IS EXPERIMENTAL! Feel free to revert if something does not
29+ * work as expected.
30+ */
31+ if( $fieldtype == 'number' && ( is_int( $new_value ) || is_float( $new_value ) ) )
32+ {
33+ settype( $new_value, 'string' );
34+ }
35+
36 /* >old
37 if( !isset($this->$parname) )
38 { // This property has never been set before, set it to NULL now in order for tests to work:
39@@ -563,8 +591,11 @@
40 {
41 // Set the value in the object:
42 // echo '<br/>'.$this->dbtablename.' object, setting param '.$parname.'/'.$dbfield.' to '.$new_value.(is_null($new_value)?' NULL':'').' (was:'.$this->$parname.(is_null($this->$parname)?' NULL':'').')';
43+ $Debuglog->add( $this->dbtablename.' object, setting param '
44+ .$parname.'/'.$dbfield.' to '.var_export( $new_value, true )
45+ .' (old: '.( isset( $this->$parname ) ? var_export( $this->$parname, true ) : 'NULL' )
46+ .')', 'dataobjects' );
47 $this->$parname = $new_value;
48- $Debuglog->add( $this->dbtablename.' object, setting param '.$parname.'/'.$dbfield.' to '.$this->$parname, 'dataobjects' );
49
50 // Remember change for later db update:
51 $this->dbchange( $dbfield, $fieldtype, $parname );
52@@ -656,4 +687,4 @@
53
54
55
56-?>
57\ No newline at end of file
58+?>

Subscribers

People subscribed via source and target branches