r70847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70846‎ | r70847 | r70848 >
Date:06:30, 11 August 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on script to get extension metadata
Modified paths:
  • /trunk/extensions/Distribution/maintenance/getSvnMetadata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Distribution/maintenance/getSvnMetadata.php
@@ -152,22 +152,21 @@
153153 *
154154 * @since 0.1
155155 *
156 - * @param array $metaData
 156+ * @param $metaData Array
157157 */
158158 protected function saveExtensionMetadata( array $metaData ) {
159159 // Get the database connections.
160160 $dbr = wfGetDB( DB_SLAVE );
161 - $dbw = wfGetDB( DB_MASTER );
162161
163162 // Query for existing units with the same name.
164 - $extension = $dbr->selectRow(
 163+ $unit = $dbr->selectRow(
165164 'distribution_units',
166165 array( 'unit_id' ),
167166 array( 'unit_name' => $metaData['name'] )
168167 );
169168
170 - // Map the values to the db schema.
171 - $values = array(
 169+ // Map the unit values to the db schema.
 170+ $unitValues = array(
172171 'unit_name' => $metaData['name'],
173172 'current_version_nr' => $metaData['version'],
174173 'current_desc' => $metaData['description'],
@@ -175,23 +174,100 @@
176175 'current_url' => $metaData['url'],
177176 );
178177
179 - // Insert or update depending on if it already exists.
180 - if ( $extension == false ) {
 178+ // Map the version values to the db schema.
 179+ $versionValues = array(
 180+ 'version_status' => 0, // TODO
 181+ 'version_desc' => $metaData['description'],
 182+ 'version_authors' => $metaData['authors'],
 183+ 'version_url' => $metaData['url'],
 184+ );
 185+
 186+ // Insert or update the unit.
 187+ if ( $unit == false ) {
 188+ $this->insertUnit( $unitValues, $versionValues );
 189+ }
 190+ else {
 191+ $this->updateUnit( $unit, $unitValues, $versionValues, $dbr );
 192+ }
 193+ }
 194+
 195+ /**
 196+ * Inserts a new unit and creates a new version for this unit.
 197+ *
 198+ * @since 0.1
 199+ *
 200+ * @param $unitValues Array
 201+ * @param $versionValues Array
 202+ */
 203+ protected function insertUnit( array $unitValues, array $versionValues ) {
 204+ $dbw = wfGetDB( DB_MASTER );
 205+
 206+ $dbw->insert(
 207+ 'distribution_units',
 208+ $unitValues
 209+ );
 210+
 211+ $versionValues['version_nr'] = $unitValues['current_version_nr'];
 212+ $versionValues['unit_id'] = $dbw->insertId();
 213+
 214+ $dbw->insert(
 215+ 'distribution_unit_versions',
 216+ $versionValues
 217+ );
 218+ }
 219+
 220+ /**
 221+ * Updates an existing unit. If the unit already had a version for the current number,
 222+ * it will be updated, otherwise a new one will be created.
 223+ *
 224+ * @since 0.1
 225+ *
 226+ * @param $unit Array
 227+ * @param $unitValues Array
 228+ * @param $versionValues Array
 229+ * @param $dbr DatabaseBase
 230+ */
 231+ protected function updateUnit( array $unit, array $unitValues, array $versionValues, DatabaseBase $dbr ) {
 232+ $dbw = wfGetDB( DB_MASTER );
 233+
 234+ $versionValues['unit_id'] = $unit['unit_id'];
 235+
 236+ // Query for existing versions of this unit with the same version number.
 237+ $version = $dbr->selectRow(
 238+ 'distribution_unit_versions',
 239+ array( 'version_id' ),
 240+ array(
 241+ 'unit_id' => $unit['unit_id'],
 242+ 'version_nr' => $unitValues['current_version_nr']
 243+ )
 244+ );
 245+
 246+ if ( $version == false ) {
 247+ $versionValues['version_nr'] = $unitValues['current_version_nr'];
 248+
181249 $dbw->insert(
182 - 'distribution_units',
183 - $values
184 - );
 250+ 'distribution_unit_versions',
 251+ $versionValues
 252+ );
 253+
 254+ $unitValues['current_version_nr'] = $dbw->insertId();
185255 }
186256 else {
187257 $dbw->update(
188 - 'distribution_units',
189 - $values,
190 - array( 'unit_name' => $metaData['name'] )
191 - );
 258+ 'distribution_unit_versions',
 259+ $versionValues,
 260+ array( 'version_id' => $version['version_id'] )
 261+ );
 262+
 263+ $unitValues['current_version_nr'] = $version['version_id'];
192264 }
193265
194 - // TODO: distribution_unit_versions
195 - }
 266+ $dbw->update(
 267+ 'distribution_units',
 268+ $unitValues,
 269+ array( 'unit_id' => $unit['unit_id'] )
 270+ );
 271+ }
196272
197273 }
198274

Follow-up revisions

RevisionCommit summaryAuthorDate
r70848Follow up to r70847 - fixed object vs array issuejeroendedauw06:46, 11 August 2010

Status & tagging log