This can be implemented much easier by instantiating the catalog and locale manager, use their getTree() method to fetch the whole tree and update each node in the database while traversing the whole tree.