Remove ugly function existence check
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index b6c249b..ec01869 100644 (file)
@@ -1470,8 +1470,7 @@ class LocalFile extends File {
                # This avoids race conditions by locking the row until the commit, and also
                # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
                $commentStore = MediaWikiServices::getInstance()->getCommentStore();
-               list( $commentFields, $commentCallback ) =
-                       $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
+               $commentFields = $commentStore->insert( $dbw, 'img_description', $comment );
                $actorMigration = ActorMigration::newMigration();
                $actorFields = $actorMigration->getInsertValues( $dbw, 'img_user', $user );
                $dbw->insert( 'image',
@@ -1543,7 +1542,8 @@ class LocalFile extends File {
                        }
                        if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
                                $tables[] = 'image_comment_temp';
-                               $fields['oi_description_id'] = 'imgcomment_description_id';
+                               $fields['oi_description_id'] =
+                                       'CASE WHEN img_description_id = 0 THEN imgcomment_description_id ELSE img_description_id END';
                                $joins['image_comment_temp'] = [
                                        $wgCommentTableSchemaMigrationStage === MIGRATION_NEW ? 'JOIN' : 'LEFT JOIN',
                                        [ 'imgcomment_name = img_name' ]
@@ -1559,16 +1559,17 @@ class LocalFile extends File {
                                $res = $dbw->select(
                                        [ 'image', 'image_comment_temp' ],
                                        [ 'img_name', 'img_description' ],
-                                       [ 'img_name' => $this->getName(), 'imgcomment_name' => null ],
+                                       [
+                                               'img_name' => $this->getName(),
+                                               'imgcomment_name' => null,
+                                               'img_description_id' => 0,
+                                       ],
                                        __METHOD__,
                                        [],
                                        [ 'image_comment_temp' => [ 'LEFT JOIN', [ 'imgcomment_name = img_name' ] ] ]
                                );
                                foreach ( $res as $row ) {
-                                       list( , $callback ) = $commentStore->insertWithTempTable(
-                                               $dbw, 'img_description', $row->img_description
-                                       );
-                                       $callback( $row->img_name );
+                                       $commentStore->insert( $dbw, 'img_description', $row->img_description );
                                }
                        }
 
@@ -1630,11 +1631,10 @@ class LocalFile extends File {
                                __METHOD__
                        );
                        if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) {
-                               // So $commentCallback can insert the new row
+                               // Clear deprecated table row
                                $dbw->delete( 'image_comment_temp', [ 'imgcomment_name' => $this->getName() ], __METHOD__ );
                        }
                }
-               $commentCallback( $this->getName() );
 
                $descTitle = $this->getTitle();
                $descId = $descTitle->getArticleID();
@@ -1696,6 +1696,7 @@ class LocalFile extends File {
                # Defer purges, page creation, and link updates in case they error out.
                # The most important thing is that files and the DB registry stay synced.
                $dbw->endAtomic( __METHOD__ );
+               $fname = __METHOD__;
 
                # Do some cache purges after final commit so that:
                # a) Changes are more likely to be seen post-purge
@@ -1706,7 +1707,7 @@ class LocalFile extends File {
                                __METHOD__,
                                function () use (
                                        $reupload, $wikiPage, $newPageContent, $comment, $user,
-                                       $logEntry, $logId, $descId, $tags
+                                       $logEntry, $logId, $descId, $tags, $fname
                                ) {
                                        # Update memcache after the commit
                                        $this->invalidateCache();
@@ -1758,7 +1759,7 @@ class LocalFile extends File {
                                                'logging',
                                                $update,
                                                [ 'log_id' => $logId ],
-                                               __METHOD__
+                                               $fname
                                        );
                                        $this->getRepo()->getMasterDB()->insert(
                                                'log_search',
@@ -1767,7 +1768,7 @@ class LocalFile extends File {
                                                        'ls_value' => $logEntry->getAssociatedRevId(),
                                                        'ls_log_id' => $logId,
                                                ],
-                                               __METHOD__
+                                               $fname
                                        );
 
                                        # Add change tags, if any
@@ -2537,7 +2538,8 @@ class LocalFileDeleteBatch {
                        }
                        if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
                                $tables[] = 'image_comment_temp';
-                               $fields['fa_description_id'] = 'imgcomment_description_id';
+                               $fields['fa_description_id'] =
+                                       'CASE WHEN img_description_id = 0 THEN imgcomment_description_id ELSE img_description_id END';
                                $joins['image_comment_temp'] = [
                                        $wgCommentTableSchemaMigrationStage === MIGRATION_NEW ? 'JOIN' : 'LEFT JOIN',
                                        [ 'imgcomment_name = img_name' ]
@@ -2553,16 +2555,17 @@ class LocalFileDeleteBatch {
                                $res = $dbw->select(
                                        [ 'image', 'image_comment_temp' ],
                                        [ 'img_name', 'img_description' ],
-                                       [ 'img_name' => $this->file->getName(), 'imgcomment_name' => null ],
+                                       [
+                                               'img_name' => $this->file->getName(),
+                                               'imgcomment_name' => null,
+                                               'img_description_id' => 0,
+                                       ],
                                        __METHOD__,
                                        [],
                                        [ 'image_comment_temp' => [ 'LEFT JOIN', [ 'imgcomment_name = img_name' ] ] ]
                                );
                                foreach ( $res as $row ) {
-                                       list( , $callback ) = $commentStore->insertWithTempTable(
-                                               $dbw, 'img_description', $row->img_description
-                                       );
-                                       $callback( $row->img_name );
+                                       $commentStore->insert( $dbw, 'img_description', $row->img_description );
                                }
                        }
 
@@ -2669,6 +2672,7 @@ class LocalFileDeleteBatch {
                if ( $deleteCurrent ) {
                        $dbw->delete( 'image', [ 'img_name' => $this->file->getName() ], __METHOD__ );
                        if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) {
+                               // Clear deprecated table row
                                $dbw->delete(
                                        'image_comment_temp', [ 'imgcomment_name' => $this->file->getName() ], __METHOD__
                                );
@@ -2936,8 +2940,7 @@ class LocalFileRestoreBatch {
                        if ( $first && !$exists ) {
                                // This revision will be published as the new current version
                                $destRel = $this->file->getRel();
-                               list( $commentFields, $commentCallback ) =
-                                       $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
+                               $commentFields = $commentStore->insert( $dbw, 'img_description', $comment );
                                $actorFields = $actorMigration->getInsertValues( $dbw, 'img_user', $user );
                                $insertCurrent = [
                                        'img_name' => $row->fa_name,
@@ -3049,7 +3052,6 @@ class LocalFileRestoreBatch {
                // This is not ideal, which is why it's important to lock the image row.
                if ( $insertCurrent ) {
                        $dbw->insert( 'image', $insertCurrent, __METHOD__ );
-                       $commentCallback( $insertCurrent['img_name'] );
                }
 
                if ( $insertBatch ) {