Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMssql.php
index 773e548..fed6f14 100644 (file)
@@ -359,6 +359,28 @@ class DatabaseMssql extends Database {
                }
        }
 
+       protected function wasKnownStatementRollbackError() {
+               $errors = sqlsrv_errors( SQLSRV_ERR_ALL );
+               if ( !$errors ) {
+                       return false;
+               }
+               // The transaction vs statement rollback behavior depends on XACT_ABORT, so make sure
+               // that the "statement has been terminated" error (3621) is specifically present.
+               // https://docs.microsoft.com/en-us/sql/t-sql/statements/set-xact-abort-transact-sql
+               $statementOnly = false;
+               $codeWhitelist = [ '2601', '2627', '547' ];
+               foreach ( $errors as $error ) {
+                       if ( $error['code'] == '3621' ) {
+                               $statementOnly = true;
+                       } elseif ( !in_array( $error['code'], $codeWhitelist ) ) {
+                               $statementOnly = false;
+                               break;
+                       }
+               }
+
+               return $statementOnly;
+       }
+
        /**
         * @return int
         */
@@ -1272,9 +1294,7 @@ class DatabaseMssql extends Database {
                        $this->populateColumnCaches();
                }
 
-               return isset( $this->binaryColumnCache[$tableRaw] )
-                       ? $this->binaryColumnCache[$tableRaw]
-                       : [];
+               return $this->binaryColumnCache[$tableRaw] ?? [];
        }
 
        /**
@@ -1289,9 +1309,7 @@ class DatabaseMssql extends Database {
                        $this->populateColumnCaches();
                }
 
-               return isset( $this->bitColumnCache[$tableRaw] )
-                       ? $this->bitColumnCache[$tableRaw]
-                       : [];
+               return $this->bitColumnCache[$tableRaw] ?? [];
        }
 
        private function populateColumnCaches() {
@@ -1396,4 +1414,7 @@ class DatabaseMssql extends Database {
        }
 }
 
+/**
+ * @deprecated since 1.29
+ */
 class_alias( DatabaseMssql::class, 'DatabaseMssql' );