4 $type = $argv[1]; // BS CS GR
5 $file = $argv[2]; // XMLファイル
9 function handler( $signo = 0 ) {
11 if( file_exists( $file ) ) {
19 if( pcntl_fork() != 0 )
22 if( pcntl_fork() != 0 )
24 pcntl_signal(SIGTERM, "handler");
31 pcntl_setpriority(20);
33 include_once('config.php');
34 include_once( INSTALL_PATH . '/DBRecord.class.php' );
35 include_once( INSTALL_PATH . '/Reservation.class.php' );
36 include_once( INSTALL_PATH . '/Keyword.class.php' );
37 include_once( INSTALL_PATH . '/Settings.class.php' );
39 $settings = Settings::factory();
41 if( file_exists( $file ) ) {
42 storeProgram( $type, $file );
49 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
50 foreach( $arr as $val ) $val->delete();
54 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" );
55 foreach( $arr as $val ) $val->delete();
59 $arr = Keyword::createKeywords();
60 foreach( $arr as $val ) {
64 catch( Exception $e ) {
70 function storeProgram( $type, $xmlfile ) {
71 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP;
74 if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
75 else if( $type == "GR") $map = $GR_CHANNEL_MAP;
76 else if( $type == "CS") $map = $CS_CHANNEL_MAP;
79 $xml = @simplexml_load_file( $xmlfile );
80 if( $xml === false ) {
81 return; // XMLが読み取れないなら何もしない
84 foreach( $xml->channel as $ch ) {
88 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" );
90 if( array_key_exists( "$disc", $map ) ) {
92 $rec = new DBRecord( CHANNEL_TBL );
94 $rec->channel = $map["$disc"];
95 $rec->channel_disc = $disc;
96 $rec->name = $ch->{'display-name'};
100 // 存在した場合も、とりあえずチャンネル名は更新する
101 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc );
102 $rec->name = $ch->{'display-name'};
105 catch( Exception $e ) {
113 foreach( $xml->programme as $program ) {
114 $channel_disc = $program['channel'];
115 if( ! array_key_exists( "$channel_disc", $map ) ) continue;
117 $channel = $map["$channel_disc"];
118 $starttime = str_replace(" +0900", '', $program['start'] );
119 $endtime = str_replace( " +0900", '', $program['stop'] );
120 $title = $program->title;
121 $desc = $program->desc;
124 foreach( $program->category as $cat ) {
125 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
126 if( $cat['lang'] == "en" ) $cat_en = $cat;
128 $program_disc = md5( $channel_disc . $starttime . $endtime );
129 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
132 $category_disc = md5( $cat_ja . $cat_en );
133 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
137 $cat_rec = new DBRecord( CATEGORY_TBL );
138 $cat_rec->name_jp = $cat_ja;
139 $cat_rec->name_en = $cat_en;
140 $cat_rec->category_disc = $category_disc;
143 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
145 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc );
146 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
150 $options = "WHERE channel_disc = '".$channel_disc."' ".
151 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
152 $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
153 if( $battings > 0 ) {
155 $records = DBRecord::createRecords(PROGRAM_TBL, $options );
156 foreach( $records as $rec ) {
157 // 自動録画予約された番組は放映時間変更と同時にいったん削除する
159 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
160 if( $reserve->autorec ) {
161 Reservation::cancel( $reserve->id );
164 catch( Exception $e ) {
172 $rec = new DBRecord( PROGRAM_TBL );
173 $rec->channel_disc = $channel_disc;
174 $rec->channel_id = $channel_rec->id;
176 $rec->channel = $channel_rec->channel;
177 $rec->title = $title;
178 $rec->description = $desc;
179 $rec->category_id = $cat_rec->id;
180 $rec->starttime = $starttime;
181 $rec->endtime = $endtime;
182 $rec->program_disc = $program_disc;
186 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
187 $rec->title = $title;
188 $rec->description = $desc;
189 $rec->category_id = $cat_rec->id;
192 catch(Exception $e) {
193 exit( $e->getMessage() );