OSDN Git Service

mod: EPGの更新と同時に予約情報を更新するように変更、ログビューアの追加
authorepgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
Sun, 21 Mar 2010 07:42:58 +0000 (16:42 +0900)
committerepgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
Sun, 21 Mar 2010 07:42:58 +0000 (16:42 +0900)
Reservation.class.php
changeReservation.php
customReservation.php
envSetting.php
getepg.php
logViewer.php [new file with mode: 0755]
recomplete.php
storeProgram.inc.php
tableStruct.inc.php
templates/logTable.html [new file with mode: 0755]
upgrade_db.php

index caf83b9..0107bf2 100755 (executable)
@@ -43,7 +43,8 @@ class Reservation {
                $category_id = 0,               // カテゴリID
                $program_id = 0,                // 番組ID
                $autorec = 0,                   // 自動録画
-               $mode = 0                               // 録画モード
+               $mode = 0,                              // 録画モード
+               $dirty = 0                              // ダーティフラグ
        ) {
                global $RECORD_MODE;
                $settings = Settings::factory();
@@ -130,6 +131,7 @@ class Reservation {
                                                $prev_endtime      = $trecs[$i]->endtime;
                                                $prev_autorec      = $trecs[$i]->autorec;
                                                $prev_mode         = $trecs[$i]->mode;
+                                               $prev_dirty        = $trecs[$i]->dirty;
                                                
                                                $prev_start_time = toTimestamp($prev_starttime);
                                                // 始まっていない予約?
@@ -153,7 +155,8 @@ class Reservation {
                                                                        $prev_category_id,                      // カテゴリID
                                                                        $prev_program_id,                       // 番組ID
                                                                        $prev_autorec,                          // 自動録画
-                                                                       $prev_mode );
+                                                                       $prev_mode,
+                                                                       $prev_dirty );
                                                        }
                                                        catch( Exception $e ) {
                                                                throw new Exception( "重複予約を解消できません" );
index 17b5b92..ecfac61 100755 (executable)
@@ -27,6 +27,7 @@ try {
        
        if( isset( $_POST['title'] ) ) {
                $rec->title = trim( $_POST['title'] );
+               $rec->dirty = 1;
                if( ($dbh !== false) && ($rec->complete == 1) ) {
                        $title = trim( mysql_real_escape_string($_POST['title']));
                        $title .= "(".date("Y/m/d", toTimestamp($rec->starttime)).")";
@@ -37,6 +38,7 @@ try {
        
        if( isset( $_POST['description'] ) ) {
                $rec->description = trim( $_POST['description'] );
+               $rec->dirty = 1;
                if( ($dbh !== false) && ($rec->complete == 1) ) {
                        $desc = "dc:description=".trim( mysql_real_escape_string($_POST['description']));
                        $desc .= "&epgrec:id=".$reserve_id;
@@ -51,4 +53,4 @@ catch( Exception $e ) {
 
 exit("complete");
 
-?>
+?>
\ No newline at end of file
index d7a46a9..0105c66 100755 (executable)
@@ -60,7 +60,8 @@ try{
                $category_id,
                $program_id,
                0,              // 自動録画
-               $mode   // 録画モード
+               $mode,  // 録画モード
+               1               // ダーティフラグ
        );
 }
 catch( Exception $e ) {
index f73e0a1..23c9715 100755 (executable)
@@ -11,7 +11,7 @@ $smarty->assign( "record_mode", $RECORD_MODE );
 $smarty->assign( "install_path", INSTALL_PATH );
 $smarty->assign( "post_to", "postsettings.php" );
 $smarty->assign( "sitetitle", "環境設定設定" );
-$smarty->assign( "message", '<a href="index.php">設定せずに番組表に戻る</a>/<a href="systemSetting.php">システム設定へ</a>' );
+$smarty->assign( "message", '<a href="index.php">設定せずに番組表に戻る</a>/<a href="systemSetting.php">システム設定へ</a>/<a href="logViewer.php">動作ログを見る</a>' );
 
 $smarty->display("envSetting.html");
-?>
\ No newline at end of file
+?>
index a1a04b8..34172fe 100755 (executable)
@@ -8,6 +8,7 @@
   include_once( INSTALL_PATH . '/Keyword.class.php' );
   include_once( INSTALL_PATH . '/Settings.class.php' );
   include_once( INSTALL_PATH . '/storeProgram.inc.php' );
+  include_once( INSTALL_PATH . '/recLog.inc.php' );
   
   // 後方互換性
   if( ! defined( "BS_EPG_CHANNEL" )  ) define( "BS_EPG_CHANNEL",  "211"  );
   // 並列化が可能か執念深く調べる
   $use_para = false;
   $use_para = (function_exists( "pcntl_fork" ) && function_exists( "posix_setsid" ) && function_exists( "pcntl_signal" ) && function_exists("pcntl_setpriority"));
-  
+  if( ! $use_para ) {
+       reclog("getepg:: 並列実行が行えないPHP環境です" );
+  }
+  else {
+       reclog("getepg:: 並列実行を使用します" );
+  }
   
   $settings = Settings::factory();
   
diff --git a/logViewer.php b/logViewer.php
new file mode 100755 (executable)
index 0000000..cd053b1
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+include_once('config.php');
+include_once( INSTALL_PATH . '/DBRecord.class.php' );
+include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' );
+
+
+$arr = DBRecord::createRecords( LOG_TBL, " ORDER BY logtime DESC" );
+
+$smarty = new Smarty();
+
+$smarty->assign( "sitetitle" , "epgrec動作ログ" );
+$smarty->assign( "logs", $arr );
+
+$smarty->display( "logTable.html" );
+?>
\ No newline at end of file
index f082210..fc75fb2 100755 (executable)
@@ -5,6 +5,7 @@ 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();
 
@@ -12,10 +13,12 @@ $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 ) ) {
                // 予約完了
-               $rrec->complete = '1';
+               reclog( "recomplete:: 予約ID". $rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画が完了" );
+               
                if( $settings->mediatomb_update == 1 ) {
                        // ちょっと待った方が確実っぽい
                        @exec("sync");
@@ -36,10 +39,13 @@ try{
        }
        else {
                // 予約失敗
+               reclog( "recomplete:: 予約ID". $rrec->id .":".$rrec->type.$rrec->channel.$rrec->title."の録画に失敗した模様", E_ERROR );
                $rrec->delete();
        }
 }
 catch( exception $e ) {
+       reclog( "recomplete:: 予約テーブルのアクセスに失敗した模様", E_ERROR );
+       reclog( "recomplete:: ".$e->getMessage()."" , E_ERROR );
        exit( $e->getMessage() );
 }
 
index 061ee75..af9f716 100755 (executable)
@@ -12,9 +12,9 @@ function garbageClean() {
        $arr = DBRecord::createRecords(  PROGRAM_TBL, "WHERE starttime  > adddate( now(), 8 ) ");
        foreach( $arr as $val ) $val->delete();
 
-       // 8日以上前のログを消す
+       // 30日以上前のログを消す
        $arr = array();
-       $arr = DBRecord::createRecords(  LOG_TBL, "WHERE endtime < subdate( now(), 8 )" );
+       $arr = DBRecord::createRecords(  LOG_TBL, "WHERE endtime < subdate( now(), 30 )" );
        foreach( $arr as $val ) $val->delete();
 }
 
@@ -25,7 +25,7 @@ function doKeywordReservation() {
        foreach( $arr as $val ) {
                try {
                        $val->reservation();
-                       reclog( "getepg::ã\82­ã\83¼ã\83¯ã\83¼ã\83\89ID".$val->id."ã\82\92äº\88ç´\84");
+                       reclog( "getepg::ã\82­ã\83¼ã\83¯ã\83¼ã\83\89ID".$val->id."ã\81®é\8c²ç\94»ã\81\8cäº\88ç´\84ã\81\95ã\82\8cã\81\9f");
                }
                catch( Exception $e ) {
                        // 無視
@@ -45,7 +45,7 @@ function storeProgram( $type, $xmlfile ) {
        // XML parse
        $xml = @simplexml_load_file( $xmlfile );
        if( $xml === false ) {
-               reclog( "getepg::".$xmlfile."が作成されなかった模様", E_ERROR );
+               reclog( "getepg:: 正常な".$xmlfile."が作成されなかった模様(放送間帯でないなら問題ありません)" );
                return; // XMLが読み取れないなら何もしない
        }
        // channel抽出
@@ -89,7 +89,7 @@ function storeProgram( $type, $xmlfile ) {
                        $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" );
                }
                catch( Exception $e ) {
-                       reclog( "getepg::チャンネルレコードが発見できない", E_ERROR );
+                       reclog( "getepg::チャンネルレコード $channel_disc が発見できない", E_ERROR );
                }
                if( $channel_rec == null ) continue;    // あり得ないことが起きた
                if( $channel_rec->skip == 1 ) continue; // 受信しないチャンネル
@@ -106,71 +106,98 @@ function storeProgram( $type, $xmlfile ) {
                }
                $program_disc = md5( $channel_disc . $starttime . $endtime );
                // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
+               
+               // カテゴリ登録
+               
+               $cat_rec = null;
                try {
-                // カテゴリを処理する
-                $category_disc = md5( $cat_ja . $cat_en );
-                $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
-                $cat_rec = null;
-                if( $num == 0 ) {
-                       // 新規カテゴリの追加
-                       $cat_rec = new DBRecord( CATEGORY_TBL );
-                       $cat_rec->name_jp = $cat_ja;
-                       $cat_rec->name_en = $cat_en;
-                       $cat_rec->category_disc = $category_disc;
-                }
-                else
-                       $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
-                //
-                $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
-                if( $num == 0 ) {
-                       // 新規番組
-                       // 重複チェック 同時間帯にある番組
-                       $options = "WHERE channel_disc = '".$channel_disc."' ".
-                               "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
-                       $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
-                       if( $battings > 0 ) {
-                               // 重複発生=おそらく放映時間の変更
-                               $records = DBRecord::createRecords(PROGRAM_TBL, $options );
-                               foreach( $records as $rec ) {
-                                       // 自動録画予約された番組は放映時間変更と同時にいったん削除する
-                                       try {
-                                               $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
-                                               if( $reserve->autorec ) {
-                                                       reclog( "getepg::録画ID".$reserve->id."は時間変更の可能性あり予約を取り消し");
-                                                       Reservation::cancel( $reserve->id );
+                       // カテゴリを処理する
+                       $category_disc = md5( $cat_ja . $cat_en );
+                       $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
+                       if( $num == 0 ) {
+                               // 新規カテゴリの追加
+                               $cat_rec = new DBRecord( CATEGORY_TBL );
+                               $cat_rec->name_jp = $cat_ja;
+                               $cat_rec->name_en = $cat_en;
+                               $cat_rec->category_disc = $category_disc;
+                               reclog("getepg:: 新規カテゴリ".$cat_ja."を追加" );
+                       }
+                       else
+                               $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
+               }
+               catch( Exception $e ) {
+                       reclog("getepg:: カテゴリテーブルのアクセスに失敗した模様", E_ERROR );
+                       reclog("getepg:: ".$e->getMessage()."" ,E_ERROR );
+                       exit( $e->getMessage() );
+               }
+               
+               // プログラム登録
+               
+               try {
+                       //
+                       $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
+                       if( $num == 0 ) {
+                               // 新規番組
+                               // 重複チェック 同時間帯にある番組
+                               $options = "WHERE channel_disc = '".$channel_disc."' ".
+                                       "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
+                               $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
+                               if( $battings > 0 ) {
+                                       // 重複発生=おそらく放映時間の変更
+                                       $records = DBRecord::createRecords(PROGRAM_TBL, $options);
+                                       foreach( $records as $rec ) {
+                                               // 自動録画予約された番組は放映時間変更と同時にいったん削除する
+                                               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 );
+                                                       }
                                                }
+                                               catch( Exception $e ) {
+                                                       // 無視
+                                               }
+                                               // 番組削除
+                                               reclog( "getepg::放送時間重複が発生した番組ID".$rec->id." ".$rec->type.$rec->channel.$rec->title."を削除" );
+                                               $rec->delete();
                                        }
-                                       catch( Exception $e ) {
-                                               // 無視
+                               }
+                               // //
+                               $rec = new DBRecord( PROGRAM_TBL );
+                               $rec->channel_disc = $channel_disc;
+                               $rec->channel_id = $channel_rec->id;
+                               $rec->type = $type;
+                               $rec->channel = $channel_rec->channel;
+                               $rec->title = $title;
+                               $rec->description = $desc;
+                               $rec->category_id = $cat_rec->id;
+                               $rec->starttime = $starttime;
+                               $rec->endtime = $endtime;
+                               $rec->program_disc = $program_disc;
+                       }
+                       else {
+                               // 番組内容更新
+                               $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
+                               $rec->title = $title;
+                               $rec->description = $desc;
+                               $rec->category_id = $cat_rec->id;
+                               
+                               try {
+                                       $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id );
+                                       if( $reserve->dirty == 0 ) {
+                                               $reserve->title = $title;
+                                               $reserve->description = $desc;
+                                               reclog( "getepg:: 予約ID".$reserve->id."のEPG情報が更新された" );
                                        }
-                                       // 番組削除
-                                       reclog( "getepg::放送時間重複が発生した番組ID".$rec->id."を削除" );
-                                       $rec->delete();
+                               }
+                               catch( Exception $e ) {
+                                       // 無視する
                                }
                        }
-                       // //
-                       $rec = new DBRecord( PROGRAM_TBL );
-                       $rec->channel_disc = $channel_disc;
-                       $rec->channel_id = $channel_rec->id;
-                       $rec->type = $type;
-                       $rec->channel = $channel_rec->channel;
-                       $rec->title = $title;
-                       $rec->description = $desc;
-                       $rec->category_id = $cat_rec->id;
-                       $rec->starttime = $starttime;
-                       $rec->endtime = $endtime;
-                       $rec->program_disc = $program_disc;
-                }
-                else {
-                       // 番組内容更新
-                       $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
-                       $rec->title = $title;
-                       $rec->description = $desc;
-                       $rec->category_id = $cat_rec->id;
-                }
                }
                catch(Exception $e) {
-                       reclog( "getepg::DBの入出力に問題が生じた模様", E_ERROR );
+                       reclog( "getepg:: プログラムテーブルに問題が生じた模様", E_ERROR );
+                       reclog( "getepg:: ".$e->getMessage()."" , E_ERROR);
                        exit( $e->getMessage() );
                }
        }
index 8967984..ba12b61 100755 (executable)
@@ -21,6 +21,7 @@ define( "RESERVE_STRUCT",
        "reserve_disc varchar(128) not null default 'none',".                   // 識別用hash
        "autorec integer not null default '0',".                                                // キーワードID
        "mode integer not null default '0',".                                                   // 録画モード
+       "dirty boolean not null default '0',".                                                  // ダーティフラグ
        "index reserve_ch_idx (channel_disc),".                                                 // インデックス
        "index reserve_st_idx (starttime)".
        ""
@@ -74,8 +75,8 @@ define( "KEYWORD_STRUCT",
        "category_id integer not null default '0',".                                    // カテゴリID
        "use_regexp boolean not null default '0',".                                             // 正規表現を使用するなら1
        "autorec_mode integer not null default '0',".                                   // 自動録画のモード02/23/2010追加
-       "weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'".// 曜日、同追加
-       ",prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24') default '24'".      // 時間 03/13/2010追加
+       "weekofday enum ('0','1','2','3','4','5','6','7' ) not null default '7'".// 曜日、同追加
+       ",prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24') not null default '24'".     // 時間 03/13/2010追加
        ""
 );
 
@@ -87,4 +88,4 @@ define( "LOG_STRUCT",
        ""
 );
 
-?>
\ No newline at end of file
+?>
diff --git a/templates/logTable.html b/templates/logTable.html
new file mode 100755 (executable)
index 0000000..62173bd
--- /dev/null
@@ -0,0 +1,74 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+"http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>{$sitetitle}</title>
+<meta http-equiv="Content-Style-Type" content="text/css">
+
+{literal}
+<style type="text/css">
+<!--
+body {padding:4px;margin:0;font-size:10pt;}
+a {text-decoration:none;}
+
+table#log_table {
+    width: 800px;
+    border: 1px #BBB solid;
+    border-collapse: collapse;
+    border-spacing: 0;
+}
+
+table#log_table th {
+    padding: 5px;
+    border: #E3E3E3 solid;
+    border-width: 0 0 1px 1px;
+    background: #BBB;
+    font-weight: bold;
+    line-height: 120%;
+    text-align: center;
+}
+table#log_table td {
+    padding: 5px;
+    border: 1px #BBB solid;
+    border-width: 0 0 1px 1px;
+    text-align: center;
+}
+
+table#log_table td.errorlevel0 {background-color: #FFFFFF;}
+table#log_table td.errorlevel1 {background-color: red;}
+
+
+-->
+</style>
+{/literal}
+
+</head>
+
+<body>
+
+<h2>{$sitetitle}</h2>
+
+<div><a href="index.php">番組表に戻る</a></div>
+
+<table id="log_table">
+ <tr>
+  <th>レベル</th>
+  <th>日時</th>
+  <th>内容</th>
+ </tr>
+
+{foreach from=$logs item=log}
+ <tr>
+  <td class="errorlevel{$log->level}">
+    {if $log->level == 0}情報
+    {elseif $log->level == 1}エラー
+    {/if}
+  </td>
+  <td>{$log->logtime}</td>
+  <td>{$log->message|escape}</td>
+ </tr>
+{/foreach}
+</body>
+</html>
index 866b009..cc11882 100755 (executable)
@@ -66,6 +66,13 @@ if( $dbh !== FALSE ) {
         "alter table ".$settings->tbl_prefix.RESERVE_TBL." modify  mode integer not null default '0';",                                        //録画モード
        );
        
+       if( index_exists( $settings->tbl_prefix.RESERVE_TBL, "dirty", $dbh) ) {
+               echo "dirtyフィールドはすでに存在しているため作成しません\n";
+       }
+       else {
+               array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.RESERVE_TBL." add dirty boolean not null default '0';" );
+       }
+       
        if( multi_query( $sqlstrs, $dbh ) ) {
                echo "予約テーブルのアップデートに失敗\n";
        }
@@ -178,31 +185,35 @@ if( $dbh !== FALSE ) {
        }
        if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "weekofday", $dbh ) ) {
                echo "weekofdayは存在しているので作成しません\n";
+               array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify weekofday enum ('0','1','2','3','4','5','6','7' ) not null default '7'" );
        }
        else {
-               array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add weekofday enum ('0','1','2','3','4','5','6','7' ) default '7'" );
+               array_push( $sqlstrs, "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add weekofday enum ('0','1','2','3','4','5','6','7' ) not null default '7'" );
        }
        if( column_exists( $settings->tbl_prefix.KEYWORD_TBL, "prgtime", $dbh ) ) {
                echo "prgtimeは存在しているので作成しません\n";
+               array_push( $sqlstrs, 
+                       "alter table ".$settings->tbl_prefix.KEYWORD_TBL." modify prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12',".
+                                                                                                                                                               "'13','14','15','16','17','18','19','20','21','22','23','24') not null default '24'" );
        }
        else {
                array_push( $sqlstrs, 
                        "alter table ".$settings->tbl_prefix.KEYWORD_TBL." add prgtime enum ('0','1','2','3','4','5','6','7','8','9','10','11','12',".
-                                                                                                                                                               "'13','14','15','16','17','18','19','20','21','22','23','24') default '24'" );
+                                                                                                                                                               "'13','14','15','16','17','18','19','20','21','22','23','24') not null default '24'" );
        }
 
        if( multi_query( $sqlstrs, $dbh ) ) {
                echo "キーワードテーブルのアップデートに失敗\n";
        }
 
-       // ログテーブル
+       // ログテーブル新規作成
 
        try {
                $log = new DBRecord( LOG_TBL );
                $log->createTable( LOG_STRUCT );
        }
        catch( Exception $e ) {
-               echo $e->message;
+               echo $e->getMessage();
                echo "\n";
        }