Forums: Open Discussion (Thread #30448)

履歴保存時のfor_search項目が無いSQLエラーの件 (2011-09-23 19:39 by domifara #59728)

xoops_trust_path/pico/include/transact_functions.phpの
line 736で
変更前
[code]
// store a content into history table (before delete or update)
function pico_transact_backupcontent( $mydirname , $content_id , $forced = false )
{
global $xoopsUser , $xoopsModuleConfig ;

$db =& Database::getInstance() ;

$histories_per_content = intval( @$xoopsModuleConfig['histories_per_content'] ) ;
$minlifetime_per_history = intval( @$xoopsModuleConfig['minlifetime_per_history'] ) ;

// fetch the latest history first
list( $last_ch_id ) = $db->fetchRow( $db->query( "SELECT MAX(content_history_id) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_id=".intval($content_id) ) ) ;
ここ→ list( $last_ch_modified , $last_ch_4search ) = $db->fetchRow( $db->query( "SELECT `modified_time`,MD5(`for_search`) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_history_id=".intval($last_ch_id) ) ) ;
list( $current_4search ) = $db->fetchRow( $db->query( "SELECT MD5(`for_search`) FROM ".$db->prefix($mydirname."_contents")." WHERE content_id=".intval($content_id) ) ) ;

// compare for_search fileld (it is not saved if identical)
判定 if( ! $forced && $current_4search == $last_ch_4search ) return ;

// min life time of each history
if( $minlifetime_per_history > 0 && $last_ch_modified > time() - $minlifetime_per_history ) return ;

// max histories
if( $histories_per_content > 0 ) {
do {
list( $ch_count , $min_ch_id ) = $db->fetchRow( $db->query( "SELECT COUNT(*),MIN(content_history_id) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_id=".intval($content_id) ) ) ;
if( $ch_count >= $histories_per_content ) {
$db->queryF( "DELETE FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_history_id=".intval($min_ch_id) ) ;
}
} while( $ch_count >= $histories_per_content ) ;
}

$uid = is_object( $xoopsUser ) ? $xoopsUser->getVar('uid') : 0 ;
if( ! $db->queryF( "INSERT INTO ".$db->prefix($mydirname."_content_histories")." (content_id,vpath,cat_id,created_time,modified_time,poster_uid,poster_ip,modifier_uid,modifier_ip,subject,htmlheader,body,filters,tags,extra_fields) SELECT content_id,vpath,cat_id,created_time,modified_time,poster_uid,poster_ip,modifier_uid,modifier_ip,subject,htmlheader,body,filters,tags,extra_fields FROM ".$db->prefix($mydirname."_contents")." WHERE content_id=".intval($content_id) ) ) die( _MD_PICO_ERR_SQL.__LINE__ ) ;
}
[/code]
_content_historiesテーブルにfor_searchという項目がないのに、MD5(`for_search`)と項目参照してSQLエラーとなっています。
本文の内容がかわったかどうかの判定に使うつもりのようにみえるので、
for_searchのかわりにbody項目をかわりにしてみようと思います。
変更後
[code]
// store a content into history table (before delete or update)
function pico_transact_backupcontent( $mydirname , $content_id , $forced = false )
{
global $xoopsUser , $xoopsModuleConfig ;

$db =& Database::getInstance() ;

$histories_per_content = intval( @$xoopsModuleConfig['histories_per_content'] ) ;
$minlifetime_per_history = intval( @$xoopsModuleConfig['minlifetime_per_history'] ) ;

// fetch the latest history first
list( $last_ch_id ) = $db->fetchRow( $db->query( "SELECT MAX(content_history_id) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_id=".intval($content_id) ) ) ;
//FIX by domifara 2011.09.21
// list( $last_ch_modified , $last_ch_4search ) = $db->fetchRow( $db->query( "SELECT `modified_time`,MD5(`for_search`) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_history_id=".intval($last_ch_id) ) ) ;
// list( $current_4search ) = $db->fetchRow( $db->query( "SELECT MD5(`for_search`) FROM ".$db->prefix($mydirname."_contents")." WHERE content_id=".intval($content_id) ) ) ;
list( $last_ch_modified , $last_ch_4search ) = $db->fetchRow( $db->query( "SELECT `modified_time`,MD5(`body`) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_history_id=".intval($last_ch_id) ) ) ;
list( $current_4search ) = $db->fetchRow( $db->query( "SELECT MD5(`body`) FROM ".$db->prefix($mydirname."_contents")." WHERE content_id=".intval($content_id) ) ) ;

// compare for_search fileld (it is not saved if identical)
if( ! $forced && $current_4search == $last_ch_4search ) return ;

// min life time of each history
if( $minlifetime_per_history > 0 && $last_ch_modified > time() - $minlifetime_per_history ) return ;

// max histories
if( $histories_per_content > 0 ) {
do {
list( $ch_count , $min_ch_id ) = $db->fetchRow( $db->query( "SELECT COUNT(*),MIN(content_history_id) FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_id=".intval($content_id) ) ) ;
if( $ch_count >= $histories_per_content ) {
$db->queryF( "DELETE FROM ".$db->prefix($mydirname."_content_histories")." WHERE content_history_id=".intval($min_ch_id) ) ;
}
} while( $ch_count >= $histories_per_content ) ;
}

$uid = is_object( $xoopsUser ) ? $xoopsUser->getVar('uid') : 0 ;
if( ! $db->queryF( "INSERT INTO ".$db->prefix($mydirname."_content_histories")." (content_id,vpath,cat_id,created_time,modified_time,poster_uid,poster_ip,modifier_uid,modifier_ip,subject,htmlheader,body,filters,tags,extra_fields) SELECT content_id,vpath,cat_id,created_time,modified_time,poster_uid,poster_ip,modifier_uid,modifier_ip,subject,htmlheader,body,filters,tags,extra_fields FROM ".$db->prefix($mydirname."_contents")." WHERE content_id=".intval($content_id) ) ) die( _MD_PICO_ERR_SQL.__LINE__ ) ;
}
[/code]