| Conditions | 5 |
| Paths | 2 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | protected function write(array $elements){ |
||
| 37 | $columns = join(',', array_keys($elements)); |
||
| 38 | $values = join(',', array_map(function($value){ |
||
| 39 | if(is_null($value)){ |
||
| 40 | return null; |
||
| 41 | } |
||
| 42 | |||
| 43 | if(is_bool($value)){ |
||
| 44 | return (int)$value; |
||
| 45 | } |
||
| 46 | |||
| 47 | return is_string($value) ? $this->db->escape($value) : $value ; |
||
| 48 | }, array_values($elements))); |
||
| 49 | |||
| 50 | $this->db->begin(); |
||
| 51 | $resql = $this->db->query(sprintf('INSERT INTO ' . $this->tableName . '(%s) VALUES (%s)', $columns, $values)); |
||
| 52 | |||
| 53 | if (!$resql) { |
||
| 54 | $lasterror = $this->db->lasterror(); |
||
| 55 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
||
| 56 | $this->db->rollback(); |
||
| 57 | throw new \Exception("Repository error - ".$lasterror); |
||
| 58 | } |
||
| 59 | |||
| 60 | $id = $this->db->last_insert_id($this->tableName); |
||
| 61 | $this->db->commit(); |
||
| 62 | return $id; |
||
| 63 | } |
||
| 64 | |||
| 66 | } |