Mercurial > epgrec.yaz
diff storeProgram.inc.php @ 146:4afd353b4507
merged with upstream
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Tue, 23 Mar 2010 02:37:31 +0900 |
parents | 2cb414518ccd |
children | 5b192e94f49d |
line wrap: on
line diff
--- a/storeProgram.inc.php Sun Mar 21 05:51:19 2010 +0900 +++ b/storeProgram.inc.php Tue Mar 23 02:37:31 2010 +0900 @@ -12,9 +12,9 @@ $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 ) "); foreach( $arr as $val ) $val->delete(); - // 8日以上前のログを消す + // 10日以上前のログを消す $arr = array(); - $arr = DBRecord::createRecords( LOG_TBL, "WHERE endtime < subdate( now(), 8 )" ); + $arr = DBRecord::createRecords( LOG_TBL, "WHERE logtime < subdate( now(), 10 )" ); foreach( $arr as $val ) $val->delete(); } @@ -25,7 +25,7 @@ foreach( $arr as $val ) { try { $val->reservation(); - reclog( "getepg::キーワードID".$val->id."を予約"); +// reclog( "getepg::キーワードID".$val->id."の録画が予約された"); } catch( Exception $e ) { // 無視 @@ -45,7 +45,7 @@ // XML parse $xml = @simplexml_load_file( $xmlfile ); if( $xml === false ) { - reclog( "getepg::".$xmlfile."が作成されなかった模様", E_ERROR ); + reclog( "getepg:: 正常な".$xmlfile."が作成されなかった模様(放送間帯でないなら問題ありません)" ); return; // XMLが読み取れないなら何もしない } // channel抽出 @@ -89,7 +89,7 @@ $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" ); } catch( Exception $e ) { - reclog( "getepg::チャンネルレコードが発見できない", E_ERROR ); + reclog( "getepg::チャンネルレコード $channel_disc が発見できない", E_ERROR ); } if( $channel_rec == null ) continue; // あり得ないことが起きた if( $channel_rec->skip == 1 ) continue; // 受信しないチャンネル @@ -106,71 +106,98 @@ } $program_disc = md5( $channel_disc . $starttime . $endtime ); // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); + + // カテゴリ登録 + + $cat_rec = null; try { - // カテゴリを処理する - $category_disc = md5( $cat_ja . $cat_en ); - $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); - $cat_rec = null; - if( $num == 0 ) { - // 新規カテゴリの追加 - $cat_rec = new DBRecord( CATEGORY_TBL ); - $cat_rec->name_jp = $cat_ja; - $cat_rec->name_en = $cat_en; - $cat_rec->category_disc = $category_disc; - } - else - $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); - // - $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); - if( $num == 0 ) { - // 新規番組 - // 重複チェック 同時間帯にある番組 - $options = "WHERE channel_disc = '".$channel_disc."' ". - "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; - $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); - if( $battings > 0 ) { - // 重複発生=おそらく放映時間の変更 - $records = DBRecord::createRecords(PROGRAM_TBL, $options ); - foreach( $records as $rec ) { - // 自動録画予約された番組は放映時間変更と同時にいったん削除する - try { - $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); - if( $reserve->autorec ) { - reclog( "getepg::録画ID".$reserve->id."は時間変更の可能性あり予約を取り消し"); - Reservation::cancel( $reserve->id ); + // カテゴリを処理する + $category_disc = md5( $cat_ja . $cat_en ); + $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); + if( $num == 0 ) { + // 新規カテゴリの追加 + $cat_rec = new DBRecord( CATEGORY_TBL ); + $cat_rec->name_jp = $cat_ja; + $cat_rec->name_en = $cat_en; + $cat_rec->category_disc = $category_disc; + reclog("getepg:: 新規カテゴリ".$cat_ja."を追加" ); + } + else + $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); + } + catch( Exception $e ) { + reclog("getepg:: カテゴリテーブルのアクセスに失敗した模様", E_ERROR ); + reclog("getepg:: ".$e->getMessage()."" ,E_ERROR ); + exit( $e->getMessage() ); + } + + // プログラム登録 + + try { + // + $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); + if( $num == 0 ) { + // 新規番組 + // 重複チェック 同時間帯にある番組 + $options = "WHERE channel_disc = '".$channel_disc."' ". + "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; + $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); + if( $battings > 0 ) { + // 重複発生=おそらく放映時間の変更 + $records = DBRecord::createRecords(PROGRAM_TBL, $options); + foreach( $records as $rec ) { + // 自動録画予約された番組は放映時間変更と同時にいったん削除する + try { + $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); + if( $reserve->autorec ) { + reclog( "getepg::録画ID".$reserve->id.":".$reserve->type.$reserve->channel.$reserve->title."は時間変更の可能性があり予約取り消し" ); + Reservation::cancel( $reserve->id ); + } } - } - catch( Exception $e ) { - // 無視 + catch( Exception $e ) { + // 無視 + } + // 番組削除 + reclog( "getepg::放送時間重複が発生した番組ID".$rec->id." ".$rec->type.$rec->channel.$rec->title."を削除" ); + $rec->delete(); } - // 番組削除 - reclog( "getepg::放送時間重複が発生した番組ID".$rec->id."を削除" ); - $rec->delete(); + } + // // + $rec = new DBRecord( PROGRAM_TBL ); + $rec->channel_disc = $channel_disc; + $rec->channel_id = $channel_rec->id; + $rec->type = $type; + $rec->channel = $channel_rec->channel; + $rec->title = $title; + $rec->description = $desc; + $rec->category_id = $cat_rec->id; + $rec->starttime = $starttime; + $rec->endtime = $endtime; + $rec->program_disc = $program_disc; + } + else { + // 番組内容更新 + $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc ); + $rec->title = $title; + $rec->description = $desc; + $rec->category_id = $cat_rec->id; + + try { + $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); + if( $reserve->dirty == 0 ) { + $reserve->title = $title; + $reserve->description = $desc; + reclog( "getepg:: 予約ID".$reserve->id."のEPG情報が更新された" ); + } + } + catch( Exception $e ) { + // 無視する } } - // // - $rec = new DBRecord( PROGRAM_TBL ); - $rec->channel_disc = $channel_disc; - $rec->channel_id = $channel_rec->id; - $rec->type = $type; - $rec->channel = $channel_rec->channel; - $rec->title = $title; - $rec->description = $desc; - $rec->category_id = $cat_rec->id; - $rec->starttime = $starttime; - $rec->endtime = $endtime; - $rec->program_disc = $program_disc; - } - else { - // 番組内容更新 - $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc ); - $rec->title = $title; - $rec->description = $desc; - $rec->category_id = $cat_rec->id; - } } catch(Exception $e) { - reclog( "getepg::DBの入出力に問題が生じた模様", E_ERROR ); + reclog( "getepg:: プログラムテーブルに問題が生じた模様", E_ERROR ); + reclog( "getepg:: ".$e->getMessage()."" , E_ERROR); exit( $e->getMessage() ); } }