[텍스트큐브] 보람말 이름을 바꾸는 기능이 보람말을 없애는 벌레 잡기

텍스트큐브 태그 관리

  텍스트큐브에는 글에 들어간 보람말(태그)을 바꾸는 기능이 있다. (관리 화면(센터) - 글 - 태그 관리)

  그런데 '태그 이름 변경'에서 보람말 이름을 바꾸지 않거나 영문 대문자/소문자만 바꾼 채로 '변경' 단추를 누르면 그 보람말이 사라지는 벌레가 있다.

  보람말의 이름을 바꾸는 renameTag 함수는 텍스트큐브 1.10.10을 기준으로 /library/model/blog.tag.php의 맨 아래쪽에 있다.주1

function renameTag($blogid, $id, $name) {
// 1. If tag with new name already exists, skip the tag creation process.
// 2. If tag with new name does not exist in this service, create new tag.
// 3. Modify the tag relation information
// 4. If older tag is not used anymore, drop the tag.
$oldTagId = $id;
$newTagId = addTag($blogid, $name);
$query = DBModel::getInstance();
$query->reset("TagRelations");
$query->setAttribute('tag', $newTagId);
$query->setQualifier('blogid', 'equals', $blogid);
$query->setQualifier('tag', 'equals', $oldTagId);
$query->update();
deleteTagById($blogid, $oldTagId);
return $newTagId;
}

  이 함수에 아래처럼 내용을 끼워 넣어 준다.

function renameTag($blogid, $id, $name) {
// 1. If tag with new name already exists, skip the tag creation process.
// 2. If tag with new name does not exist in this service, create new tag.
// 3. Modify the tag relation information
// 4. If older tag is not used anymore, drop the tag.
$oldTagName = getTagById($blogid, $id);
if(!strcmp($name, $oldTagName)) return $id;
if(!strcasecmp($name, $oldTagName)) {
$query = DBModel::getInstance();
$query->reset("Tags");
$query->setAttribute('name', $name);
$query->setQualifier('id', 'equals', $id);
$query->update();
return $id;
}
$oldTagId = $id;
$newTagId = addTag($blogid, $name);
$query = DBModel::getInstance();
$query->reset("TagRelations");
$query->setAttribute('tag', $newTagId);
$query->setQualifier('blogid', 'equals', $blogid);
$query->setQualifier('tag', 'equals', $oldTagId);
$query->update();
deleteTagById($blogid, $oldTagId);
return $newTagId;
}

  이렇게 하면 '변경' 단추를 누른 뒤에 보람말이 사라지는 일은 생기지 않는다.

  똑같은 보람말일 때에는 보람말 정보를 아예 건드리지 않고, 영문 대 · 소문자만 바꾼 경우에는 보람말 이름만 바꾸고 본래 있던 보람말 아이디(id) 정보는 건드리지 않는다. 영문 대 · 소문자를 같게 따지더라도 보람말 이름을 다르게 바꾸는 때에는 예전처럼 보람말을 아이디와 이름을 새로 등록한다.

〈주석〉
  1. 텍스트큐브 2.0은 /library/model/blog/tag.php back
글 걸기 주소 : 이 글에는 글을 걸 수 없습니다.

덧글을 달아 주세요