+ /**
+ * @param stdClass|bool $row
+ * @return stdClass
+ */
+ private static function salvageInsaneRow( $row ) {
+ $map = $row ? (array)$row : [];
+ // Fill in any missing values with zero
+ $map += array_fill_keys( self::selectFields(), 0 );
+ // Convert negative values to zero
+ foreach ( $map as $field => $value ) {
+ $map[$field] = max( 0, $value );
+ }
+
+ return (object)$row;
+ }
+