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 );
324 throw new UnexpectedValueException(
325 __METHOD__ .
' can\'t have empty $rows value' );
327 if ( $this->
table ===
'' ) {
328 throw new UnexpectedValueException(
329 __METHOD__ .
' expects table not to be empty' );
332 throw new UnexpectedValueException(
333 __METHOD__ .
' called with upsert but no set value or unique key has been provided' );
336 throw new UnexpectedValueException(
337 __METHOD__ .
' is not called with upsert but set value or unique key has been provided' );
339 if ( $this->upsert ) {
361 'table' => $this->table,
362 'rows' => $this->rows,
363 'upsert' => $this->upsert,
365 'uniqueIndexFields' => $this->uniqueIndexFields,
366 'options' => $this->options,
368 if ( $this->caller !== __CLASS__ ) {
369 $info[
'caller'] = $this->caller;
if(!defined('MW_SETUP_CALLBACK'))