More debug diagnostics for upload by URL
authorsaper <saper@saper.info>
Mon, 10 Nov 2014 23:25:54 +0000 (00:25 +0100)
committerkaldari <rkaldari@wikimedia.org>
Mon, 23 Feb 2015 21:16:23 +0000 (13:16 -0800)
Increase debug log verbosity to
troubleshoot file upload by URL issues.

Bug: 73200
Change-Id: I530bd38b85911e0c153280b7d9a9da023f799b02

includes/upload/UploadFromUrl.php

index b605640..5e418ea 100644 (file)
@@ -231,12 +231,18 @@ class UploadFromUrl extends UploadBase {
         * @return int Number of bytes handled
         */
        public function saveTempFileChunk( $req, $buffer ) {
+               wfDebugLog( 'fileupload', 'Received chunk of ' . strlen( $buffer ) . ' bytes' );
                $nbytes = fwrite( $this->mTmpHandle, $buffer );
 
                if ( $nbytes == strlen( $buffer ) ) {
                        $this->mFileSize += $nbytes;
                } else {
                        // Well... that's not good!
+                       wfDebugLog(
+                               'fileupload',
+                               'Short write ' . $this->nbytes . '/' . strlen( $buffer ) .
+                                       ' bytes, aborting with '  . $this->mFileSize . ' uploaded so far'
+                       );
                        fclose( $this->mTmpHandle );
                        $this->mTmpHandle = false;
                }
@@ -262,6 +268,7 @@ class UploadFromUrl extends UploadBase {
                if ( !$this->mTmpHandle ) {
                        return Status::newFatal( 'tmp-create-error' );
                }
+               wfDebugLog( 'fileupload', 'Temporary file created "' . $this->mTempPath . '"' );
 
                $this->mRemoveTempFile = true;
                $this->mFileSize = 0;
@@ -275,6 +282,11 @@ class UploadFromUrl extends UploadBase {
                if ( $wgCopyUploadTimeout && !isset( $options['timeout'] ) ) {
                        $options['timeout'] = $wgCopyUploadTimeout;
                }
+               wfDebugLog(
+                       'fileupload',
+                       'Starting download from "' . $this->mUrl . '" ' .
+                               '<' . implode( ',', array_keys( array_filter( $options ) ) ) . '>'
+               );
                $req = MWHttpRequest::factory( $this->mUrl, $options );
                $req->setCallback( array( $this, 'saveTempFileChunk' ) );
                $status = $req->execute();
@@ -288,8 +300,14 @@ class UploadFromUrl extends UploadBase {
                        return Status::newFatal( 'tmp-write-error' );
                }
 
-               if ( !$status->isOk() ) {
-                       return $status;
+               wfDebugLog( 'fileupload', $status );
+               if ( $status->isOk() ) {
+                       wfDebugLog( 'fileupload', 'Download by URL completed successfuly.' );
+               } else {
+                       wfDebugLog(
+                               'fileupload',
+                               'Download by URL completed with HTTP status ' . $req->getStatus()
+                       );
                }
 
                return $status;