MediaWiki  master
DumpFileOutput.php
Go to the documentation of this file.
1 <?php
29 class DumpFileOutput extends DumpOutput {
31  protected $handle = false;
33  protected $filename;
34 
38  function __construct( $file ) {
39  $this->handle = fopen( $file, "wt" );
40  $this->filename = $file;
41  }
42 
46  function writeCloseStream( $string ) {
47  parent::writeCloseStream( $string );
48  if ( $this->handle ) {
49  fclose( $this->handle );
50  $this->handle = false;
51  }
52  }
53 
57  function write( $string ) {
58  fputs( $this->handle, $string );
59  }
60 
64  function closeRenameAndReopen( $newname ) {
65  $this->closeAndRename( $newname, true );
66  }
67 
72  function renameOrException( $newname ) {
73  if ( !rename( $this->filename, $newname ) ) {
74  throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
75  }
76  }
77 
83  function checkRenameArgCount( $newname ) {
84  if ( is_array( $newname ) ) {
85  if ( count( $newname ) > 1 ) {
86  throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" );
87  } else {
88  $newname = $newname[0];
89  }
90  }
91  return $newname;
92  }
93 
97  function closeAndRename( $newname, $open = false ) {
98  $newname = $this->checkRenameArgCount( $newname );
99  if ( $newname ) {
100  if ( $this->handle ) {
101  fclose( $this->handle );
102  $this->handle = false;
103  }
104  $this->renameOrException( $newname );
105  if ( $open ) {
106  $this->handle = fopen( $this->filename, "wt" );
107  }
108  }
109  }
110 
114  function getFilenames() {
115  return $this->filename;
116  }
117 }
closeAndRename( $newname, $open=false)
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
closeRenameAndReopen( $newname)
renameOrException( $newname)
resource false $handle
checkRenameArgCount( $newname)
writeCloseStream( $string)