Index: trunk/phase3/includes/MessageBlobStore.php |
— | — | @@ -117,49 +117,37 @@ |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | | - * Update all message blobs for a given module. |
| 121 | + * Update the message blob for a given module in a given language |
122 | 122 | * |
123 | 123 | * @param $name String: module name |
124 | 124 | * @param $module ResourceLoaderModule object |
125 | | - * @param $lang String: language code (optional) |
126 | | - * @return Mixed: if $lang is set, the new message blob for that language is |
127 | | - * returned if present. Otherwise, null is returned. |
| 125 | + * @param $lang String: language code |
| 126 | + * @return String Regenerated message blob, or null if there was no blob for the given module/language pair |
128 | 127 | */ |
129 | | - public static function updateModule( $name, ResourceLoaderModule $module, $lang = null ) { |
130 | | - $retval = null; |
131 | | - |
132 | | - // Find all existing blobs for this module |
| 128 | + public static function updateModule( $name, ResourceLoaderModule $module, $lang ) { |
133 | 129 | $dbw = wfGetDB( DB_MASTER ); |
134 | | - $res = $dbw->select( 'msg_resource', |
135 | | - array( 'mr_lang', 'mr_blob' ), |
136 | | - array( 'mr_resource' => $name ), |
| 130 | + $row = $dbw->selectRow( 'msg_resource', 'mr_blob', |
| 131 | + array( 'mr_resource' => $name, 'mr_lang' => $lang ), |
137 | 132 | __METHOD__ |
138 | 133 | ); |
139 | | - |
140 | | - // Build the new msg_resource rows |
141 | | - $newRows = array(); |
142 | | - $now = $dbw->timestamp(); |
143 | | - // Save the last-processed old and new blobs for later |
144 | | - $oldBlob = $newBlob = null; |
145 | | - |
146 | | - foreach ( $res as $row ) { |
147 | | - $oldBlob = $row->mr_blob; |
148 | | - $newBlob = self::generateMessageBlob( $module, $row->mr_lang ); |
149 | | - |
150 | | - if ( $row->mr_lang === $lang ) { |
151 | | - $retval = $newBlob; |
152 | | - } |
153 | | - $newRows[] = array( |
154 | | - 'mr_resource' => $name, |
155 | | - 'mr_lang' => $row->mr_lang, |
156 | | - 'mr_blob' => $newBlob, |
157 | | - 'mr_timestamp' => $now |
158 | | - ); |
| 134 | + if ( !$row ) { |
| 135 | + return null; |
159 | 136 | } |
160 | 137 | |
| 138 | + // Save the old and new blobs for later |
| 139 | + $oldBlob = $row->mr_blob; |
| 140 | + $newBlob = self::generateMessageBlob( $module, $lang ); |
| 141 | + |
| 142 | + $newRow = array( |
| 143 | + 'mr_resource' => $name, |
| 144 | + 'mr_lang' => $lang, |
| 145 | + 'mr_blob' => $newBlob, |
| 146 | + 'mr_timestamp' => $dbw->timestamp() |
| 147 | + ); |
| 148 | + |
161 | 149 | $dbw->replace( 'msg_resource', |
162 | 150 | array( array( 'mr_resource', 'mr_lang' ) ), |
163 | | - $newRows, __METHOD__ |
| 151 | + $newRow, __METHOD__ |
164 | 152 | ); |
165 | 153 | |
166 | 154 | // Figure out which messages were added and removed |
— | — | @@ -192,7 +180,7 @@ |
193 | 181 | ); |
194 | 182 | } |
195 | 183 | |
196 | | - return $retval; |
| 184 | + return $newBlob; |
197 | 185 | } |
198 | 186 | |
199 | 187 | /** |