Index: trunk/phase3/maintenance/deleteArchivedRevisions.inc |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php
|
3 | 3 |
|
4 | 4 | /**
|
5 | | - * Support functions for the deleteOldRevisions script
|
| 5 | + * Support functions for the deleteArchivedRevisions script
|
6 | 6 | *
|
7 | 7 | * @addtogroup Maintenance
|
8 | 8 | * @author Aaron Schulz
|
Index: trunk/phase3/maintenance/deleteArchivedRevisions.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php
|
3 | 3 |
|
4 | 4 | /**
|
5 | | - * Delete old (non-current) revisions from the database
|
| 5 | + * Delete arcived (deleted from public) revisions from the database
|
6 | 6 | *
|
7 | 7 | * @addtogroup Maintenance
|
8 | 8 | * @author Aaron Schulz
|
Index: trunk/phase3/maintenance/deleteArchivedFiles.inc |
— | — | @@ -0,0 +1,61 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * Support functions for the deleteArchivedFiles script
|
| 6 | + *
|
| 7 | + * @addtogroup Maintenance
|
| 8 | + * @author Aaron Schulz
|
| 9 | + */
|
| 10 | +
|
| 11 | +require_once( "$IP/includes/FileStore.php" );
|
| 12 | +
|
| 13 | +function DeleteArchivedFiles( $delete = false ) {
|
| 14 | +
|
| 15 | + # Data should come off the master, wrapped in a transaction
|
| 16 | + $dbw = wfGetDB( DB_MASTER );
|
| 17 | + $dbw->begin();
|
| 18 | +
|
| 19 | + $transaction = new FSTransaction();
|
| 20 | + if( !FileStore::lock() ) {
|
| 21 | + wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
|
| 22 | + return false;
|
| 23 | + }
|
| 24 | +
|
| 25 | + $tbl_arch = $dbw->tableName( 'filearchive' );
|
| 26 | +
|
| 27 | + # Get "active" revisions from the filearchive table
|
| 28 | + echo( "Searching for and deleting archived files...\n" );
|
| 29 | + $res = $dbw->query( "SELECT fa_storage_group,fa_storage_key FROM $tbl_arch" );
|
| 30 | + while( $row = $dbw->fetchObject( $res ) ) {
|
| 31 | + $key = $row->fa_storage_key;
|
| 32 | + $group = $row->fa_storage_group;
|
| 33 | +
|
| 34 | + $store = FileStore::get( $group );
|
| 35 | + if ( $store ) {
|
| 36 | + $path = $store->filePath( $key );
|
| 37 | + if ( $path && file_exists($path) ) {
|
| 38 | + $transaction->addCommit( FSTransaction::DELETE_FILE, $path );
|
| 39 | + } else {
|
| 40 | + echo( "Notice - file '$key' not found in group '$group'\n" );
|
| 41 | + }
|
| 42 | + } else {
|
| 43 | + echo( "Notice - invalid file storage group '$group'\n" );
|
| 44 | + }
|
| 45 | + }
|
| 46 | + echo( "done.\n" );
|
| 47 | +
|
| 48 | + $transaction->commit();
|
| 49 | +
|
| 50 | +
|
| 51 | + # Delete as appropriate
|
| 52 | + echo( "Deleting filearchive rows..." );
|
| 53 | + $dbw->query( "TRUNCATE TABLE $tbl_arch" );
|
| 54 | + echo( "done.\n" );
|
| 55 | +
|
| 56 | + # This bit's done
|
| 57 | + # Purge redundant text records
|
| 58 | + $dbw->commit();
|
| 59 | +
|
| 60 | +}
|
| 61 | +
|
| 62 | +?> |
\ No newline at end of file |
Index: trunk/phase3/maintenance/deleteArchivedFiles.php |
— | — | @@ -0,0 +1,31 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * Delete archived (non-current) files from the database
|
| 6 | + *
|
| 7 | + * @addtogroup Maintenance
|
| 8 | + * @author Aaron Schulz
|
| 9 | + * Based on deleteOldRevisions.php by Rob Church
|
| 10 | + */
|
| 11 | +
|
| 12 | +$options = array( 'delete', 'help' );
|
| 13 | +require_once( 'commandLine.inc' );
|
| 14 | +require_once( 'deleteArchivedFiles.inc' );
|
| 15 | +
|
| 16 | +echo( "Delete Archived Images\n\n" );
|
| 17 | +
|
| 18 | +if( @$options['help'] ) {
|
| 19 | + ShowUsage();
|
| 20 | +} else {
|
| 21 | + DeleteArchivedFiles( @$options['delete'] );
|
| 22 | +}
|
| 23 | +
|
| 24 | +function ShowUsage() {
|
| 25 | + echo( "Deletes all archived images.\n\n" );
|
| 26 | + echo( "These images will no longer be restorable.\n\n" );
|
| 27 | + echo( "Usage: php deleteArchivedRevisions.php [--delete|--help]\n\n" );
|
| 28 | + echo( "delete : Performs the deletion\n" );
|
| 29 | + echo( " help : Show this usage information\n" );
|
| 30 | +}
|
| 31 | +
|
| 32 | +?> |
\ No newline at end of file |