# HG changeset patch # User epgrec@park.mda.or.jp # Date 1270368617 -32400 # Node ID 84220382fea83a91e5ba81abf59243d6c4af966a # Parent 00b5ed67d7923b1f6ce1889a8fee915d6dc83dfc mod: ????????????????????????????? diff -r 00b5ed67d792 -r 84220382fea8 Reservation.class.php --- a/Reservation.class.php Tue Mar 30 19:00:39 2010 +0900 +++ b/Reservation.class.php Sun Apr 04 17:10:17 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 00b5ed67d792 -r 84220382fea8 cancelReservation.php --- a/cancelReservation.php Tue Mar 30 19:00:39 2010 +0900 +++ b/cancelReservation.php Sun Apr 04 17:10:17 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']; @@ -17,24 +19,12 @@ try { $rec = new DBRecord( RESERVE_TBL, "id" , $reserve_id ); $program_id = $rec->program_id; - - 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"); - } - } - } } catch( Exception $e ) { // 無視 } } - - // 手動取り消しのときには、その番組を自動録画対象から外す if( $program_id ) { try { @@ -45,10 +35,27 @@ // 無視 } } +if( $rec == null ) exit( "Error: 予約レコードが取得出来ません" ); + +if( isset( $_GET['delete_file'] ) ) { + if( $_GET['delete_file'] == 1 ) { + $path = INSTALL_PATH."/".$settings->spool."/".$rec->path; + } +} + // 予約取り消し実行 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 00b5ed67d792 -r 84220382fea8 config.php.sample --- a/config.php.sample Tue Mar 30 19:00:39 2010 +0900 +++ b/config.php.sample Sun Apr 04 17:10:17 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 00b5ed67d792 -r 84220382fea8 install/step1.php --- a/install/step1.php Tue Mar 30 19:00:39 2010 +0900 +++ b/install/step1.php Sun Apr 04 17:10:17 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 00b5ed67d792 -r 84220382fea8 recomplete.php --- a/recomplete.php Tue Mar 30 19:00:39 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -#!/usr/bin/php -complete = '1'; - - if( file_exists( INSTALL_PATH .$settings->spool . "/". $rrec->path ) ) { - // 予約完了 - reclog( "recomplete:: 予約ID". $rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画が完了" ); - - if( $settings->mediatomb_update == 1 ) { - // ちょっと待った方が確実っぽい - @exec("sync"); - sleep(15); - $dbh = mysql_connect( $settings->db_host, $settings->db_user, $settings->db_pass ); - if( $dbh !== false ) { - $sqlstr = "use ".$settings->db_name; - @mysql_query( $sqlstr ); - // 別にやらなくてもいいが - $sqlstr = "set NAME utf8"; - @mysql_query( $sqlstr ); - $sqlstr = "update mt_cds_object set metadata='dc:description=".mysql_real_escape_string($rrec->description)."&epgrec:id=".$reserve_id."' where dc_title='".$rrec->path."'"; - @mysql_query( $sqlstr ); - $sqlstr = "update mt_cds_object set dc_title='".mysql_real_escape_string($rrec->title)."(".date("Y/m/d").")' where dc_title='".$rrec->path."'"; - @mysql_query( $sqlstr ); - } - } - } - else { - // 予約失敗 - reclog( "recomplete:: 予約ID". $rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画に失敗した模様", EPGREC_ERROR ); - $rrec->delete(); - } -} -catch( exception $e ) { - reclog( "recomplete:: 予約テーブルのアクセスに失敗した模様", EPGREC_ERROR ); - reclog( "recomplete:: ".$e->getMessage()."" , EPGREC_ERROR ); - exit( $e->getMessage() ); -} - -?> diff -r 00b5ed67d792 -r 84220382fea8 recorder.php --- a/recorder.php Tue Mar 30 19:00:39 2010 +0900 +++ b/recorder.php Sun Apr 04 17:10:17 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" ); @@ -171,6 +172,7 @@ else { epgrec_send_message("success"); reclog("recorder:: 録画ID".$rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画が中断された" ); + $rec_cont = false; } break; diff -r 00b5ed67d792 -r 84220382fea8 templates/recordedTable.html --- a/templates/recordedTable.html Tue Mar 30 19:00:39 2010 +0900 +++ b/templates/recordedTable.html Sun Apr 04 17:10:17 2010 +0900 @@ -25,19 +25,20 @@ }, 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 { $('#resid_' + id ).hide(); + $('#floatBox4Dialog').dialog('close'); } }); }, diff -r 00b5ed67d792 -r 84220382fea8 templates/reservationTable.html --- a/templates/reservationTable.html Tue Mar 30 19:00:39 2010 +0900 +++ b/templates/reservationTable.html Sun Apr 04 17:10:17 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}