OSDN Git Service

mod: ログ機能を追加
authorepgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
Sat, 20 Mar 2010 14:59:01 +0000 (23:59 +0900)
committerepgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
Sat, 20 Mar 2010 14:59:01 +0000 (23:59 +0900)
Keyword.class.php
Reservation.class.php
install/step3.php
recLog.inc.php [new file with mode: 0755]
storeProgram.inc.php
tableStruct.inc.php
upgrade_db.php

index 7c8ad9d..b8955a7 100755 (executable)
@@ -44,13 +44,13 @@ class Keyword extends DBRecord {
                                $options .= " AND ( CONCAT(title,' ',description) like '%".mysql_real_escape_string($keyword)."%'";
                                
                                if( $f_zennum ) {
-                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVN' ))."%'";
+                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVN',"UTF-8" ))."%'";
                                }
                                if( $f_zenal ) {
-                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVR' ))."%'";
+                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVR', "UTF-8" ))."%'";
                                }
                                if( $f_zenal && $f_zennum ) {
-                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVRN' ))."%'";
+                                       $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVRN', "UTF-8" ))."%'";
                                }
                                $options .= ") ";
                        }
index a364928..caf83b9 100755 (executable)
@@ -3,6 +3,7 @@ include_once('config.php');
 include_once( INSTALL_PATH . "/DBRecord.class.php" );
 include_once( INSTALL_PATH . "/reclib.php" );
 include_once( INSTALL_PATH . "/Settings.class.php" );
+include_once( INSTALL_PATH . "/recLog.inc.php" );
 
 
 // 予約クラス
@@ -178,7 +179,6 @@ class Reservation {
                                throw new Exception( "終わりつつある/終わっている番組です" );
                        }
                        
-                       
                        // ここからファイル名生成
 /*
                        %TITLE% 番組タイトル
@@ -300,6 +300,7 @@ class Reservation {
                        }
                        else {
                                $rrec->delete();
+                               reclog( "Reservation::custom atの実行に失敗した模様", E_ERROR);
                                throw new Exception("AT実行エラー");
                        }
                        // job番号を取り出す
@@ -313,11 +314,13 @@ class Reservation {
                        if( $key !== false ) {
                                if( is_numeric( $rarr[$key+1]) ) {
                                        $rrec->job = $rarr[$key+1];
+                                       reclog( "Reservation::custom ジョブ番号".$rrec->job."に録画ジョブを登録");
                                        return $rrec->job;                      // 成功
                                }
                        }
                        // エラー
                        $rrec->delete();
+                       reclog( "Reservation::custom job番号の取得に失敗",E_ERROR );
                        throw new Exception( "job番号の取得に失敗" );
                }
                catch( Exception $e ) {
@@ -349,13 +352,16 @@ class Reservation {
                        }
                        if( ! $rec->complete ) {
                                // 未実行の予約である
-                               if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) )
-                                       throw new Exception("過去の録画予約です");
+                               if( toTimestamp($rec->starttime) < (time() + PADDING_TIME + $settings->former_time) ) {
+                                       reclog("Reservation::cancel 未実行の予約の取り消しが実行された", E_ERROR );
+                               }
                                exec( $settings->atrm . " " . $rec->job );
+                               reclog("Reservation::cancel ジョブ番号".$rec->job."を削除");
                        }
                        $rec->delete();
                }
                catch( Exception $e ) {
+                       reclog("Reservation::cancel 予約キャンセルでDB接続またはアクセスに失敗した模様", E_ERROR );
                        throw $e;
                }
        }
index a7a8eb2..324d124 100755 (executable)
@@ -41,6 +41,9 @@ try {
     
     $rec = new DBRecord( KEYWORD_TBL );
     $rec->createTable( KEYWORD_STRUCT );
+
+    $rec = new DBRecord( LOG_TBL );
+    $rec->createTable( LOG_STRUCT );
 }
 catch( Exception $e ) {
        jdialog("テーブルの作成に失敗しました。データベースに権限がない等の理由が考えられます。", "step2.php" );
diff --git a/recLog.inc.php b/recLog.inc.php
new file mode 100755 (executable)
index 0000000..f399569
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+define( "E_INFO" , 0 );
+define( "E_ERROR", 2 );
+
+
+function reclog( $message , $level = E_INFO ) {
+       
+       try {
+               $log = new DBRecord( LOG_TBL );
+               
+               $log->logtime = date("Y-m-d H:i:s");
+               $log->level = $level;
+               $log->message = $message;
+       }
+       catch( Exception $e ) {
+               // 
+       }
+}
+
+?>
index 27b7f0e..061ee75 100755 (executable)
@@ -9,7 +9,12 @@ function garbageClean() {
        
        // 8日以上先のデータがあれば消す
        $arr = array();
-       $arr = DBRecord::createRecords(  PROGRAM_TBL, "WHERE starttime  > adddate( now(), 8 )" );
+       $arr = DBRecord::createRecords(  PROGRAM_TBL, "WHERE starttime  > adddate( now(), 8 ) ");
+       foreach( $arr as $val ) $val->delete();
+
+       // 8日以上前のログを消す
+       $arr = array();
+       $arr = DBRecord::createRecords(  LOG_TBL, "WHERE endtime < subdate( now(), 8 )" );
        foreach( $arr as $val ) $val->delete();
 }
 
@@ -20,9 +25,10 @@ function doKeywordReservation() {
        foreach( $arr as $val ) {
                try {
                        $val->reservation();
+                       reclog( "getepg::キーワードID".$val->id."を予約");
                }
                catch( Exception $e ) {
-               // 無視
+                       // 無視
                }
        }
 }
@@ -39,6 +45,7 @@ function storeProgram( $type, $xmlfile ) {
        // XML parse
        $xml = @simplexml_load_file( $xmlfile );
        if( $xml === false ) {
+               reclog( "getepg::".$xmlfile."が作成されなかった模様", E_ERROR );
                return; // XMLが読み取れないなら何もしない
        }
        // channel抽出
@@ -64,7 +71,7 @@ function storeProgram( $type, $xmlfile ) {
                }
         }
         catch( Exception $e ) {
-               // 無視
+               reclog( "getepg::DBの接続またはチャンネルテーブルの書き込みに失敗", E_ERROR );
         }
        }
        // channel 終了
@@ -82,7 +89,7 @@ function storeProgram( $type, $xmlfile ) {
                        $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", "$channel_disc" );
                }
                catch( Exception $e ) {
-                       // 無視
+                       reclog( "getepg::チャンネルレコードが発見できない", E_ERROR );
                }
                if( $channel_rec == null ) continue;    // あり得ないことが起きた
                if( $channel_rec->skip == 1 ) continue; // 受信しないチャンネル
@@ -129,13 +136,15 @@ function storeProgram( $type, $xmlfile ) {
                                        try {
                                                $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
                                                if( $reserve->autorec ) {
+                                                       reclog( "getepg::録画ID".$reserve->id."は時間変更の可能性あり予約を取り消し");
                                                        Reservation::cancel( $reserve->id );
                                                }
                                        }
                                        catch( Exception $e ) {
-                                               //無視
+                                               // 無視
                                        }
                                        // 番組削除
+                                       reclog( "getepg::放送時間重複が発生した番組ID".$rec->id."を削除" );
                                        $rec->delete();
                                }
                        }
@@ -161,9 +170,10 @@ function storeProgram( $type, $xmlfile ) {
                 }
                }
                catch(Exception $e) {
+                       reclog( "getepg::DBの入出力に問題が生じた模様", E_ERROR );
                        exit( $e->getMessage() );
                }
        }
        // Programme取得完了
 }
-?>
\ No newline at end of file
+?>
index 2ec35b5..8967984 100755 (executable)
@@ -79,4 +79,12 @@ define( "KEYWORD_STRUCT",
        ""
 );
 
+define( "LOG_STRUCT",
+       "id integer not null auto_increment primary key".                               // ID
+       ",logtime  datetime not null default '1970-01-01 00:00:00'".    // 記録日時
+       ",level integer not null default '0'".                                                  // エラーレベル
+       ",message varchar(512) not null default ''".
+       ""
+);
+
 ?>
\ No newline at end of file
index 9fbb380..866b009 100755 (executable)
@@ -4,7 +4,8 @@ $script_path = dirname( __FILE__ );
 chdir( $script_path );
 include_once($script_path . '/config.php');
 include_once(INSTALL_PATH . '/Settings.class.php' );
-
+include_once(INSTALL_PATH . '/DBRecord.class.php' );
+include_once(INSTALL_PATH . '/tableStruct.inc.php' );
 
 // mysqli::multi_queryは動作がいまいちなので使わない
 
@@ -193,6 +194,18 @@ if( $dbh !== FALSE ) {
        if( multi_query( $sqlstrs, $dbh ) ) {
                echo "キーワードテーブルのアップデートに失敗\n";
        }
+
+       // ログテーブル
+
+       try {
+               $log = new DBRecord( LOG_TBL );
+               $log->createTable( LOG_STRUCT );
+       }
+       catch( Exception $e ) {
+               echo $e->message;
+               echo "\n";
+       }
+
 }
 else
        exit( "DBの接続に失敗\n" );