Index: trunk/extensions/Score/Score.body.php |
— | — | @@ -383,19 +383,11 @@ |
384 | 384 | $multiFormat = "$filePrefix-%d.png"; |
385 | 385 | |
386 | 386 | /* delete old files if necessary */ |
387 | | - $rc = true; |
388 | | - if ( file_exists( $midi ) ) { |
389 | | - $rc = $rc && unlink( $midi ); |
390 | | - } |
391 | | - if ( file_exists( $image ) ) { |
392 | | - $rc = $rc && unlink( $image ); |
393 | | - } |
| 387 | + self::cleanupFile( $midi ); |
| 388 | + self::cleanupFile( $image ); |
394 | 389 | for ( $i = 1; file_exists( $f = sprintf( $multiFormat, $i ) ); ++$i ) { |
395 | | - $rc = $rc && unlink( $f ); |
| 390 | + self::cleanupFile( $f ); |
396 | 391 | } |
397 | | - if ( !$rc ) { |
398 | | - throw new ScoreException( wfMessage( 'score-cleanerr' ) ); |
399 | | - } |
400 | 392 | |
401 | 393 | /* Create the working environment */ |
402 | 394 | self::createFactory( $factoryDirectory ); |
— | — | @@ -543,6 +535,9 @@ |
544 | 536 | $midi = "$filePrefix.midi"; |
545 | 537 | $ogg = "$filePrefix.ogg"; |
546 | 538 | |
| 539 | + /* Delete old file if necessary */ |
| 540 | + self::cleanupFile( $ogg ); |
| 541 | + |
547 | 542 | /* Run timidity */ |
548 | 543 | if ( !is_executable( $wgScoreTimidity ) ) { |
549 | 544 | throw new ScoreException( wfMessage( 'score-timiditynotexecutable', $wgScoreTimidity ) ); |
— | — | @@ -581,6 +576,10 @@ |
582 | 577 | |
583 | 578 | $ly = "$filePrefix.ly"; |
584 | 579 | |
| 580 | + /* Delete old file if necessary */ |
| 581 | + self::cleanupFile( $ly ); |
| 582 | + |
| 583 | + /* Generate LilyPond code by score language */ |
585 | 584 | switch ( $options['lang'] ) { |
586 | 585 | case 'ABC': |
587 | 586 | $lilypondCode = self::generateLilypondFromAbc( $code, $factoryDirectory ); |
— | — | @@ -591,6 +590,7 @@ |
592 | 591 | throw new MWException( 'Unknown score language in ' . __METHOD__ . ". This should not happen.\n" ); |
593 | 592 | } |
594 | 593 | |
| 594 | + /* Create LilyPond file and return the code */ |
595 | 595 | $rc = file_put_contents( $ly, $lilypondCode ); |
596 | 596 | if ( $rc === false ) { |
597 | 597 | self::debug( "Unable to write LilyPond code to $ly.\n" ); |
— | — | @@ -709,6 +709,23 @@ |
710 | 710 | } |
711 | 711 | |
712 | 712 | /** |
| 713 | + * Deletes a file if it exists. |
| 714 | + * |
| 715 | + * @param $path string path to the file to be deleted. |
| 716 | + * |
| 717 | + * @throws ScoreException if the file specified by $path exists but |
| 718 | + * could not be deleted. |
| 719 | + */ |
| 720 | + private static function cleanupFile( $path ) { |
| 721 | + if ( file_exists( $path ) ) { |
| 722 | + $rc = unlink( $path ); |
| 723 | + if ( !$rc ) { |
| 724 | + throw new ScoreException( wfMessage( 'score-cleanerr' ) ); |
| 725 | + } |
| 726 | + } |
| 727 | + } |
| 728 | + |
| 729 | + /** |
713 | 730 | * Writes the specified message to the Score debug log. |
714 | 731 | * |
715 | 732 | * @param $msg string message to log. |