r46820 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46819‎ | r46820 | r46821 >
Date:22:15, 4 February 2009
Author:dale
Status:deferred
Tags:
Comment:
maintenance updates for stream removal
Modified paths:
  • /trunk/extensions/MetavidWiki/includes/MV_MagicWords.php (modified) (history)
  • /trunk/extensions/MetavidWiki/includes/MV_Stream.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.php (modified) (history)
  • /trunk/extensions/MetavidWiki/maintenance/video_ocr_thumb_insert.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetavidWiki/maintenance/video_ocr_thumb_insert.php
@@ -73,7 +73,7 @@
7474 class streamObject{ };
7575 $stream = new streamObject();
7676 $stream->name = $stream_name;
77 -$stream->org_start_time = $org_start_time;
 77+$stream->date_start_time = $org_start_time;
7878 $stream->sync_status = 'in_sync';
7979 $stream->duration = $duration;
8080
Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.php
@@ -95,6 +95,7 @@
9696 'update_templates' will update templates & some semantic properties
9797 'file_check' checks inserted streams file urls/pointers
9898 'do_stream_date_check'
 99+ 'do_remove_orphaned_streams'
99100
100101 EOT;
101102 exit ();
@@ -137,6 +138,9 @@
138139 case 'do_stream_date_check':
139140 do_stream_date_check();
140141 break;
 142+ case 'do_remove_orphaned_streams':
 143+ do_remove_orphaned_streams();
 144+ break;
141145 case 'update_templates' :
142146 $force = ( isset( $options['force'] ) ) ? true:false;
143147 include_once( 'metavid_gov_templates.php' );
Index: trunk/extensions/MetavidWiki/maintenance/metavid2mvWiki.inc.php
@@ -34,24 +34,106 @@
3535 // if($i==3)die;
3636 // $i++;
3737 }
38 -function do_stream_date_check(){
 38+function get_all_mv_streams(){
3939 $dbr = wfGetDB( DB_READ );
 40+ $streams = array();
4041 $result = $dbr->select( 'mv_streams',
4142 '*',
4243 '',
 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+ '',
4361 __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 ) {
48112 preg_match("/([0-9]+-[0-9]+-[0-9]+)/", $stream->name, $matches);
49113 if( ! isset( $matches[1] ) ){
50114 print "no date found in {$stream->name}\n";
51115 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 ) {
56138 //print "should update date: " . $stream->date_start_time . ' to '. $sdate . ' for ' . $stream->name . "\n";
57139 $dbw = wfGetDB( DB_WRITE );
58140 $sql = "UPDATE `mv_streams` SET `date_start_time`= '$sdate' " .
@@ -60,24 +142,14 @@
61143 print "$stream->name date updated\n";
62144 }else{
63145 print "$stream->name date is ok\n";
64 - }
65 -
 146+ }
66147 }
67148 }
68149 function do_stream_file_check( $old_stream=false ) {
69150 global $mvgIP, $mvVideoArchivePaths;
70151 $stream_set = Array();
71152 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();
82154 }else{
83155 $stream_set = Array( $old_stream );
84156 }
Index: trunk/extensions/MetavidWiki/includes/MV_Stream.php
@@ -61,16 +61,6 @@
6262 function doesStreamExist() {
6363 return $this->db_load_stream();
6464 }
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 - }
7565 function db_load_stream() {
7666 $dbr = & wfGetDB( DB_SLAVE );
7767 if ( $this->name != '' ) {
@@ -231,8 +221,24 @@
232222 $article->doDelete( 'parent stream removed' );
233223 }
234224 }
 225+ //remove the stream db entries and images:
 226+ $this->deleteDB();
235227 return true;
236228 }
 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+ }
237243 function updateStreamDB() {
238244 $dbw = & wfGetDB( DB_WRITE );
239245 $dbw->update( 'mv_streams', array(
Index: trunk/extensions/MetavidWiki/includes/MV_MagicWords.php
@@ -148,7 +148,7 @@
149149 $dbr = & wfGetDB( DB_READ );
150150 $o = '';
151151 $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() ) );
153153 $options = array( 'GROUP BY' => 'query_key', 'ORDER BY' => '`hit_count` DESC ',
154154 'LIMIT' => intval( $this->params['num_results'] ) );
155155 $result = $dbr->select( 'mv_clipview_digest',

Status & tagging log