Skip to content

Commit

Permalink
- Fixed #13332: Updating a data element only works if you've requeste…
Browse files Browse the repository at this point in the history
…d it

  before.


git-svn-id: http://svn.ez.no/svn/ezcomponents/trunk@11386 bc0e7bdc-f0fc-0310-8ff6-f601c06e1256
  • Loading branch information
kn committed Feb 17, 2010
1 parent 90a9036 commit 8fbc43b
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Tree/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.1.4 - [RELEASEDATE]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fixed #13332: Updating a data element only works if you've requested it
before.


1.1.3 - Monday 22 June 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
3 changes: 2 additions & 1 deletion Tree/src/stores/xml_internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function fetchDataForNode( ezcTreeNode $node )
{
throw new ezcTreeDataStoreMissingDataException( $node->id );
}
$node->data = $dataElem->firstChild->data;

$node->injectData( $dataElem->firstChild->data );
$node->dataFetched = true;
}

Expand Down
28 changes: 23 additions & 5 deletions Tree/src/tree_node.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ public function __set( $name, $value )
throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ );

case 'data':
$this->properties[$name] = $value;
$this->properties['dataStored'] = false;
if ( $this->properties['dataFetched'] )
if ( !$this->properties['dataFetched'] )
{
$this->tree->store->storeDataForNode( $this );
$this->tree->store->fetchDataForNode( $this );
$this->properties['dataFetched'] = true;
}
$this->properties['dataFetched'] = true;

$this->properties[$name] = $value;
$this->properties['dataStored'] = false;
$this->tree->store->storeDataForNode( $this );
return;

case 'dataFetched':
Expand Down Expand Up @@ -178,6 +180,22 @@ public function __isset( $name )
}
}

/**
* Inject data.
*
* Used to set the data from a data loader. Should not be used for
* interfacing with the tree node, since the node will not be flagged as
* modified by this method.
*
* @access private
* @param string $data
* @return void
*/
public function injectData( $data )
{
$this->properties['data'] = $data;
}

/**
* Implements the accept method for visiting.
*
Expand Down
29 changes: 29 additions & 0 deletions Tree/tests/files/init-renamed-node.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tree PUBLIC "" "">
<tree prefix="id" xmlns="http://components.ez.no/Tree" xmlns:etd="http://components.ez.no/Tree/data">
<node id="id1">
<etd:data>Node 1 renamed</etd:data>
<node id="id2">
<etd:data>Node 2</etd:data>
</node>
<node id="id3">
<etd:data>Node 3</etd:data>
</node>
<node id="id4">
<etd:data>Node 4</etd:data>
<node id="id6">
<etd:data>Node 6</etd:data>
<node id="id7">
<etd:data>Node 7</etd:data>
</node>
<node id="id8">
<etd:data>Node 8</etd:data>
</node>
</node>
</node>
<node id="id5">
<etd:data>Node 5</etd:data>
<node id="id9"/>
</node>
</node>
</tree>
13 changes: 13 additions & 0 deletions Tree/tests/xml_tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ public function testStoreUpdatedData2()
self::assertSame( "Non-Metals renamed", $nonMetals->data );
}

public function testStoreUpdatedData3()
{
$tree = $this->setUpTestTree();

$node = $tree->fetchNodeById( 1 );
$node->data = "Node 1 renamed";

self::assertXmlFileEqualsXmlFile(
dirname( __FILE__ ) . '/files/init-renamed-node.xml',
$this->tempDir . '/test.xml'
);
}

public function testReloadAutoGenId()
{
$tree = ezcTreeXml::create(
Expand Down

0 comments on commit 8fbc43b

Please sign in to comment.