summaryrefslogtreecommitdiff
path: root/extensions/TimedMediaHandler/maintenance/cleanupTranscodes.php
blob: 01c7b00485755c70f89b77994625f42a1995b90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 );