changeset 161:84220382fea8

mod: 録画中のキャンセルを可能にした(動作確認、まだ不完全かも)
author epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
date Sun, 04 Apr 2010 17:10:17 +0900
parents 00b5ed67d792
children c6c6bd734f18
files Reservation.class.php cancelReservation.php config.php.sample install/step1.php recomplete.php recorder.php templates/recordedTable.html templates/reservationTable.html
diffstat 8 files changed, 100 insertions(+), 89 deletions(-) [+]
line wrap: on
line diff
--- 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 篋膣c潟祉DB・膓障≪祉鴻紊掩罔≧", EPGREC_ERROR );
@@ -370,4 +413,4 @@
 		}
 	}
 }
-?>
+?>
\ No newline at end of file
--- 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() );
--- 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/CSEPG緇c潟
 // 絽吾紊綽荀障
--- 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,
--- 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
-<?php
-$script_path = dirname( __FILE__ );
-chdir( $script_path );
-include_once( $script_path . '/config.php');
-include_once( INSTALL_PATH . "/DBRecord.class.php" );
-include_once( INSTALL_PATH . "/Settings.class.php" );
-include_once( INSTALL_PATH . "/recLog.inc.php" );
-
-$settings = Settings::factory();
-
-$reserve_id = $argv[1];
-
-try{
-	$rrec = new DBRecord( RESERVE_TBL, "id" , $reserve_id );
-	$rrec->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 ) {
-			// <c緇c鴻腆阪c純
-			@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() );
-}
-
-?>
--- 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;
 					
--- 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');
 				}
 			});
 		},
--- 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('c潟祉筝......');
+				$('#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:'c潟祉',width:400});
+		EG.dialog('close');
+
 	});
 
 </script>
@@ -155,7 +163,7 @@
 {/if}
 
 <div id="floatBox4Dialog">jQuery UI Dialog</div>
-
+<div id="eraseDialog">jQuery UI Dialog</div>
 
 {literal}
 <script type="text/javascript">