<?php
require 'autoload.php';
/*
First of all, create the tables on some DB
==========================================
CREATE TABLE `eztaxonomy_tree_nested_set` (
`id` varchar(255) NOT NULL,
`parent_id` varchar(255),
`lft` integer NOT NULL,
`rgt` integer NOT NULL
);
CREATE UNIQUE INDEX `nested_set_pri` on `eztaxonomy_tree_nested_set` ( `id` );
CREATE INDEX `nested_set_left` on `eztaxonomy_tree_nested_set` ( `lft` );
CREATE INDEX `nested_set_right` on `eztaxonomy_tree_nested_set` ( `rgt` );
CREATE TABLE `eztaxonomy_tree_data` (
`node_id` varchar(255) NOT NULL,
`keyword` varchar(255),
`used_by` longtext
);
CREATE UNIQUE INDEX `data_pri` on `eztaxonomy_tree_data` ( `node_id` );
Then
====
Update the method ezcTreeIssueTest::createDBConnection() : change the DB connection credentials.
Synopsis
========
* the method initiateTreeStructure() creates a root node containing data. Right after having called getTree(), the tree contains only the root node called "Root of the tree"
* adding a child to the root replaces the root ( check the content of the DB after having executed this script ).
Potential causes
================
* the generateNodeID() method in TreeDatabaseTiein/src/backends/db.php does not seem to return the right value. Might come from PDO::lastInsertId( .. ) or form a
misconfiguration of the DB fields above. My 2 cents.
*/
class ezcTreeIssueTest
{
public $tree = null;
protected $tree_struct_db = 'eztaxonomy_tree_nested_set';
protected $tree_data_db = 'eztaxonomy_tree_data';
public function getTree()
{
try {
$dbHandler = $this->createDbConnection();
}
catch ( ezcDbHandlerNotFoundException $e )
{
throw new eZTaxonomyUnavailableTreeException( $e->getMessage() );
}
$store = new ezcTreeDbExternalTableDataStore( $dbHandler, $this->tree_data_db, 'node_id' );
// $this->tree = ezcTreeDbNestedSet::create( $dbHandler, $this->tree_struct_db, $store );
$this->tree = new ezcTreeDbNestedSet( $dbHandler, $this->tree_struct_db, $store );
$this->tree->autoId = true;
$this->initiateTreeStructure();
return $this->tree;
}
protected function initiateTreeStructure()
{
if ( $this->tree->getRootNode() === null )
{
// No root node was set, create one.
$this->tree->setRootNode( $this->tree->createNode( null, array( 'keyword' => 'Root of the tree', 'used_by' => '' ) ) );
}
}
function createDBConnection()
{
$dsn = '';
$dsn .= 'mysql';
$dsn .= '://';
$dsn .= 'remote';
$dsn .= ':';
$dsn .= 'start';
$dsn .= '@';
$dsn .= 'localhost';
$dsn .= '/';
$dsn .= 'ezctree_nestedset_autoid_issue';
return ezcDbFactory::create( $dsn );
}
}
$ezcTreeIsueTest = new ezcTreeIssueTest();
try
{
$tree = $ezcTreeIsueTest->getTree();
}
catch ( Exception $e )
{
$error .= ' ' . $e->getMessage();
}
$ezcNode = $tree->getRootNode();
$newNode = $tree->createNode( null, array( 'keyword' => 'child node',
'used_by' => '' ) );
$ezcNode->addChild( $newNode );
?>
Hello !
as discussed on IRC, here is the php script used to reproduce the
auto Id issue i happen to have stumbled upon.
All necessary info is written in the header of this file.
Cheers,
--
Nicolas Pastorino
Consultant - Trainer - System Developer
Phone : +33 (0)4.78.37.01.34
eZ Systems ( Western Europe ) | http://ez.no
--
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components