http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89979

Revision: 89979
Author:   dale
Date:     2011-06-13 16:44:26 +0000 (Mon, 13 Jun 2011)
Log Message:
-----------
bug 29179 on complete new upload that is a transcodable file, clear transcode 
state  
Also added a hook to remove old transcode files, when a file is moved

Modified Paths:
--------------
    trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php
    trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
    trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
    
trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php

Modified: trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php
===================================================================
--- trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php    2011-06-13 
16:36:16 UTC (rev 89978)
+++ trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php    2011-06-13 
16:44:26 UTC (rev 89979)
@@ -35,8 +35,7 @@
                if( !TimedMediaHandlerHooks::isTranscodableTitle( $titleObj ) ){
                        $this->dieUsage( array( 'invalidtranscodetitle', 
$params['title'] ) );
                }
-               $file = wfFindFile( $titleObj );
-               WebVideoTranscode::removeTranscodeJobs( $file, isset( 
$params['transcodekey'] )? $params['transcodekey']: false );
+               WebVideoTranscode::removeTranscodes( $titleObj, isset( 
$params['transcodekey'] )? $params['transcodekey']: false );
                
                $this->getResult()->addValue(null, 'success', 'removed 
transcode');
        }

Modified: trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php
===================================================================
--- trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php      
2011-06-13 16:36:16 UTC (rev 89978)
+++ trunk/extensions/TimedMediaHandler/TimedMediaHandler.hooks.php      
2011-06-13 16:44:26 UTC (rev 89979)
@@ -63,6 +63,12 @@
                // When an upload completes ( check clear any existing 
transcodes )
                $wgHooks['UploadComplete'][] = 
'TimedMediaHandlerHooks::checkUploadComplete';
 
+               // When an image page is moved: 
+               $wgHooks['TitleMoveComplete'][] = 
'TimedMediaHandlerHooks::checkTitleMoveComplete';
+
+               // When image page is deleted so that we remove transcode 
settings / files. 
+               $wgHooks['ArticleDeleteComplete'][] = 
'TimedMediaHandlerHooks::checkArticleDeleteComplete';
+               
                // Add parser hook
                $wgParserOutputHooks['TimedMediaHandler'] = array( 
'TimedMediaHandler', 'outputHook' );
                
@@ -70,8 +76,6 @@
                // dynamic contexts ( for example in special upload, when there 
is an "existing file" warning. )
                $wgHooks['BeforePageDisplay'][] = 
'TimedMediaHandlerHooks::pageOutputHook';
 
-               // Add a hook for article deletion so that we remove transcode 
settings / files. 
-               $wgHooks['ArticleDeleteComplete'][] = 
'TimedMediaHandlerHooks::checkArticleDeleteComplete';
                
                // Exclude transcoded assets from normal thumbnail purging
                // ( a maintenance script could handle transcode asset purging)
@@ -159,17 +163,35 @@
                return true;
        }
        public static function checkUploadComplete( &$image ){
-               if( self::isTranscodableTitle( $image->getTitle() ) ){
-                       // clear transcode data:
+               $title = $image->getTitle();
+               // Check that the file is a transcodable asset:
+               if( self::isTranscodableTitle( $title ) ){
+                       // Remove all the transcode files and db states for 
this asset ( will be re-added the first time the asset is displayed )
+                       WebVideoTranscode::removeTranscodes( $title );
                }
                return true;
        }
+       /**
+        * Handle moved titles
+        * 
+        * For now we just remove all the derivatives for the oldTitle. In the 
future we could
+        * look at moving the files, but right now thumbs are not moved, so I 
don't want to be 
+        * inconsistent.
+        */
+       public static function checkTitleMoveComplete( &$title, &$newTitle, 
&$user, $oldid, $newid ){
+               if( self::isTranscodableTitle( $title ) ){
+                       // Remove all the transcode files and db states for 
this asset 
+                       // ( will be re-added the first time the asset is 
displayed with its new title )
+                       WebVideoTranscode::removeTranscodes( $title );
+               }
+               return true;
+       }
        public static function checkArticleDeleteComplete( &$article, &$user, 
$reason, $id  ){
-               // Check if the article is a file and remove transcode jobs:
+               // Check if the article is a file and remove transcode files:
                if( $article->getTitle()->getNamespace() == NS_FILE ) {
                        $file = wfFindFile( $article->getTitle() );
                        if( self::isTranscodableFile( $file ) ){
-                               WebVideoTranscode::removeTranscodeJobs( $file );
+                               WebVideoTranscode::removeTranscodes( $file );
                        }
                } 
                return true;

Modified: 
trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php
===================================================================
--- trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php  
2011-06-13 16:36:16 UTC (rev 89978)
+++ trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscode.php  
2011-06-13 16:44:26 UTC (rev 89979)
@@ -395,15 +395,15 @@
        }
        
        /**
-        * Remove any transcode jobs associated with a given $fileName
+        * Remove any transcode files and db states associated with a given 
$title
         * 
         * also remove the transcode files: 
-        * @param $file File Object
+        * @param $titleObj Title Object
         * @param $transcodeKey String Optional transcode key to remove only 
this key
         */
-       public static function removeTranscodeJobs( &$file, $transcodeKey = 
false ){
-               $titleObj = $file->getTitle();
-               print " \n\n " . $titleObj->getDBKey() . "\n\n";
+       public static function removeTranscodes( &$titleObj, $transcodeKey = 
false ){
+               $file = wfFindFile($titleObj );
+               
                // if transcode key is non-false, non-null:
                if( $transcodeKey ){
                        // only remove the requested $transcodeKey
@@ -441,13 +441,13 @@
                $dbw->delete( 'transcode', $deleteWhere, __METHOD__ );
                
                // Purge the cache for pages that include this video: 
-               self::invalidatePagesWithAsset( $titleObj );
+               self::invalidatePagesWithFile( $titleObj );
 
                // Remove from local WebVideoTranscode cache:
                self::clearTranscodeCache(  $titleObj->getDBKey()  );
        }
        
-       public static function invalidatePagesWithAsset( &$titleObj ){
+       public static function invalidatePagesWithFile( &$titleObj ){
                wfDebug("WebVideoTranscode:: Invalidate pages that include: " . 
$titleObj->getDBKey() );
                // Purge the main image page: 
                $titleObj->invalidateCache();

Modified: 
trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
===================================================================
--- 
trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php   
    2011-06-13 16:36:16 UTC (rev 89978)
+++ 
trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php   
    2011-06-13 16:44:26 UTC (rev 89979)
@@ -114,8 +114,8 @@
                );
                
                // Check for ( hopefully rare ) issue of or job restarted while 
transcode in progress
-               if( $jobStartTimeCache != $dbStartTime ){
-                       wfDebug('Possible Error, transcode task restarted, 
removed, or completed while transcode was in progress');
+               if(  $db->timestamp( $jobStartTimeCache ) != $db->timestamp( 
$dbStartTime ) ){
+                       $this->output('Possible Error, transcode task 
restarted, removed, or completed while transcode was in progress');
                        // if an error; just error out, we can't remove temp 
files or update states, because the new job may be doing stuff.
                        if( $status !== true ){
                                return false;   
@@ -145,7 +145,7 @@
                                __METHOD__,
                                array( 'LIMIT' => 1 )
                        );                      
-                       WebVideoTranscode::invalidatePagesWithAsset( 
$this->title );
+                       WebVideoTranscode::invalidatePagesWithFile( 
$this->title );
                } else {
                        // Update the transcode table with failure time and 
error 
                        $dbw->update( 
@@ -161,7 +161,9 @@
                                __METHOD__,
                                array( 'LIMIT' => 1 )
                        );
-                       // no need to invalidate cache. Because all pages 
remain valid ( no $transcodeKey derivative ) 
+                       // no need to invalidate all pages with video. Because 
all pages remain valid ( no $transcodeKey derivative ) 
+                       // just clear the file page ( so that the transcode 
table shows the error )
+                       $this->title->invalidateCache();
                }
                // Clear the webVideoTranscode cache ( so we don't keep out 
dated table cache around ) 
                webVideoTranscode::clearTranscodeCache( 
$this->title->getDBkey() );
@@ -251,7 +253,7 @@
                wfProfileOut( 'ffmpeg_encode' );
 
                if( $retval ){
-                       return $shellOutput;
+                       return $cmd . "\n\n" . $shellOutput;
                }
                return true;
        }
@@ -381,7 +383,7 @@
                wfProfileOut( 'ffmpeg2theora_encode' );
 
                if( $retval ){
-                       return $shellOutput;
+                       return $cmd . "\n\n" . $shellOutput;
                }
                return true;
        }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to