Protected function UploadBase->validateName changed to public
[lhc/web/wiklou.git] / includes / MessageBlobStore.php
index 34014e1..6322be7 100644 (file)
@@ -80,42 +80,45 @@ class MessageBlobStore {
                        return false;
                }
 
-               $dbw = wfGetDB( DB_MASTER );
-               $success = $dbw->insert( 'msg_resource', array(
-                               'mr_lang' => $lang,
-                               'mr_resource' => $name,
-                               'mr_blob' => $blob,
-                               'mr_timestamp' => $dbw->timestamp()
-                       ),
-                       __METHOD__,
-                       array( 'IGNORE' )
-               );
-
-               if ( $success ) {
-                       if ( $dbw->affectedRows() == 0 ) {
-                               // Blob was already present, fetch it
-                               $blob = $dbw->selectField( 'msg_resource', 'mr_blob', array(
-                                               'mr_resource' => $name,
-                                               'mr_lang' => $lang,
-                                       ),
-                                       __METHOD__
-                               );
-                       } else {
-                               // Update msg_resource_links
-                               $rows = array();
+               try {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $success = $dbw->insert( 'msg_resource', array(
+                                       'mr_lang' => $lang,
+                                       'mr_resource' => $name,
+                                       'mr_blob' => $blob,
+                                       'mr_timestamp' => $dbw->timestamp()
+                               ),
+                               __METHOD__,
+                               array( 'IGNORE' )
+                       );
 
-                               foreach ( $module->getMessages() as $key ) {
-                                       $rows[] = array(
-                                               'mrl_resource' => $name,
-                                               'mrl_message' => $key
+                       if ( $success ) {
+                               if ( $dbw->affectedRows() == 0 ) {
+                                       // Blob was already present, fetch it
+                                       $blob = $dbw->selectField( 'msg_resource', 'mr_blob', array(
+                                                       'mr_resource' => $name,
+                                                       'mr_lang' => $lang,
+                                               ),
+                                               __METHOD__
+                                       );
+                               } else {
+                                       // Update msg_resource_links
+                                       $rows = array();
+
+                                       foreach ( $module->getMessages() as $key ) {
+                                               $rows[] = array(
+                                                       'mrl_resource' => $name,
+                                                       'mrl_message' => $key
+                                               );
+                                       }
+                                       $dbw->insert( 'msg_resource_links', $rows,
+                                               __METHOD__, array( 'IGNORE' )
                                        );
                                }
-                               $dbw->insert( 'msg_resource_links', $rows,
-                                       __METHOD__, array( 'IGNORE' )
-                               );
                        }
+               } catch ( Exception $e ) {
+                       wfDebug( __METHOD__ . " failed to update DB: $e\n" );
                }
-
                return $blob;
        }
 
@@ -140,49 +143,52 @@ class MessageBlobStore {
                // Save the old and new blobs for later
                $oldBlob = $row->mr_blob;
                $newBlob = self::generateMessageBlob( $module, $lang );
-               
-               $newRow = array(
-                       'mr_resource' => $name,
-                       'mr_lang' => $lang,
-                       'mr_blob' => $newBlob,
-                       'mr_timestamp' => $dbw->timestamp()
-               );
 
-               $dbw->replace( 'msg_resource',
-                       array( array( 'mr_resource', 'mr_lang' ) ),
-                       $newRow, __METHOD__
-               );
-
-               // Figure out which messages were added and removed
-               $oldMessages = array_keys( FormatJson::decode( $oldBlob, true ) );
-               $newMessages = array_keys( FormatJson::decode( $newBlob, true ) );
-               $added = array_diff( $newMessages, $oldMessages );
-               $removed = array_diff( $oldMessages, $newMessages );
+               try {
+                       $newRow = array(
+                               'mr_resource' => $name,
+                               'mr_lang' => $lang,
+                               'mr_blob' => $newBlob,
+                               'mr_timestamp' => $dbw->timestamp()
+                       );
 
-               // Delete removed messages, insert added ones
-               if ( $removed ) {
-                       $dbw->delete( 'msg_resource_links', array(
-                                       'mrl_resource' => $name,
-                                       'mrl_message' => $removed
-                               ), __METHOD__
+                       $dbw->replace( 'msg_resource',
+                               array( array( 'mr_resource', 'mr_lang' ) ),
+                               $newRow, __METHOD__
                        );
-               }
 
-               $newLinksRows = array();
+                       // Figure out which messages were added and removed
+                       $oldMessages = array_keys( FormatJson::decode( $oldBlob, true ) );
+                       $newMessages = array_keys( FormatJson::decode( $newBlob, true ) );
+                       $added = array_diff( $newMessages, $oldMessages );
+                       $removed = array_diff( $oldMessages, $newMessages );
 
-               foreach ( $added as $message ) {
-                       $newLinksRows[] = array(
-                               'mrl_resource' => $name,
-                               'mrl_message' => $message
-                       );
-               }
+                       // Delete removed messages, insert added ones
+                       if ( $removed ) {
+                               $dbw->delete( 'msg_resource_links', array(
+                                               'mrl_resource' => $name,
+                                               'mrl_message' => $removed
+                                       ), __METHOD__
+                               );
+                       }
 
-               if ( $newLinksRows ) {
-                       $dbw->insert( 'msg_resource_links', $newLinksRows, __METHOD__,
-                                array( 'IGNORE' ) // just in case
-                       );
-               }
+                       $newLinksRows = array();
+
+                       foreach ( $added as $message ) {
+                               $newLinksRows[] = array(
+                                       'mrl_resource' => $name,
+                                       'mrl_message' => $message
+                               );
+                       }
 
+                       if ( $newLinksRows ) {
+                               $dbw->insert( 'msg_resource_links', $newLinksRows, __METHOD__,
+                                       array( 'IGNORE' ) // just in case
+                               );
+                       }
+               } catch ( Exception $e ) {
+                       wfDebug( __METHOD__ . " failed to update DB: $e\n" );
+               }
                return $newBlob;
        }
 
@@ -192,50 +198,58 @@ class MessageBlobStore {
         * @param $key String: message key
         */
        public static function updateMessage( $key ) {
-               $dbw = wfGetDB( DB_MASTER );
-
-               // Keep running until the updates queue is empty.
-               // Due to update conflicts, the queue might not be emptied
-               // in one iteration.
-               $updates = null;
-               do {
-                       $updates = self::getUpdatesForMessage( $key, $updates );
-
-                       foreach ( $updates as $k => $update ) {
-                               // Update the row on the condition that it
-                               // didn't change since we fetched it by putting
-                               // the timestamp in the WHERE clause.
-                               $success = $dbw->update( 'msg_resource',
-                                       array(
-                                               'mr_blob' => $update['newBlob'],
-                                               'mr_timestamp' => $dbw->timestamp() ),
-                                       array(
-                                               'mr_resource' => $update['resource'],
-                                               'mr_lang' => $update['lang'],
-                                               'mr_timestamp' => $update['timestamp'] ),
-                                       __METHOD__
-                               );
+               try {
+                       $dbw = wfGetDB( DB_MASTER );
+
+                       // Keep running until the updates queue is empty.
+                       // Due to update conflicts, the queue might not be emptied
+                       // in one iteration.
+                       $updates = null;
+                       do {
+                               $updates = self::getUpdatesForMessage( $key, $updates );
+
+                               foreach ( $updates as $k => $update ) {
+                                       // Update the row on the condition that it
+                                       // didn't change since we fetched it by putting
+                                       // the timestamp in the WHERE clause.
+                                       $success = $dbw->update( 'msg_resource',
+                                               array(
+                                                       'mr_blob' => $update['newBlob'],
+                                                       'mr_timestamp' => $dbw->timestamp() ),
+                                               array(
+                                                       'mr_resource' => $update['resource'],
+                                                       'mr_lang' => $update['lang'],
+                                                       'mr_timestamp' => $update['timestamp'] ),
+                                               __METHOD__
+                                       );
 
-                               // Only requeue conflicted updates.
-                               // If update() returned false, don't retry, for
-                               // fear of getting into an infinite loop
-                               if ( !( $success && $dbw->affectedRows() == 0 ) ) {
-                                       // Not conflicted
-                                       unset( $updates[$k] );
+                                       // Only requeue conflicted updates.
+                                       // If update() returned false, don't retry, for
+                                       // fear of getting into an infinite loop
+                                       if ( !( $success && $dbw->affectedRows() == 0 ) ) {
+                                               // Not conflicted
+                                               unset( $updates[$k] );
+                                       }
                                }
-                       }
-               } while ( count( $updates ) );
+                       } while ( count( $updates ) );
 
-               // No need to update msg_resource_links because we didn't add
-               // or remove any messages, we just changed their contents.
+                       // No need to update msg_resource_links because we didn't add
+                       // or remove any messages, we just changed their contents.
+               } catch ( Exception $e ) {
+                       wfDebug( __METHOD__ . " failed to update DB: $e\n" );
+               }
        }
 
        public static function clear() {
                // TODO: Give this some more thought
                // TODO: Is TRUNCATE better?
-               $dbw = wfGetDB( DB_MASTER );
-               $dbw->delete( 'msg_resource', '*', __METHOD__ );
-               $dbw->delete( 'msg_resource_links', '*', __METHOD__ );
+               try {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $dbw->delete( 'msg_resource', '*', __METHOD__ );
+                       $dbw->delete( 'msg_resource_links', '*', __METHOD__ );
+               } catch ( Exception $e ) {
+                       wfDebug( __METHOD__ . " failed to update DB: $e\n" );
+               }
        }
 
        /**
@@ -311,6 +325,7 @@ class MessageBlobStore {
         * @param $resourceLoader ResourceLoader object
         * @param $modules Array of module names
         * @param $lang String: language code
+        * @throws MWException
         * @return array Array mapping module names to blobs
         */
        private static function getFromDB( ResourceLoader $resourceLoader, $modules, $lang ) {