Changeset 3

Show
Ignore:
Timestamp:
08/02/06 05:12:04
Author:
svn
Message:

fix tag editing, add more error handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phptagengine.class.inc.php

    r2 r3  
    333333         */ 
    334334        function save_tags($item, $tags, $type = null, $user = null) { 
     335                $type = $this->default_value('type', $type); 
     336                $user = $this->default_value('user', $user); 
    335337                $old_tags = $this->get_tags($item, $type, $user); 
    336338                $new_tags = array(); 
     
    345347                                        if ($tag != '') { 
    346348                                                if ($this->add_tag($user, $item, $tag, $type)) { 
    347                                                         $new_tags[] = $tag
     349                                                        $new_tags[] = $this->normalize($tag)
    348350                                                } 
    349351                                                else { 
     
    474476                } 
    475477                $tag_id = $this->get_tag_id($tag); 
     478                if ($tag_id == false) { 
     479                        return false; 
     480                } 
    476481                $result = $this->db->Execute(" 
    477482                        DELETE 
     
    518523                        if (!$result) { 
    519524                                return false; 
     525                        } 
     526// check for dupes 
     527                        $result = $this->db->Execute(" 
     528                                SELECT * 
     529                                FROM $this->table_tags 
     530                                WHERE tag = '$new_tag_id' 
     531                        ") or die($this->db->ErrorMsg().' in '.__FILE__); 
     532                        if (!$result) { 
     533                                return false; 
     534                        } 
     535                        else if ($result->RowCount() > 0) { 
     536                                $tags = array(); 
     537                                $ids_to_delete = array(); 
     538                                while ($data = $result->FetchNextObject()) { 
     539                                        $key = $data->TAG.$data->ITEM.$data->TYPE.$data->USER; 
     540                                        if (!in_array($key, $tags)) { 
     541                                                $tags[] = $key; 
     542                                        } 
     543                                        else { 
     544                                                $ids_to_delete[] = $data->ID; 
     545                                        } 
     546                                } 
     547// remove dupes 
     548                                if (count($ids_to_delete) > 0) { 
     549                                        $result = $this->db->Execute(" 
     550                                                DELETE 
     551                                                FROM $this->table_tags 
     552                                                WHERE id IN (".implode(',', $ids_to_delete).") 
     553                                        ") or die($this->db->ErrorMsg().' in '.__FILE__); 
     554                                        if (!$result) { 
     555                                                return false; 
     556                                        } 
     557                                } 
    520558                        } 
    521559                }