public static function deleteSubtree($id) { static::applyDeleteRestrictions($id, $parentId = false); $parentColName = static::getPARENTIDColumnName(); $idColName = static::getIDColumnName(); $directColName = static::getDIRECTColumnName(); $dbConnection = Main\HttpApplication::getConnection(); // delete subtree itself $sql = "\n\t\t\tdelete from " . static::getTableName() . " where " . $idColName . " in (\n\t\t\t\t" . Helper::getTemporaryTableSubQuerySql("select " . $idColName . " from " . static::getTableName() . " where " . $parentColName . " = '" . intval($id) . "'", $idColName) . "\n\t\t\t)\n\t\t"; $res = $dbConnection->query($sql); /* while($item = $res->fetch()) { print_r('UNlink: '.$item[$parentColName].' => '.$item[$idColName].PHP_EOL); } */ }
/** * Breaks link between nodes. Low-level method. */ public static function dropLinkL($id, $parentId = false, $behaviour = array('CHILDREN' => 'unlink')) { $id = Assert::expectIntegerPositive($id, '$id'); if ($parentId !== false) { // parent id === false means that all links with all parents will be broken $parentId = Assert::expectIntegerPositive($parentId, '$parentId'); } if (!is_array($behaviour)) { $behaviour = array(); } if (!isset($behaviour['CHILDREN'])) { $behaviour['CHILDREN'] = 'unlink'; } if (!static::checkNodeExists($id)) { throw new Tree\TargetNodeNotFoundException('Node not found: ' . $id); } $parentColName = static::getPARENTIDColumnName(); $idColName = static::getIDColumnName(); $dbConnection = Main\HttpApplication::getConnection(); if ($behaviour['CHILDREN'] == 'unlink') { $dbConnection->query("delete from " . static::getTableName() . " where \n\t\t\t\t" . $idColName . " in (\n\t\t\t\t\t" . Helper::getTemporaryTableSubQuerySql("select " . $idColName . " from " . static::getTableName() . " where " . $parentColName . " = '" . intval($id) . "'", $idColName) . "\n\t\t\t\t)"); } elseif ($behaviour['CHILDREN'] == 'relocate') { throw new Main\NotImplementedException(); } }