5use InvalidArgumentException;
6use UnexpectedValueException;
35 private $caller = __CLASS__;
40 private $upsert =
false;
50 private $uniqueIndexFields = [];
71 if ( $this->db->getType() !==
$db->
getType() ) {
72 throw new InvalidArgumentException(
73 __METHOD__ .
' cannot switch to a database of a different type.'
84 if ( isset( $info[
'table'] ) ) {
85 $this->
table( $info[
'table'] );
87 if ( isset( $info[
'rows'] ) ) {
88 $this->
rows( $info[
'rows'] );
90 if ( isset( $info[
'options'] ) ) {
91 $this->
options( (array)$info[
'options'] );
93 if ( isset( $info[
'upsert'] ) ) {
96 if ( isset( $info[
'uniqueIndexFields'] ) ) {
99 if ( isset( $info[
'set'] ) ) {
100 $this->
set( (array)$info[
'set'] );
102 if ( isset( $info[
'caller'] ) ) {
103 $this->
caller( $info[
'caller'] );
116 $this->
table = $table;
128 return $this->
table( $table );
138 public function insert(
string $table ) {
139 return $this->
table( $table );
150 public function option( $name, $value =
null ) {
151 if ( $value ===
null ) {
154 $this->
options[$name] = $value;
181 public function rows( array $rows ) {
182 $this->
rows = array_merge( $this->
rows, $rows );
195 public function row( array $row ) {
196 $this->
rows[] = $row;
219 $this->upsert =
true;
230 if ( is_string( $uniqueIndexFields ) ) {
231 $uniqueIndexFields = [ $uniqueIndexFields ];
259 public function set( $set ) {
260 if ( is_array( $set ) ) {
261 foreach ( $set as $key => $value ) {
262 if ( is_int( $key ) ) {
263 $this->
set[] = $value;
265 $this->
set[$key] = $value;
282 return $this->
set( $set );
298 throw new UnexpectedValueException(
299 __METHOD__ .
' can\'t have empty $rows value' );
301 if ( $this->
table ===
'' ) {
302 throw new UnexpectedValueException(
303 __METHOD__ .
' expects table not to be empty' );
306 throw new UnexpectedValueException(
307 __METHOD__ .
' called with upsert but no set value or unique key has been provided' );
310 throw new UnexpectedValueException(
311 __METHOD__ .
' is not called with upsert but set value or unique key has been provided' );
313 if ( $this->upsert ) {
325 'table' => $this->table,
326 'rows' => $this->rows,
327 'upsert' => $this->upsert,
329 'uniqueIndexFields' => $this->uniqueIndexFields,
330 'options' => $this->options,
332 if ( $this->caller !== __CLASS__ ) {
333 $info[
'caller'] = $this->caller;
if(!defined('MW_SETUP_CALLBACK'))