Skip to content

Commit

Permalink
동시성 문제로 wr_seo_title 값이 중복되는 문제 수정 #293
Browse files Browse the repository at this point in the history
  • Loading branch information
thisgun committed Dec 18, 2023
1 parent 4f2f725 commit a061d6c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 5 deletions.
3 changes: 3 additions & 0 deletions adm/contentform.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
if (!$co['co_id']) {
alert('등록된 자료가 없습니다.');
}

if (function_exists('check_case_exist_title')) check_case_exist_title($co, G5_CONTENT_DIR, false);

} else {
$html_title .= ' 입력';
$co = array(
Expand Down
2 changes: 2 additions & 0 deletions adm/shop_admin/itemform.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@

if(!$it)
alert('상품정보가 존재하지 않습니다.');

if (function_exists('check_case_exist_title')) check_case_exist_title($it, G5_SHOP_DIR, false);

if (! (isset($ca_id) && $ca_id))
$ca_id = $it['ca_id'];
Expand Down
2 changes: 2 additions & 0 deletions bbs/view.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

if (function_exists('check_case_exist_title')) check_case_exist_title($write, G5_BBS_DIR, true);

// 게시판에서 두단어 이상 검색 후 검색된 게시물에 코멘트를 남기면 나오던 오류 수정
$sop = strtolower($sop);
if ($sop != 'and' && $sop != 'or')
Expand Down
6 changes: 5 additions & 1 deletion lib/get_data.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ function get_content_by_field($write_table, $type='bbs', $where_field='', $where
{
global $g5, $g5_object;

$order_key = 'wr_id';

if( $type === 'content' ){
$check_array = array('co_id', 'co_html', 'co_subject', 'co_content', 'co_seo_title', 'co_mobile_content', 'co_skin', 'co_mobile_skin', 'co_tag_filter_use', 'co_hit', 'co_include_head', 'co_include_tail');

$order_key = 'co_id';
} else {
$check_array = array('wr_id', 'wr_num', 'wr_reply', 'wr_parent', 'wr_is_comment', 'ca_name', 'wr_option', 'wr_subject', 'wr_content', 'wr_seo_title', 'wr_link1', 'wr_link2', 'wr_hit', 'wr_good', 'wr_nogood', 'mb_id', 'wr_name', 'wr_email', 'wr_homepage', 'wr_datetime', 'wr_ip', 'wr_1', 'wr_2', 'wr_3', 'wr_4', 'wr_5', 'wr_6', 'wr_7', 'wr_8', 'wr_9', 'wr_10');
}
Expand All @@ -162,7 +166,7 @@ function get_content_by_field($write_table, $type='bbs', $where_field='', $where
return $cache[$key];
}

$sql = " select * from {$write_table} where $where_field = '".sql_real_escape_string($where_value)."' ";
$sql = " select * from {$write_table} where $where_field = '".sql_real_escape_string($where_value)."' order by $order_key desc limit 1 ";

$cache[$key] = sql_fetch($sql);

Expand Down
4 changes: 2 additions & 2 deletions lib/shop.data.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ function get_shop_item_with_category($it_id, $seo_title='', $add_query=''){
global $g5, $default;

if( $seo_title ){
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_seo_title = '".sql_real_escape_string(generate_seo_title($seo_title))."' and a.ca_id = b.ca_id $add_query";
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_seo_title = '".sql_real_escape_string(generate_seo_title($seo_title))."' and a.ca_id = b.ca_id $add_query order by it_id desc limit 1";
} else {
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_id = '$it_id' and a.ca_id = b.ca_id $add_query";
$sql = " select a.*, b.ca_name, b.ca_use from {$g5['g5_shop_item_table']} a, {$g5['g5_shop_category_table']} b where a.it_id = '$it_id' and a.ca_id = b.ca_id $add_query order by it_id desc limit 1";
}

$item = sql_fetch($sql);
Expand Down
55 changes: 53 additions & 2 deletions lib/uri.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,69 @@ function exist_seo_url($type, $seo_title, $write_table, $sql_id=0){
return '';
}

function check_case_exist_title($data, $case=G5_BBS_DIR, $is_redirect=false) {
global $config, $g5, $board;

if ((int) $config['cf_bbs_rewrite'] !== 2) {
return;
}

$seo_title = '';
$redirect_url = '';

if ($case == G5_BBS_DIR && isset($data['wr_seo_title'])) {
$db_table = $g5['write_prefix'].$board['bo_table'];

if (exist_seo_url($case, $data['wr_seo_title'], $db_table, $data['wr_id'])) {
$seo_title = $data['wr_seo_title'].'-'.$data['wr_id'];
$sql = " update `{$db_table}` set wr_seo_title = '".sql_real_escape_string($seo_title)."' where wr_id = '{$data['wr_id']}' ";
sql_query($sql, false);

get_write($db_table, $data['wr_id'], false);
$redirect_url = get_pretty_url($board['bo_table'], $data['wr_id']);
}
} else if ($case == G5_CONTENT_DIR && isset($data['co_seo_title'])) {
$db_table = $g5['content_table'];

if (exist_seo_url($case, $data['co_seo_title'], $db_table, $data['co_id'])) {
$seo_title = $data['co_seo_title'].'-'.substr(get_random_token_string(4), 4);
$sql = " update `{$db_table}` set co_seo_title = '".sql_real_escape_string($seo_title)."' where co_id = '{$data['co_id']}' ";
sql_query($sql, false);

get_content_db($data['co_id'], false);
g5_delete_cache_by_prefix('content-' . $data['co_id'] . '-');
$redirect_url = get_pretty_url($case, $data['co_id']);
}
} else if (defined('G5_SHOP_DIR') && $case == G5_SHOP_DIR && isset($data['it_seo_title'])) {
$db_table = $g5['g5_shop_item_table'];

if (shop_exist_check_seo_title($data['it_seo_title'], $case, $db_table, $data['it_id'])) {
$seo_title = $data['it_seo_title'].'-'.substr(get_random_token_string(4), 4);
$sql = " update `{$db_table}` set it_seo_title = '".sql_real_escape_string($seo_title)."' where it_id = '{$data['it_id']}' ";
sql_query($sql, false);

get_shop_item($data['it_id'], false);
$redirect_url = get_pretty_url($case, $data['it_id']);
}
}

if ($is_redirect && $seo_title && $redirect_url) {
goto_url($redirect_url);
}
}

function exist_seo_title_recursive($type, $seo_title, $write_table, $sql_id=0){
static $count = 0;

$seo_title_add = ($count > 0) ? utf8_strcut($seo_title, 200 - ($count+1), '')."-$count" : $seo_title;
$seo_title_add = ($count > 0) ? utf8_strcut($seo_title, 100000 - ($count+1), '')."-$count" : $seo_title;

if( ! exist_seo_url($type, $seo_title_add, $write_table, $sql_id) ){
return $seo_title_add;
}

$count++;

if( $count > 198 ){
if( $count > 99998 ){
return $seo_title_add;
}

Expand Down
2 changes: 2 additions & 0 deletions mobile/shop/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
shop_seo_title_update($row['it_id']);
}

if (function_exists('check_case_exist_title')) check_case_exist_title($it, G5_SHOP_DIR, true);

if (!($it['ca_use'] && $it['it_use'])) {
if (!$is_admin)
alert('판매가능한 상품이 아닙니다.');
Expand Down
2 changes: 2 additions & 0 deletions shop/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
shop_seo_title_update($row['it_id']);
}

if (function_exists('check_case_exist_title')) check_case_exist_title($it, G5_SHOP_DIR, true);

if (!($it['ca_use'] && $it['it_use'])) {
if (!$is_admin)
alert('현재 판매가능한 상품이 아닙니다.');
Expand Down

0 comments on commit a061d6c

Please sign in to comment.