Ticket #1701 (closed defect: fixed)

Opened 16 months ago

Last modified 15 months ago

doctrine:data-load does not load product of NestedSet data-dump without children

Reported by: dao Owned by: jwage
Priority: major Milestone: 1.0.7
Component: Import/Export Version: 1.0.3
Severity: Keywords: NestedSet
Cc: Has Test: yes
Status: Pending Core Response Has Patch: yes

Description

I'm using sfDoctrinePlugin with symfony 1.2RC2 under windows/PHP 5.2.4, but the error is in Doctrine Core.

I dumped a simple NestedSet? (fixture and schema attached) with:

symfony doctrine:data-dump

and then tried to reload it with:

symfony doctrine:build-all-reload

My NestedSet? data was not loaded.

I found that Doctrine_Data_Import::_loadData looks for a 'children' property on $data if its class is a Tree. If so, it loads $data through Doctrine_Data_Import::_buildNestedSetRows. If not - as in my case - it loads through Doctrine_Data_Import::_buildRows. Later on in _loadData, there's another check to see if the data is from a tree, and if NOT, it's saved through $obj->save() (286-288). Because the data IS a tree and NOT included in $nestedSets, nothing happens.

The attached patch just removes the second check for isTree() from _loadData, and everything appears to work insofar as I'm able to manipulate the tree through sfDoctrineNestedSetManager and the contents of my NestedSet? table are identical before and after the reload.

I'm not sure why my data is dumped the way that it is, instead of with the 'children' property which seems to be how nestedSets are supposed to be exported.

Attachments

data.yml Download (0.5 KB) - added by dao 16 months ago.
Fixture per symfony doctrine:data-dump
schema.yml Download (1.8 KB) - added by dao 16 months ago.
schema.yml with Section acting as NestedSet?
1701-Data_Import.patch Download (3.7 KB) - added by dao 16 months ago.
Fixes NestedSet? import
1701-ImportTestCase.patch Download (5.7 KB) - added by dao 16 months ago.
Adds test for nested set data as exported by doctrine
1701-Doctrine_Data_Import.patch Download (0.7 KB) - added by piccoloprincipe 16 months ago.
Minimal patch proposal
1701-Data_Import_clarified.patch Download (5.4 KB) - added by dao 16 months ago.
clarifies handling of different forms of nested set fixtures in Data_Import

Change History

Changed 16 months ago by dao

Fixture per symfony doctrine:data-dump

Changed 16 months ago by dao

schema.yml with Section acting as NestedSet?

Changed 16 months ago by dao

  • has_test set

Modified tests/Data/ImportTestCase to include test for importing NestedSet? data as it is currently exported by Doctrine (with lft/rgt values). Before, ImportTestCase? only tested an alternate NestedSet? fixture format of nested children.

Created patch for lib/Doctrine/Data/Import, which works by processing $nestedSets first and clearing processed records from _importedObjects. Also removed a call to fetch $obj templates, as this wasn't used any more.

Changed 16 months ago by dao

Fixes NestedSet? import

Changed 16 months ago by dao

Adds test for nested set data as exported by doctrine

Changed 16 months ago by piccoloprincipe

Minimal patch proposal

Changed 16 months ago by piccoloprincipe

I have found the same issue and I think the problem resides in the $nestedSets array that is not populated if the children key in the $data array is not set. So I've attached a minimal patch that moves the line:

    $nestedSets[$className][] = $data;

out of the 'children' if.

Changed 16 months ago by dao

clarifies handling of different forms of nested set fixtures in Data_Import

Changed 16 months ago by dao

@piccoloprincipe: my patch for Import fixes the failing test I added to ImportTestCase? for raw nested set fixtures with lft/rgt values, and the tests for nested children fixtures still work, too.

Your patch is invalid because only tree fixtures with 'children' set should be added to $nestedSets and processed by _buildNestedSetRows; other tree fixtures in raw lft/rgt form need to be processed by _buildRows like any other fixture.

I've attached a new patch (tested) which clarifies all of this.

FYI, newlines at the end of a file are only bad when they follow a closing ?>

Changed 15 months ago by jwage

  • milestone changed from 1.0.5 to 1.0.6

Changed 15 months ago by jwage

  • milestone changed from 1.0.6 to 1.0.7

Changed 15 months ago by guilhermeblanco

  • status changed from new to closed
  • resolution set to fixed

In r5328 I applied this patch

Note: See TracTickets for help on using tickets.