Skip to content

Commit f15fad7

Browse files
committed
Add commit method to Bulk class for easier use outside of the Query class
1 parent 9145988 commit f15fad7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Classes/Bulk.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class Bulk
4141
*/
4242
public $body = [];
4343

44+
/**
45+
* Number of pending operations
46+
* @var int
47+
*/
48+
public $operationCount = 0;
49+
4450

4551
/**
4652
* Bulk constructor.
@@ -177,6 +183,8 @@ public function action($actionType, $data = [])
177183
$this->body["body"][] = $data;
178184
}
179185

186+
$this->operationCount++;
187+
180188
$this->reset();
181189
}
182190

@@ -203,5 +211,15 @@ public function reset()
203211

204212
}
205213

214+
/**
215+
* Commit all pending operations
216+
*/
217+
public function commit()
218+
{
206219

220+
$this->query->connection->bulk($this->body);
221+
$this->operationCount = 0;
222+
$this->body = [];
223+
224+
}
207225
}

0 commit comments

Comments
 (0)