Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUG trac 7482 couldnt publish composite fields to live

When publishing to live, DataObject#forceChange is called, which wasnt correctly loading
in fields that were lazy (unloaded) if those fields were from composite fields
like Money. The end result is that any Money values would be forced to null on
publish to live

Also changes the API of the (internal, protected) loadLazyFields method so that
not passing a class argument just unlazys all lazy fields regardless of source table
  • Loading branch information...
commit e8cd675c94920f4508d64e93ae1bc9358a8e4b4c 1 parent 6992863
Hamish Friedlander hafriedlander authored
Showing with 19 additions and 11 deletions.
  1. +19 −11 model/DataObject.php
30 model/DataObject.php
View
@@ -679,13 +679,7 @@ public function data() {
* @return array The data as a map.
*/
public function toMap() {
- foreach ($this->record as $key => $value) {
- if (strlen($key) > 5 && substr($key, -5) == '_Lazy') {
- $this->loadLazyFields($value);
- break;
- }
- }
-
+ $this->loadLazyFields();
return $this->record;
}
@@ -847,13 +841,16 @@ public function merge($rightObj, $priority = 'right', $includeRelations = true,
* if they are not already marked as changed.
*/
public function forceChange() {
+ // Ensure lazy fields loaded
+ $this->loadLazyFields();
+
// $this->record might not contain the blank values so we loop on $this->inheritedDatabaseFields() as well
$fieldNames = array_unique(array_merge(array_keys($this->record), array_keys($this->inheritedDatabaseFields())));
foreach($fieldNames as $fieldName) {
if(!isset($this->changed[$fieldName])) $this->changed[$fieldName] = 1;
// Populate the null values in record so that they actually get written
- if(!$this->$fieldName) $this->record[$fieldName] = null;
+ if(!isset($this->record[$fieldName])) $this->record[$fieldName] = null;
}
// @todo Find better way to allow versioned to write a new version after forceChange
@@ -1954,13 +1951,24 @@ public function getAllFields() {
}
/**
- * Loads all the stub fields than an initial lazy load didn't load fully.
+ * Loads all the stub fields that an initial lazy load didn't load fully.
*
* @param tableClass Base table to load the values from. Others are joined as required.
+ * Not specifying a tableClass will load all lazy fields from all tables.
*/
protected function loadLazyFields($tableClass = null) {
- // Smarter way to work out the tableClass? Should the functionality in toMap and getField be moved into here?
- if (!$tableClass) $tableClass = $this->ClassName;
+ if (!$tableClass) {
+ $loaded = array();
+
+ foreach ($this->record as $key => $value) {
+ if (strlen($key) > 5 && substr($key, -5) == '_Lazy' && !array_key_exists($value, $loaded)) {
+ $this->loadLazyFields($value);
+ $loaded[$value] = $value;
+ }
+ }
+
+ return;
+ }
$dataQuery = new DataQuery($tableClass);
Please sign in to comment.
Something went wrong with that request. Please try again.