Mercurial > epgrec.yaz
view storeProgram.inc.php @ 169:e379552d084c
fix: recorder.php:子プロセスを再帰的に停止させるよう変更
author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
---|---|
date | Sun, 18 Apr 2010 18:06:39 +0900 |
parents | b3095425e613 |
children |
line wrap: on
line source
<?php include_once( INSTALL_PATH . "/reclib.php" ); function garbageClean() { // 筝荀違 // 8ヤ札筝違羔 $arr = array(); $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); foreach( $arr as $val ) $val->delete(); // 8ヤ札筝若帥井 $arr = array(); $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 ) "); foreach( $arr as $val ) $val->delete(); // 10ヤ札筝違羔 $arr = array(); $arr = DBRecord::createRecords( LOG_TBL, "WHERE logtime < subdate( now(), 10 )" ); foreach( $arr as $val ) $val->delete(); } function doKeywordReservation() { // 若若牙私膣 $arr = array(); $arr = Keyword::createKeywords(); foreach( $arr as $val ) { try { $val->reservation(); } catch( Exception $e ) { // ∴ } } } function storeProgram( $type, $xmlfile ) { global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; global $settings; // c潟<ゃ羣 $map = array(); if( $type == "BS" ) $map = $BS_CHANNEL_MAP; else if( $type == "GR") $map = $GR_CHANNEL_MAP; else if( $type == "CS") $map = $CS_CHANNEL_MAP; // XML parse $xml = @simplexml_load_file( $xmlfile ); if( $xml === false ) { reclog( "getepg:: 罩e幻".$xmlfile."篏c罔≧(冗絽с馹障)", EPGREC_WARN ); return; // XML茯水篏 } // channel遵 foreach( $xml->channel as $ch ) { $disc = $ch['id']; try { // c潟若帥「 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); if( $num == 0 ) { if( array_key_exists( "$disc", $map ) ) { // c潟若帥域鋎 $rec = new DBRecord( CHANNEL_TBL ); $rec->type = $type; $rec->channel = $map["$disc"]; $rec->channel_disc = $disc; $rec->name = $ch->{'display-name'}; } } else { // 絖翫c潟贋違 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc ); $rec->name = $ch->{'display-name'}; } } catch( Exception $e ) { reclog( "getepg::DB・膓障c潟若吾莨若帥紊掩", EPGREC_ERROR ); } } // channel 腟篋 // programme 緇 foreach( $xml->programme as $program ) { $channel_rec = null; $channel_disc = $program['channel']; if( ! array_key_exists( "$channel_disc", $map ) ) continue; $channel = $map["$channel_disc"]; try { $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" ); } catch( Exception $e ) { reclog( "getepg::c潟潟若 $channel_disc 肴с", EPGREC_ERROR ); } if( $channel_rec == null ) continue; // 緇莎激 if( $channel_rec->skip == 1 ) continue; // 篆<c潟 $starttime = str_replace(" +0900", '', $program['start'] ); $endtime = str_replace( " +0900", '', $program['stop'] ); $title = $program->title; $desc = $program->desc; $cat_ja = ""; $cat_en = ""; foreach( $program->category as $cat ) { if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat; if( $cat['lang'] == "en" ) $cat_en = $cat; } $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."'" ); 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:: 眼若≪祉鴻紊掩罔≧", EPGREC_ERROR ); reclog("getepg:: ".$e->getMessage()."" ,EPGREC_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 ) { // 牙私膣腟丈紊眼cゃ try { $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); // с紮牙祉∴ if( time() > (toTimestamp($reserve->starttime) - PADDING_TIME - $settings->former_time) ) { reclog( "getepg::牙ID".$reserve->id.":".$reserve->type.$reserve->channel.$reserve->title."牙脂紮緇紊眼榊醇с", EPGREC_WARN ); } else { if( $reserve->autorec ) { reclog( "getepg::牙ID".$reserve->id.":".$reserve->type.$reserve->channel.$reserve->title."紊眼醇с篋膣羔" ); Reservation::cancel( $reserve->id ); } } } catch( Exception $e ) { // ∴ } // 腟 reclog( "getepg::冗茲榊腟ID".$rec->id." ".$rec->type.$rec->channel.$rec->title."" ); $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 ); // dirty腴c憜緇牙私膣с if( ($reserve->dirty == 0) && (toTimestamp($reserve->starttime) > time()) ) { $reserve->title = $title; $reserve->description = $desc; reclog( "getepg:: 篋膣ID".$reserve->id."EPG宴贋違" ); } } catch( Exception $e ) { // ∴ } } } catch(Exception $e) { reclog( "getepg:: 違若馹罔≧", EPGREC_ERROR ); reclog( "getepg:: ".$e->getMessage()."" , EPGREC_ERROR); exit( $e->getMessage() ); } } // Programme緇絎篋 } ?>