Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
BulkDeletes.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\orm\bulk;
4
6
16
17 public function addInstance($instance, $id = null) {
18 $id = $id ?? OrmUtils::getFirstKeyValue ( $instance );
19 $this->instances [$id] = $instance;
20 }
21
22 public function createSQL() {
23 $quote = $this->db->quote;
24 $this->parameters = \array_keys ( $this->instances );
25 $count = \count ( $this->parameters );
26
27 return "DELETE FROM {$quote}{$this->tableName}{$quote} WHERE {$quote}{$this->pkName}{$quote} IN (" . \implode ( ',', \array_fill ( 0, $count, '?' ) ) . ')';
28 }
29
30 public function groupOp($count = 5) {
31 $quote = $this->db->quote;
32 $groups = \array_chunk ( $this->instances, $count );
33
34 $deleteTable = "DELETE FROM {$quote}{$this->tableName}{$quote} WHERE ";
35 foreach ( $groups as $group ) {
36 $sql = '';
37 foreach ( $group as $instance ) {
38 $kv = OrmUtils::getKeyFieldsAndValues ( $instance );
39 $sql .= $deleteTable . $this->db->getCondition ( $kv ) . ';';
40 }
41 $this->execGroupTrans ( $sql );
42 }
43 $this->instances = [ ];
44 $this->parameters = [ ];
45 }
46}
47
Object/relational mapping utilities.
Definition OrmUtils.php:17
static getKeyFieldsAndValues($instance, $prefix='')
Definition OrmUtils.php:49
static getFirstKeyValue($instance)
Definition OrmUtils.php:107
Ubiquity\orm\bulk$AbstractBulks This class is part of Ubiquity.
Ubiquity\orm\bulk$BulkDeletes This class is part of Ubiquity.
addInstance($instance, $id=null)