diff options
Diffstat (limited to 'extensions/TimedMediaHandler/maintenance')
4 files changed, 198 insertions, 0 deletions
diff --git a/extensions/TimedMediaHandler/maintenance/cleanupTranscodes.php b/extensions/TimedMediaHandler/maintenance/cleanupTranscodes.php new file mode 100644 index 00000000..01c7b004 --- /dev/null +++ b/extensions/TimedMediaHandler/maintenance/cleanupTranscodes.php @@ -0,0 +1,46 @@ +<?php +/** + * cleanup transcodes no longer defined in $wgEnabledTranscodeSet + * + */ +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = dirname( __FILE__ ) . '/../../..'; +} +require_once( "$IP/maintenance/Maintenance.php" ); + +class CleanupTranscodes extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->addOption( "key", "remove all transcodes for given key", false, true ); + $this->addOption( "all", "remove all transcodes", false, false ); + $this->mDescription = "cleanup transcodes left over after changing encoding profiles."; + } + public function execute() { + global $wgEnabledTranscodeSet; + + if ( $this->hasOption( "all" ) ) { + $where = array(); + } elseif ( $this->hasOption( "key" ) ) { + $where = array( 'transcode_key' => $this->getOption( 'key' ) ); + } else { + $where = 'transcode_key NOT IN ("'. implode('", "', $wgEnabledTranscodeSet ).'")'; + } + $this->output( "Cleanup transcodes:\n" ); + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( 'transcode', '*', $where, __METHOD__ ); + foreach ( $res as $row ) { + $this->output( + 'remove: '. $row->transcode_image_name . ' ' . $row->transcode_key . "\n" + ); + $title = Title::newFromText( $row->transcode_image_name, NS_FILE ); + $file = wfLocalFile( $title ); + WebVideoTranscode::removeTranscodes( $file, $row->transcode_key ); + } + $this->output( "Finished!\n" ); + } +} + +$maintClass = 'CleanupTranscodes'; // Tells it to run the class +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/extensions/TimedMediaHandler/maintenance/moveTranscoded.php b/extensions/TimedMediaHandler/maintenance/moveTranscoded.php new file mode 100644 index 00000000..1ff6717c --- /dev/null +++ b/extensions/TimedMediaHandler/maintenance/moveTranscoded.php @@ -0,0 +1,56 @@ +<?php +/** + * move transcoded files from thumb to transcoded container + * + */ +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = dirname( __FILE__ ) . '/../../..'; +} +require_once( "$IP/maintenance/Maintenance.php" ); + +class MoveTranscoded extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->mDescription = "move transcoded files from thumb to transcoded container."; + } + public function execute() { + global $wgEnabledTranscodeSet; + + $this->output( "Move transcoded files:\n" ); + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( 'transcode', '*', array(), __METHOD__ ); + foreach ( $res as $row ) { + $title = Title::newFromText( $row->transcode_image_name, NS_FILE ); + $file = wfLocalFile( $title ); + if ( !$file ) { + continue; + } + $oldPath = $file->getThumbPath( $file->getName() . '.' . $row->transcode_key ); + + $newPath = WebVideoTranscode::getDerivativeFilePath( $file, $row->transcode_key ); + if ($oldPath != $newPath) { + if( $file->repo->fileExists( $oldPath ) ){ + if( $file->repo->fileExists( $newPath ) ){ + $res = $file->repo->quickPurge( $oldPath ); + if( !$res ){ + wfDebug( "Could not delete file $oldPath\n" ); + } else { + $this->output( "deleted $oldPath, exists in transcoded container\n" ); + } + } else { + $this->output( " $oldPath => $newPath\n" ); + $file->repo->quickImport( $oldPath, $newPath ); + $file->repo->quickPurge( $oldPath ); + } + } + } + + } + $this->output( "Finished!\n" ); + } +} + +$maintClass = 'MoveTranscoded'; // Tells it to run the class +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/extensions/TimedMediaHandler/maintenance/resetTranscodes.php b/extensions/TimedMediaHandler/maintenance/resetTranscodes.php new file mode 100644 index 00000000..ca3493ed --- /dev/null +++ b/extensions/TimedMediaHandler/maintenance/resetTranscodes.php @@ -0,0 +1,41 @@ +<?php +/** + * reset stalled transcodes + * + */ +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = dirname( __FILE__ ) . '/../../..'; +} +require_once( "$IP/maintenance/Maintenance.php" ); + +class ResetTranscodes extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->mDescription = "Reset stalled transcodes, that are no longer in the job queue."; + } + public function execute() { + global $wgEnabledTranscodeSet; + $where = array( + "transcode_time_startwork" => NULL, + "transcode_time_error" => NULL + ); + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( 'transcode', '*', $where, __METHOD__ ); + foreach ( $res as $row ) { + $title = Title::newFromText( $row->transcode_image_name, NS_FILE ); + // re-insert WebVideoTranscodeJob, + // will only be added if not in queue + // due to deduplication + $job = new WebVideoTranscodeJob( $title, array( + 'transcodeMode' => 'derivative', + 'transcodeKey' => $row->transcode_key, + ) ); + $job->insert(); + } + } +} + +$maintClass = 'ResetTranscodes'; // Tells it to run the class +require_once( RUN_MAINTENANCE_IF_MAIN ); diff --git a/extensions/TimedMediaHandler/maintenance/retryTranscodes.php b/extensions/TimedMediaHandler/maintenance/retryTranscodes.php new file mode 100644 index 00000000..be1ab9ee --- /dev/null +++ b/extensions/TimedMediaHandler/maintenance/retryTranscodes.php @@ -0,0 +1,55 @@ +<?php +/** + * Retry transcodes for a given key or error. + * This script can be used after updating/fixing + * the encoding pipeline to rerun transcodes + * that are known to work now. + * + */ +$IP = getenv( 'MW_INSTALL_PATH' ); +if ( $IP === false ) { + $IP = dirname( __FILE__ ) . '/../../..'; +} +require_once( "$IP/maintenance/Maintenance.php" ); + +class RetryTranscodes extends Maintenance { + + public function __construct() { + parent::__construct(); + $this->addOption( "key", "retry all failed transcodes for given key", false, true ); + $this->addOption( "error", "retry all failed transcodes matching error substring", false, true); + $this->mDescription = "retry transcodes for given key or error"; + } + public function execute() { + if ( !$this->hasOption( "error" ) && !$this->hasOption( "key" ) ) { + $this->output("You have to provide --key and/or --error\n"); + return; + } + $dbw = wfGetDB( DB_MASTER ); + $cond = array(); + $cond[] = 'transcode_time_error IS NOT NULL'; + if ( $this->hasOption( "key" ) ) { + $cond['transcode_key'] = $this->getOption( 'key' ); + } + if ( $this->hasOption( "error" ) ) { + $cond[] = "transcode_error " . $dbw->buildLike( $dbw->anyString(), + $this->getOption( 'error' ), $dbw->anyString() ); + } + do { + $res = $dbw->select( 'transcode', 'transcode_id', + $cond, __METHOD__, array( 'LIMIT' => 100 ) ); + $ids = array(); + foreach ( $res as $row ) { + $ids[] = $row->transcode_id; + } + if ( $ids ) { + $dbw->delete( 'transcode', + array( 'transcode_id' => $ids ), __METHOD__ ); + wfWaitForSlaves(); + } + } while ($ids); + } +} + +$maintClass = 'RetryTranscodes'; // Tells it to run the class +require_once( RUN_MAINTENANCE_IF_MAIN ); |