| {CODE()}public function move_to_structure($page_ref_id, $structure_id, $begin=true){CODE} | | {CODE()}public function move_to_structure($page_ref_id, $structure_id, $begin=true){CODE} |
| changes the moved node's structure_id, but not the children's structure_id. The target structure will still show the children, but will not allow them to be moved. (Pressing save will have no effect, basically causing a read-only structure, with no warnings or errors ouptut) | | changes the moved node's structure_id, but not the children's structure_id. The target structure will still show the children, but will not allow them to be moved. (Pressing save will have no effect, basically causing a read-only structure, with no warnings or errors ouptut) |
| + | --- |
| + | Here's your fix: |
| + | {CODE(colors=""""php"""")}{ |
| + | $page_info = $this->s_get_page_info($page_ref_id); |
| + | $query = """"update `tiki_structures` set `pos`=`pos`-1 where `pos`>? and `parent_id`=?""""; |
| + | $this->query($query, array((int) $page_info[""""pos""""], (int) $page_info[""""parent_id""""])); |
| + | if ($begin) { |
| + | $query = """"update `tiki_structures` set `pos`=`pos`+1 where `parent_id`=?""""; |
| + | $this->query($query, array($structure_id)); |
| + | $pos = 1; |
| + | $query = """"update `tiki_structures` set `structure_id`=?, `parent_id`=?, `pos`=? where `page_ref_id`=?""""; |
| + | $this->query($query, array($structure_id, $structure_id, $pos+1, $page_ref_id)); |
| + | } else { |
| + | $query = """"select max(`pos`) from `tiki_structures` where `parent_id`=?""""; |
| + | $pos = $this->getOne($query, array($structure_id)); |
| + | $query = """"update `tiki_structures` set `structure_id`=?, `parent_id`=?, `pos`=? where `page_ref_id`=?""""; |
| + | $this->query($query, array($structure_id, $structure_id, $pos+1, $page_ref_id)); |
| + | } |
| + | // get the page_ref_ids of all child pages of the moved page |
| + | $child_ref_ids = array(); |
| + | $result = $this->query(""""select child.page_ref_id from tiki_structures p inner join tiki_structures child on child.parent_id = p.page_ref_id where p.page_ref_id="""" . $page_ref_id); |
| + | while ($row = $result->fetchRow()){ |
| + | array_push($child_ref_ids, $row['page_ref_id']); |
| + | } |
| + | // update the structure ids of the child pages |
| + | $this->query(""""update tiki_structures set structure_id="""" . $structure_id . """" where page_ref_id in ("""" . implode(',',$child_ref_ids) . """")""""); |
| + | } |
| + | {CODE} |