Skip to content

Instantly share code, notes, and snippets.

@jraddaoui
Created November 9, 2013 02:20
Show Gist options
  • Save jraddaoui/7380743 to your computer and use it in GitHub Desktop.
Save jraddaoui/7380743 to your computer and use it in GitHub Desktop.
<?php
// Add root term as parent for terms without it
$sql = sprintf("UPDATE %s
SET parent_id = ?
WHERE parent_id IS NULL
AND id != ?;", QubitTerm::TABLE_NAME);
QubitPdo::modify($sql, array(QubitTerm::ROOT_ID, QubitTerm::ROOT_ID));
// Update rgt value for root term
$sql = sprintf("UPDATE %s
SET rgt = (SELECT result.new_rgt
FROM (SELECT MAX(rgt) + 1 AS new_rgt FROM %s) result)
WHERE id = ?;", QubitTerm::TABLE_NAME, QubitTerm::TABLE_NAME);
QubitPdo::modify($sql, array(QubitTerm::ROOT_ID));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment