5use InvalidArgumentException;
6use UnexpectedValueException;
35 private $caller = __CLASS__;
40 private $upsert =
false;
50 private $uniqueIndexFields = [];
75 if ( $this->db->getType() !==
$db->
getType() ) {
76 throw new InvalidArgumentException(
77 __METHOD__ .
' cannot switch to a database of a different type.'
103 if ( isset( $info[
'table'] ) ) {
104 $this->
table( $info[
'table'] );
106 if ( isset( $info[
'rows'] ) ) {
107 $this->
rows( $info[
'rows'] );
109 if ( isset( $info[
'options'] ) ) {
110 $this->
options( (array)$info[
'options'] );
112 if ( isset( $info[
'upsert'] ) ) {
115 if ( isset( $info[
'uniqueIndexFields'] ) ) {
118 if ( isset( $info[
'set'] ) ) {
119 $this->
set( (array)$info[
'set'] );
121 if ( isset( $info[
'caller'] ) ) {
122 $this->
caller( $info[
'caller'] );
135 $this->
table = $table;
147 return $this->
table( $table );
157 public function insert(
string $table ) {
158 return $this->
table( $table );
169 public function option( $name, $value =
null ) {
170 if ( $value ===
null ) {
173 $this->
options[$name] = $value;
200 public function rows( array $rows ) {
201 $this->
rows = array_merge( $this->
rows, $rows );
214 public function row( array $row ) {
215 $this->
rows[] = $row;
238 $this->upsert =
true;
249 if ( is_string( $uniqueIndexFields ) ) {
250 $uniqueIndexFields = [ $uniqueIndexFields ];
278 public function set( $set ) {
279 if ( is_array( $set ) ) {
280 foreach ( $set as $key => $value ) {
281 if ( is_int( $key ) ) {
282 $this->
set[] = $value;
284 $this->
set[$key] = $value;
301 return $this->
set( $set );
321 throw new UnexpectedValueException(
322 __METHOD__ .
' can\'t have empty $rows value' );
324 if ( $this->
table ===
'' ) {
325 throw new UnexpectedValueException(
326 __METHOD__ .
' expects table not to be empty' );
329 throw new UnexpectedValueException(
330 __METHOD__ .
' called with upsert but no set value or unique key has been provided' );
333 throw new UnexpectedValueException(
334 __METHOD__ .
' is not called with upsert but set value or unique key has been provided' );
336 if ( $this->upsert ) {
358 'table' => $this->table,
359 'rows' => $this->rows,
360 'upsert' => $this->upsert,
362 'uniqueIndexFields' => $this->uniqueIndexFields,
363 'options' => $this->options,
365 if ( $this->caller !== __CLASS__ ) {
366 $info[
'caller'] = $this->caller;
if(!defined('MW_SETUP_CALLBACK'))