5use InvalidArgumentException;
6use UnexpectedValueException;
35 private $caller = __CLASS__;
40 private $upsert =
false;
50 private $uniqueIndexFields = [];
78 if ( $this->db->getType() !==
$db->
getType() ) {
79 throw new InvalidArgumentException(
80 __METHOD__ .
' cannot switch to a database of a different type.'
106 if ( isset( $info[
'table'] ) ) {
107 $this->
table( $info[
'table'] );
109 if ( isset( $info[
'rows'] ) ) {
110 $this->
rows( $info[
'rows'] );
112 if ( isset( $info[
'options'] ) ) {
113 $this->
options( (array)$info[
'options'] );
115 if ( isset( $info[
'upsert'] ) ) {
118 if ( isset( $info[
'uniqueIndexFields'] ) ) {
121 if ( isset( $info[
'set'] ) ) {
122 $this->
set( (array)$info[
'set'] );
124 if ( isset( $info[
'caller'] ) ) {
125 $this->
caller( $info[
'caller'] );
138 $this->
table = $table;
150 return $this->
table( $table );
160 public function insert(
string $table ) {
161 return $this->
table( $table );
172 public function option( $name, $value =
null ) {
173 if ( $value ===
null ) {
176 $this->
options[$name] = $value;
203 public function rows( array $rows ) {
204 $this->
rows = array_merge( $this->
rows, $rows );
217 public function row( array $row ) {
218 $this->
rows[] = $row;
241 $this->upsert =
true;
252 if ( is_string( $uniqueIndexFields ) ) {
253 $uniqueIndexFields = [ $uniqueIndexFields ];
281 public function set( $set ) {
282 if ( is_array( $set ) ) {
283 foreach ( $set as $key => $value ) {
284 if ( is_int( $key ) ) {
285 $this->
set[] = $value;
287 $this->
set[$key] = $value;
304 return $this->
set( $set );
323 if ( !$this->
rows ) {
325 wfDeprecatedMsg( self::class .
' triggered with no rows set; exit early instead.' );
329 if ( $this->
table ===
'' ) {
330 throw new UnexpectedValueException(
331 __METHOD__ .
' expects table not to be empty' );
334 throw new UnexpectedValueException(
335 __METHOD__ .
' called with upsert but no set value or unique key has been provided' );
338 throw new UnexpectedValueException(
339 __METHOD__ .
' is not called with upsert but set value or unique key has been provided' );
341 if ( $this->upsert ) {
363 'table' => $this->table,
364 'rows' => $this->rows,
365 'upsert' => $this->upsert,
367 'uniqueIndexFields' => $this->uniqueIndexFields,
370 if ( $this->
caller !== __CLASS__ ) {
371 $info[
'caller'] = $this->caller;
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.