comparison 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
comparison
equal deleted inserted replaced
141:d1681f891462 146:4afd353b4507
10 // 8日以上先のデータがあれば消す 10 // 8日以上先のデータがあれば消す
11 $arr = array(); 11 $arr = array();
12 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 ) "); 12 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 ) ");
13 foreach( $arr as $val ) $val->delete(); 13 foreach( $arr as $val ) $val->delete();
14 14
15 // 8日以上前のログを消す 15 // 10日以上前のログを消す
16 $arr = array(); 16 $arr = array();
17 $arr = DBRecord::createRecords( LOG_TBL, "WHERE endtime < subdate( now(), 8 )" ); 17 $arr = DBRecord::createRecords( LOG_TBL, "WHERE logtime < subdate( now(), 10 )" );
18 foreach( $arr as $val ) $val->delete(); 18 foreach( $arr as $val ) $val->delete();
19 } 19 }
20 20
21 function doKeywordReservation() { 21 function doKeywordReservation() {
22 // キーワード自動録画予約 22 // キーワード自動録画予約
23 $arr = array(); 23 $arr = array();
24 $arr = Keyword::createKeywords(); 24 $arr = Keyword::createKeywords();
25 foreach( $arr as $val ) { 25 foreach( $arr as $val ) {
26 try { 26 try {
27 $val->reservation(); 27 $val->reservation();
28 reclog( "getepg::キーワードID".$val->id."を予約"); 28 // reclog( "getepg::キーワードID".$val->id."の録画が予約された");
29 } 29 }
30 catch( Exception $e ) { 30 catch( Exception $e ) {
31 // 無視 31 // 無視
32 } 32 }
33 } 33 }
43 else if( $type == "CS") $map = $CS_CHANNEL_MAP; 43 else if( $type == "CS") $map = $CS_CHANNEL_MAP;
44 44
45 // XML parse 45 // XML parse
46 $xml = @simplexml_load_file( $xmlfile ); 46 $xml = @simplexml_load_file( $xmlfile );
47 if( $xml === false ) { 47 if( $xml === false ) {
48 reclog( "getepg::".$xmlfile."が作成されなかった模様", E_ERROR ); 48 reclog( "getepg:: 正常な".$xmlfile."が作成されなかった模様(放送間帯でないなら問題ありません)" );
49 return; // XMLが読み取れないなら何もしない 49 return; // XMLが読み取れないなら何もしない
50 } 50 }
51 // channel抽出 51 // channel抽出
52 foreach( $xml->channel as $ch ) { 52 foreach( $xml->channel as $ch ) {
53 $disc = $ch['id']; 53 $disc = $ch['id'];
87 87
88 try { 88 try {
89 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" ); 89 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" );
90 } 90 }
91 catch( Exception $e ) { 91 catch( Exception $e ) {
92 reclog( "getepg::チャンネルレコードが発見できない", E_ERROR ); 92 reclog( "getepg::チャンネルレコード $channel_disc が発見できない", E_ERROR );
93 } 93 }
94 if( $channel_rec == null ) continue; // あり得ないことが起きた 94 if( $channel_rec == null ) continue; // あり得ないことが起きた
95 if( $channel_rec->skip == 1 ) continue; // 受信しないチャンネル 95 if( $channel_rec->skip == 1 ) continue; // 受信しないチャンネル
96 96
97 $starttime = str_replace(" +0900", '', $program['start'] ); 97 $starttime = str_replace(" +0900", '', $program['start'] );
104 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat; 104 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
105 if( $cat['lang'] == "en" ) $cat_en = $cat; 105 if( $cat['lang'] == "en" ) $cat_en = $cat;
106 } 106 }
107 $program_disc = md5( $channel_disc . $starttime . $endtime ); 107 $program_disc = md5( $channel_disc . $starttime . $endtime );
108 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); 108 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
109 try { 109
110 // カテゴリを処理する 110 // カテゴリ登録
111 $category_disc = md5( $cat_ja . $cat_en ); 111
112 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); 112 $cat_rec = null;
113 $cat_rec = null; 113 try {
114 if( $num == 0 ) { 114 // カテゴリを処理する
115 // 新規カテゴリの追加 115 $category_disc = md5( $cat_ja . $cat_en );
116 $cat_rec = new DBRecord( CATEGORY_TBL ); 116 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
117 $cat_rec->name_jp = $cat_ja; 117 if( $num == 0 ) {
118 $cat_rec->name_en = $cat_en; 118 // 新規カテゴリの追加
119 $cat_rec->category_disc = $category_disc; 119 $cat_rec = new DBRecord( CATEGORY_TBL );
120 } 120 $cat_rec->name_jp = $cat_ja;
121 else 121 $cat_rec->name_en = $cat_en;
122 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); 122 $cat_rec->category_disc = $category_disc;
123 // 123 reclog("getepg:: 新規カテゴリ".$cat_ja."を追加" );
124 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); 124 }
125 if( $num == 0 ) { 125 else
126 // 新規番組 126 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
127 // 重複チェック 同時間帯にある番組 127 }
128 $options = "WHERE channel_disc = '".$channel_disc."' ". 128 catch( Exception $e ) {
129 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; 129 reclog("getepg:: カテゴリテーブルのアクセスに失敗した模様", E_ERROR );
130 $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); 130 reclog("getepg:: ".$e->getMessage()."" ,E_ERROR );
131 if( $battings > 0 ) { 131 exit( $e->getMessage() );
132 // 重複発生=おそらく放映時間の変更 132 }
133 $records = DBRecord::createRecords(PROGRAM_TBL, $options ); 133
134 foreach( $records as $rec ) { 134 // プログラム登録
135 // 自動録画予約された番組は放映時間変更と同時にいったん削除する 135
136 try { 136 try {
137 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); 137 //
138 if( $reserve->autorec ) { 138 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
139 reclog( "getepg::録画ID".$reserve->id."は時間変更の可能性あり予約を取り消し"); 139 if( $num == 0 ) {
140 Reservation::cancel( $reserve->id ); 140 // 新規番組
141 // 重複チェック 同時間帯にある番組
142 $options = "WHERE channel_disc = '".$channel_disc."' ".
143 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
144 $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
145 if( $battings > 0 ) {
146 // 重複発生=おそらく放映時間の変更
147 $records = DBRecord::createRecords(PROGRAM_TBL, $options);
148 foreach( $records as $rec ) {
149 // 自動録画予約された番組は放映時間変更と同時にいったん削除する
150 try {
151 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
152 if( $reserve->autorec ) {
153 reclog( "getepg::録画ID".$reserve->id.":".$reserve->type.$reserve->channel.$reserve->title."は時間変更の可能性があり予約取り消し" );
154 Reservation::cancel( $reserve->id );
155 }
141 } 156 }
157 catch( Exception $e ) {
158 // 無視
159 }
160 // 番組削除
161 reclog( "getepg::放送時間重複が発生した番組ID".$rec->id." ".$rec->type.$rec->channel.$rec->title."を削除" );
162 $rec->delete();
142 } 163 }
143 catch( Exception $e ) { 164 }
144 // 無視 165 // //
166 $rec = new DBRecord( PROGRAM_TBL );
167 $rec->channel_disc = $channel_disc;
168 $rec->channel_id = $channel_rec->id;
169 $rec->type = $type;
170 $rec->channel = $channel_rec->channel;
171 $rec->title = $title;
172 $rec->description = $desc;
173 $rec->category_id = $cat_rec->id;
174 $rec->starttime = $starttime;
175 $rec->endtime = $endtime;
176 $rec->program_disc = $program_disc;
177 }
178 else {
179 // 番組内容更新
180 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
181 $rec->title = $title;
182 $rec->description = $desc;
183 $rec->category_id = $cat_rec->id;
184
185 try {
186 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id );
187 if( $reserve->dirty == 0 ) {
188 $reserve->title = $title;
189 $reserve->description = $desc;
190 reclog( "getepg:: 予約ID".$reserve->id."のEPG情報が更新された" );
145 } 191 }
146 // 番組削除
147 reclog( "getepg::放送時間重複が発生した番組ID".$rec->id."を削除" );
148 $rec->delete();
149 } 192 }
150 } 193 catch( Exception $e ) {
151 // // 194 // 無視する
152 $rec = new DBRecord( PROGRAM_TBL ); 195 }
153 $rec->channel_disc = $channel_disc; 196 }
154 $rec->channel_id = $channel_rec->id;
155 $rec->type = $type;
156 $rec->channel = $channel_rec->channel;
157 $rec->title = $title;
158 $rec->description = $desc;
159 $rec->category_id = $cat_rec->id;
160 $rec->starttime = $starttime;
161 $rec->endtime = $endtime;
162 $rec->program_disc = $program_disc;
163 }
164 else {
165 // 番組内容更新
166 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
167 $rec->title = $title;
168 $rec->description = $desc;
169 $rec->category_id = $cat_rec->id;
170 }
171 } 197 }
172 catch(Exception $e) { 198 catch(Exception $e) {
173 reclog( "getepg::DBの入出力に問題が生じた模様", E_ERROR ); 199 reclog( "getepg:: プログラムテーブルに問題が生じた模様", E_ERROR );
200 reclog( "getepg:: ".$e->getMessage()."" , E_ERROR);
174 exit( $e->getMessage() ); 201 exit( $e->getMessage() );
175 } 202 }
176 } 203 }
177 // Programme取得完了 204 // Programme取得完了
178 } 205 }