Index: trunk/extensions/MetavidWiki/maintenance/video_ocr_thumb_insert.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | class streamObject{ }; |
75 | 75 | $stream = new streamObject(); |
76 | 76 | $stream->name = $stream_name; |
77 | | -$stream->org_start_time = $org_start_time; |
| 77 | +$stream->date_start_time = $org_start_time; |
78 | 78 | $stream->sync_status = 'in_sync'; |
79 | 79 | $stream->duration = $duration; |
80 | 80 | |
Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.php |
— | — | @@ -95,6 +95,7 @@ |
96 | 96 | 'update_templates' will update templates & some semantic properties |
97 | 97 | 'file_check' checks inserted streams file urls/pointers |
98 | 98 | 'do_stream_date_check' |
| 99 | + 'do_remove_orphaned_streams' |
99 | 100 | |
100 | 101 | EOT; |
101 | 102 | exit (); |
— | — | @@ -137,6 +138,9 @@ |
138 | 139 | case 'do_stream_date_check': |
139 | 140 | do_stream_date_check(); |
140 | 141 | break; |
| 142 | + case 'do_remove_orphaned_streams': |
| 143 | + do_remove_orphaned_streams(); |
| 144 | + break; |
141 | 145 | case 'update_templates' : |
142 | 146 | $force = ( isset( $options['force'] ) ) ? true:false; |
143 | 147 | include_once( 'metavid_gov_templates.php' ); |
Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php |
— | — | @@ -34,24 +34,106 @@ |
35 | 35 | // if($i==3)die; |
36 | 36 | // $i++; |
37 | 37 | } |
38 | | -function do_stream_date_check(){ |
| 38 | +function get_all_mv_streams(){ |
39 | 39 | $dbr = wfGetDB( DB_READ ); |
| 40 | + $streams = array(); |
40 | 41 | $result = $dbr->select( 'mv_streams', |
41 | 42 | '*', |
42 | 43 | '', |
| 44 | + __METHOD__ |
| 45 | + ); |
| 46 | + if ( $dbr->numRows( $result ) == 0 )die("do_stream_file_check: no streams found"); |
| 47 | + while ( $stream = $dbr->fetchObject( $result ) ) { |
| 48 | + $streams[$stream->id] = $stream; |
| 49 | + } |
| 50 | + return $streams; |
| 51 | +} |
| 52 | +function do_remove_orphaned_streams(){ |
| 53 | + //get all stream ids present in mv_stream_files and mv_stream_images |
| 54 | + $dbr = wfGetDB( DB_READ ); |
| 55 | + $orphaned_streams = array(); |
| 56 | + $all_valid_streams = get_all_mv_streams(); |
| 57 | + //could be done with a join ..oh well |
| 58 | + $result = $dbr->select( 'mv_stream_files', |
| 59 | + 'stream_id', |
| 60 | + '', |
43 | 61 | __METHOD__, |
44 | | - array('LIMIT'=> 9000)); |
45 | | - if ( $dbr->numRows( $result ) == 0 )die("do_stream_file_check: no streams found"); |
46 | | - |
47 | | - while ( $stream = $dbr->fetchObject( $result ) ) { |
| 62 | + array( 'GROUP BY' => 'stream_id') |
| 63 | + ); |
| 64 | + while ( $stream = $dbr->fetchObject( $result ) ) { |
| 65 | + if(!isset($all_valid_streams[$stream->stream_id ])){ |
| 66 | + $orphaned_streams[ $stream->stream_id ] = 1; |
| 67 | + } |
| 68 | + } |
| 69 | + $result = $dbr->select( 'mv_stream_images', |
| 70 | + 'stream_id', |
| 71 | + '', |
| 72 | + __METHOD__, |
| 73 | + array( 'GROUP BY' => 'stream_id') |
| 74 | + ); |
| 75 | + while ( $stream = $dbr->fetchObject( $result ) ) { |
| 76 | + if( !isset($all_valid_streams[ $stream->stream_id ] ) ){ |
| 77 | + $orphaned_streams[ $stream->stream_id ] = 1; |
| 78 | + } |
| 79 | + } |
| 80 | + foreach($orphaned_streams as $stream_id => $na){ |
| 81 | + $mvStream = new MV_Stream( array('id'=> $stream_id) ); |
| 82 | + //double check stream does not exist: |
| 83 | + if( ! $mvStream->doesStreamExist() ){ |
| 84 | + print "stream id: {$stream_id} does not exist in stream table (remove)\n"; |
| 85 | + //remove files in the stream directory: |
| 86 | + $filedir = '/video/metavid/mvprime_stream_images/' . |
| 87 | + MV_StreamImage::getRelativeImagePath( $stream_id ); |
| 88 | + //print "dir is: $filedir \n"; |
| 89 | + if( is_dir($filedir )){ |
| 90 | + $cmd = 'rm -rf ' . $filedir; |
| 91 | + print "removing image run#: $cmd \n"; |
| 92 | + shell_exec($cmd); |
| 93 | + } |
| 94 | + //print "removing DB entires for $stream_id\n"; |
| 95 | + $mvStream->deleteDB(); |
| 96 | + } |
| 97 | + } |
| 98 | + /*$streams = get_all_mv_streams(); |
| 99 | + foreach( $streams as $stream){ |
| 100 | + //check if stream page exists: |
| 101 | + $mvStreamTitle = Title::newFromText( $stream->name, MV_NS_STREAM ); |
| 102 | + if( !$mvStreamTitle->exists() ){ |
| 103 | + print "stream: {$stream->name} does not exist as a wiki page\n"; |
| 104 | + //should remove here |
| 105 | + $mvStream = new MV_Stream( $stream ); |
| 106 | + } |
| 107 | + }*/ |
| 108 | +} |
| 109 | +function do_stream_date_check(){ |
| 110 | + $streams = get_all_mv_streams(); |
| 111 | + foreach ( $streams as $stream ) { |
48 | 112 | preg_match("/([0-9]+-[0-9]+-[0-9]+)/", $stream->name, $matches); |
49 | 113 | if( ! isset( $matches[1] ) ){ |
50 | 114 | print "no date found in {$stream->name}\n"; |
51 | 115 | continue; |
52 | | - } |
53 | | - $sd = explode('-',$matches[1]); |
54 | | - $sdate = mktime( 9, 0, 0, $sd[0], $sd[1], intval('20'.$sd[2]) ); |
55 | | - if( date('d-y', $stream->date_start_time) != date('d-y',$sdate) ) { |
| 116 | + } |
| 117 | + $sdate = $force_update = false; |
| 118 | + //check for srt file: |
| 119 | + $srt_file = '/video/metavid/raw_mpeg2/' . $stream->name . '.srt'; |
| 120 | + if( is_file( $srt_file ) ){ |
| 121 | + $srt_ary = file( $srt_file ); |
| 122 | + $time = intval( trim( str_replace( 'starttime' , '', $srt_ary[2] )) ); |
| 123 | + //ignore bad .srt values (before 08 |
| 124 | + if( intval( date('y', $time) > 8)) { |
| 125 | + if( $stream->date_start_time != $time){ |
| 126 | + $sdate=$time; |
| 127 | + $force_update = true; |
| 128 | + print "force srt update:: "; |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + //no date from srt make starting at 9am |
| 133 | + if( !$sdate ){ |
| 134 | + $sd = explode('-',$matches[1]); |
| 135 | + $sdate = mktime( 9, 0, 0, $sd[0], $sd[1], intval('20'.$sd[2]) ); |
| 136 | + } |
| 137 | + if( date('d-y', $stream->date_start_time) != date('d-y',$sdate) || $force_update ) { |
56 | 138 | //print "should update date: " . $stream->date_start_time . ' to '. $sdate . ' for ' . $stream->name . "\n"; |
57 | 139 | $dbw = wfGetDB( DB_WRITE ); |
58 | 140 | $sql = "UPDATE `mv_streams` SET `date_start_time`= '$sdate' " . |
— | — | @@ -60,24 +142,14 @@ |
61 | 143 | print "$stream->name date updated\n"; |
62 | 144 | }else{ |
63 | 145 | print "$stream->name date is ok\n"; |
64 | | - } |
65 | | - |
| 146 | + } |
66 | 147 | } |
67 | 148 | } |
68 | 149 | function do_stream_file_check( $old_stream=false ) { |
69 | 150 | global $mvgIP, $mvVideoArchivePaths; |
70 | 151 | $stream_set = Array(); |
71 | 152 | if($old_stream==false){ |
72 | | - $dbr = wfGetDB( DB_READ ); |
73 | | - $result = $dbr->select( 'mv_streams', |
74 | | - array('name','state','date_start_time','duration'), |
75 | | - '', |
76 | | - __METHOD__, |
77 | | - array('LIMIT'=> 9000)); |
78 | | - if ( $dbr->numRows( $result ) == 0 )die("do_stream_file_check: no streams found"); |
79 | | - while ( $row = $dbr->fetchObject( $result ) ) { |
80 | | - $stream_set[] = $row; |
81 | | - } |
| 153 | + $stream_set = get_all_mv_streams(); |
82 | 154 | }else{ |
83 | 155 | $stream_set = Array( $old_stream ); |
84 | 156 | } |
Index: trunk/extensions/MetavidWiki/includes/MV_Stream.php |
— | — | @@ -61,16 +61,6 @@ |
62 | 62 | function doesStreamExist() { |
63 | 63 | return $this->db_load_stream(); |
64 | 64 | } |
65 | | - // removes the stream from the db: |
66 | | - function deleteDB() { |
67 | | - $dbw = & wfGetDB( DB_WRITE ); |
68 | | - //remove any MVD index items: |
69 | | - MV_Index::remove_by_stream_id( $this->id ); |
70 | | - //remove any digest |
71 | | - $dbw->delete('mv_clipview_digest', array('stream_id'=> $this->id )); |
72 | | - //remove mv_streams |
73 | | - $dbw->delete( 'mv_streams', array( 'id' => $this->id ) ); |
74 | | - } |
75 | 65 | function db_load_stream() { |
76 | 66 | $dbr = & wfGetDB( DB_SLAVE ); |
77 | 67 | if ( $this->name != '' ) { |
— | — | @@ -231,8 +221,24 @@ |
232 | 222 | $article->doDelete( 'parent stream removed' ); |
233 | 223 | } |
234 | 224 | } |
| 225 | + //remove the stream db entries and images: |
| 226 | + $this->deleteDB(); |
235 | 227 | return true; |
236 | 228 | } |
| 229 | + // removes the stream from the db: |
| 230 | + function deleteDB() { |
| 231 | + $dbw = & wfGetDB( DB_WRITE ); |
| 232 | + //remove any MVD index items: |
| 233 | + MV_Index::remove_by_stream_id( $this->id ); |
| 234 | + //remove any digest |
| 235 | + $dbw->delete('mv_clipview_digest', array('stream_id'=> $this->id )); |
| 236 | + //remove any images |
| 237 | + $dbw->delete('mv_stream_images', array('stream_id' => $this->id)); |
| 238 | + //remove pointers to any files: |
| 239 | + $dbw->delete('mv_stream_images', array('stream_id' => $this->id)); |
| 240 | + //remove mv_streams |
| 241 | + $dbw->delete( 'mv_stream_files', array( 'stream_id' => $this->id )); |
| 242 | + } |
237 | 243 | function updateStreamDB() { |
238 | 244 | $dbw = & wfGetDB( DB_WRITE ); |
239 | 245 | $dbw->update( 'mv_streams', array( |
Index: trunk/extensions/MetavidWiki/includes/MV_MagicWords.php |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | $dbr = & wfGetDB( DB_READ ); |
150 | 150 | $o = ''; |
151 | 151 | $vars = array( 'query_key', 'stream_id', 'start_time', 'end_time', 'COUNT(1) as hit_count' ); |
152 | | - $conds = array( 'view_date >=' . $dbr->addQuotes( $this->getStartTime() ) ); |
| 152 | + $conds = array( 'view_date >=' . $dbr->addQuotes( $this->getStartTime() ) ); |
153 | 153 | $options = array( 'GROUP BY' => 'query_key', 'ORDER BY' => '`hit_count` DESC ', |
154 | 154 | 'LIMIT' => intval( $this->params['num_results'] ) ); |
155 | 155 | $result = $dbr->select( 'mv_clipview_digest', |