PartKeepr\CoreBundle\DoctrineMigrations\Version20150708120022::fixTree PHP Method

fixTree() public method

Fixes the tree for a given table due to the migration of doctrine2-nestedset to DoctrineExtensions.
public fixTree ( string $table )
$table string The table name to fix
    public function fixTree($table)
    {
        $nodes = $this->getNodeIds($table);
        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder->update($table)->set('parent_id', ':parent')->set('root', ':root')->set('lvl', ':level')->where('id = :id');
        foreach ($nodes as $node) {
            $parent = $this->fetchParent($table, $node['id']);
            $level = $this->getLevel($table, $node['id']);
            if ($parent !== false) {
                $this->connection->executeUpdate($queryBuilder->getSQL(), [':parent' => $parent, ':id' => $node['id'], ':level' => $level, ':root' => 1]);
            } else {
                $this->connection->executeUpdate($queryBuilder->getSQL(), [':parent' => null, ':id' => $node['id'], ':root' => 1, ':level' => 0]);
            }
        }
    }