# HG changeset patch # User Yoshiki Yazawa # Date 1270668140 -32400 # Node ID 3d4df1fe41667a95575c3885683e6ae1580c8714 # Parent 47a3acf19870b79e13f9c8a770174f48a50e4592# Parent 254d8a21bf3627ef39d369b89392985c7190ed9c merged with upstream diff -r 47a3acf19870 -r 3d4df1fe4166 Reservation.class.php --- a/Reservation.class.php Fri Apr 02 20:40:55 2010 +0900 +++ b/Reservation.class.php Thu Apr 08 04:22:20 2010 +0900 @@ -5,6 +5,11 @@ include_once( INSTALL_PATH . "/Settings.class.php" ); include_once( INSTALL_PATH . "/recLog.inc.php" ); +// 後方互換性 +if( !defined( "RECORDER_CMD" ) ) { + define( "RECORDER_CMD", INSTALL_PATH."/recorder.php" ); +} + // 予約クラス @@ -288,17 +293,13 @@ // ATで予約する $process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env ); if( is_resource( $process ) ) { - fwrite($pipes[0], $settings->sleep." ".$sleep_time."\n" ); - fwrite($pipes[0], DO_RECORD . "\n" ); - fwrite($pipes[0], COMPLETE_CMD." ".$rrec->id."\n" ); - if( $settings->use_thumbs == 1 ) { - fwrite($pipes[0], $gen_thumbnail."\n" ); - } + fwrite($pipes[0], RECORDER_CMD." ".$rrec->id."\n" ); fclose($pipes[0]); // 標準エラーを取る - $rstring = stream_get_contents( $pipes[2]); + $rstring = stream_get_contents($pipes[2]); fclose( $pipes[2] ); + fclose( $pipes[1] ); proc_close( $process ); } else { @@ -354,15 +355,57 @@ throw new Exception("IDの指定が無効です"); } if( ! $rec->complete ) { - // 未実行の予約である if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) { - reclog("Reservation::cancel 未実行の予約の取り消しが実行された", EPGREC_ERROR ); - throw new Exception("未実行の予約です"); + reclog("Reservation::cancel 実行中の予約ID".$rec->id."の取り消しが実行された" ); + + // recorderとの通信を試みる + $ipc_key = ftok( RECORDER_CMD, "R" ); + + /* php 5.3以降じゃないとmsg_queue_existsは使えない + if( ! msg_queue_exists( $ipc_key ) ) { + // メッセージキューがない + reclog( "Reservation::cancel 実行中と推測される予約".$rec->id."が実行されていない", EPGREC_ERROR ); + $rec->complete = 1; + throw new RecException( "Reserve:: 実行中と推測される予約が実行されていません。再度、削除を試みてください。", EPGREC_ERROR ); + } + else { + */ + $msgh_r = msg_get_queue( $ipc_key ); + $ipc_key = ftok( RECORDER_CMD, "W" ); + $msgh_w = msg_get_queue( $ipc_key ); + + // 終了を指示 + msg_send( $msgh_r, (int)$rec->id, "terminate" ); + sleep(1); + for( $i = 0; $i < 60; $i++ ) { + $r = msg_receive($msgh_w, (int)$rec->id , $msgtype, 1024, $message, TRUE, MSG_IPC_NOWAIT | MSG_NOERROR); + if( $r ) { + if( $message == "success" ) { + reclog( "Reserve:: 実行中の予約ID".$rec->id."の取り消しに成功した模様" ); + break; + } + else if( $message == "error" ){ + reclog( "Reserve:: 実行中の予約ID".$rec->id."の取り消しに失敗", EPGREC_ERROR ); + throw new RecException("実行中の予約取り消しに失敗しました。しばらく時間をおいてから再度、取り消してください", EPGREC_ERROR ); + } + // それ以外のメッセージは無視して待つ + } + sleep(1); + } + if( $i >= 60 ) throw new RecException("実行中の予約取り消しに失敗しました。しばらく時間をおいてから再度、取り消してください", EPGREC_ERROR ); +// } } - exec( $settings->atrm . " " . $rec->job ); - reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); + else { + // まだ実行されていない予約ならatを削除しとく + exec( $settings->atrm . " " . $rec->job ); + reclog("Reservation::cancel ジョブ番号".$rec->job."を削除"); + $rec->delete(); + } } - $rec->delete(); + else { + // 録画済み予約ならただ消す + $rec->delete(); + } } catch( Exception $e ) { reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", EPGREC_ERROR ); @@ -370,4 +413,4 @@ } } } -?> +?> \ No newline at end of file diff -r 47a3acf19870 -r 3d4df1fe4166 cancelReservation.php --- a/cancelReservation.php Fri Apr 02 20:40:55 2010 +0900 +++ b/cancelReservation.php Thu Apr 08 04:22:20 2010 +0900 @@ -8,6 +8,8 @@ $program_id = 0; $reserve_id = 0; $settings = Settings::factory(); +$rec = null; +$path = ""; if( isset($_GET['program_id'])) { $program_id = $_GET['program_id']; @@ -20,11 +22,7 @@ if( isset( $_GET['delete_file'] ) ) { if( $_GET['delete_file'] == 1 ) { - // ファイルを削除 - if( file_exists( INSTALL_PATH."/".$settings->spool."/".$rec->path ) ) { - @unlink(INSTALL_PATH."/".$settings->spool."/".$rec->path); - @unlink(INSTALL_PATH."/".$settings->thumbs."/".$rec->path.".jpg"); - } + $path = INSTALL_PATH."/".$settings->spool."/".$rec->path; } } } @@ -33,8 +31,6 @@ } } - - // 手動取り消しのときには、その番組を自動録画対象から外す if( $program_id ) { try { @@ -46,9 +42,20 @@ } } + + // 予約取り消し実行 try { Reservation::cancel( $reserve_id, $program_id ); + if( isset( $_GET['delete_file'] ) ) { + if( $_GET['delete_file'] == 1 ) { + // ファイルを削除 + if( file_exists( $path) ) { + @unlink($path); + @unlink($path.".jpg"); + } + } + } } catch( Exception $e ) { exit( "Error" . $e->getMessage() ); diff -r 47a3acf19870 -r 3d4df1fe4166 config.php.sample --- a/config.php.sample Fri Apr 02 20:40:55 2010 +0900 +++ b/config.php.sample Thu Apr 08 04:22:20 2010 +0900 @@ -75,6 +75,7 @@ define( "DO_RECORD", INSTALL_PATH . "/do-record.sh" ); // レコードスクリプト define( "COMPLETE_CMD", INSTALL_PATH . "/recomplete.php" ); // 録画終了コマンド define( "GEN_THUMBNAIL", INSTALL_PATH . "/gen-thumbnail.sh" ); // サムネール生成スクリプト +define( "RECORDER_CMD", INSTALL_PATH . "/recorder.php" ); // BS/CSでEPGを取得するチャンネル // 通常は変える必要はありません diff -r 47a3acf19870 -r 3d4df1fe4166 install/step1.php --- a/install/step1.php Fri Apr 02 20:40:55 2010 +0900 +++ b/install/step1.php Thu Apr 08 04:22:20 2010 +0900 @@ -45,7 +45,8 @@ $exec_files = array( DO_RECORD, - COMPLETE_CMD, +// COMPLETE_CMD, + RECORDER_CMD, INSTALL_PATH."/getepg.php", INSTALL_PATH."/storeProgram.php", $gen_thumbnail, diff -r 47a3acf19870 -r 3d4df1fe4166 recomplete.php diff -r 47a3acf19870 -r 3d4df1fe4166 recorder.php --- a/recorder.php Fri Apr 02 20:40:55 2010 +0900 +++ b/recorder.php Thu Apr 08 04:22:20 2010 +0900 @@ -14,6 +14,11 @@ define( "RECORDER_CMD", INSTALL_PATH . "/recorder.php" ); } +$settings = Settings::factory(); +$reserve_id = $argv[1]; +$msgh_r = null; // 受信用メッセージハンドラ +$msgh_w = null; // 送信用メッセージハンドラ + // ノンブロッキングメッセージ受信 @@ -54,7 +59,7 @@ function epgrec_childproc( $p ) { $st = proc_get_status( $p ); - $cpids = epgrec_childproc( $st['pid'] ); + $ppid = $st['pid']; // ps を実行する $d = array( @@ -104,10 +109,6 @@ ////// ここから本編 -$settings = Settings::factory(); -$reserve_id = $argv[1]; -$msgh_r = null; // 受信用メッセージハンドラ -$msgh_w = null; // 送信用メッセージハンドラ // メッセージハンドラを得る $ipc_key = ftok( RECORDER_CMD, "R" ); @@ -155,6 +156,7 @@ $proch = false; if( ( $proch = epgrec_exec(DO_RECORD) ) !== false ) { + reclog("recorder:: 録画ID".$rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画開始" ); // 録画完了待ち $rec_cont = true; while( $rec_cont ){ @@ -171,6 +173,7 @@ else { epgrec_send_message("success"); reclog("recorder:: 録画ID".$rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画が中断された" ); + $rec_cont = false; } break; @@ -193,7 +196,6 @@ } // 予定より短いようなら終了時間を現在に書き換える - if( time() < $endtime ) { $rrec->endtime = toDatetime( time() ); } diff -r 47a3acf19870 -r 3d4df1fe4166 storeProgram.inc.php --- a/storeProgram.inc.php Fri Apr 02 20:40:55 2010 +0900 +++ b/storeProgram.inc.php Thu Apr 08 04:22:20 2010 +0900 @@ -1,4 +1,5 @@ reservation(); -// reclog( "getepg::キーワードID".$val->id."の録画が予約された"); } catch( Exception $e ) { // 無視 @@ -35,6 +35,7 @@ function storeProgram( $type, $xmlfile ) { global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; + global $settings; // チャンネルマップファイルの準備 $map = array(); @@ -149,9 +150,15 @@ // 自動録画予約された番組は放映時間変更と同時にいったん削除する 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 ); + // すでに開始されている録画は無視する + 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 ) { diff -r 47a3acf19870 -r 3d4df1fe4166 templates/recordedTable.html --- a/templates/recordedTable.html Fri Apr 02 20:40:55 2010 +0900 +++ b/templates/recordedTable.html Thu Apr 08 04:22:20 2010 +0900 @@ -25,19 +25,21 @@ }, rec:function(id){ var df = 0; - if( $('#delete_file').attr('checked') ) { df = 1; } $('#floatBox4Dialog').dialog('close'); - + $('#floatBox4Dialog').html('削除中.......'); + $('#floatBox4Dialog').dialog('open', 'center'); $.get(INISet.prgCancelURL, { reserve_id: id, delete_file: df } ,function(data){ - if(data.match(/^error/i)){ + $('#floatBox4Dialog').dialog('close'); alert(data); } else { +// alert(data); $('#resid_' + id ).hide(); + $('#floatBox4Dialog').dialog('close'); } }); }, diff -r 47a3acf19870 -r 3d4df1fe4166 templates/reservationTable.html --- a/templates/reservationTable.html Fri Apr 02 20:40:55 2010 +0900 +++ b/templates/reservationTable.html Thu Apr 08 04:22:20 2010 +0900 @@ -15,12 +15,15 @@ var PRG = { rec:function(id){ $.get(INISet.prgCancelURL, { reserve_id: id } ,function(data){ - + $('#eraseDialog').html('キャンセル中......'); + $('#eraseDialog').dialog('open','center'); if(data.match(/^error/i)){ + $('#eraseDialog').dialog('close'); alert(data); } else { $('#resid_' + id ).hide(); + $('#eraseDialog').dialog('close'); } }); }, @@ -60,6 +63,11 @@ var DG = $('#floatBox4Dialog'); DG.dialog({title:'予約編集',width:500}); DG.dialog('close'); + + var EG = $('#eraseDialog'); + EG.dialog({title:'キャンセル',width:400}); + EG.dialog('close'); + }); @@ -155,7 +163,7 @@ {/if}
jQuery UI Dialog
- +
jQuery UI Dialog
{literal}