/** * Delete object/s and reset ORM * @param $filter * @return void */ public function erase($filter = null) { $filter = $this->queryParser->prepareFilter($filter, $this->dbsType); if (!$filter && $this->emit('beforeerase') !== false) { if ($this->fieldConf) { foreach ($this->fieldConf as $field => $conf) { if (isset($conf['has-many']) && $conf['has-many']['hasRel'] == 'has-many') { $this->set($field, null); } } $this->save(); } $this->mapper->erase(); $this->emit('aftererase'); } elseif ($filter) { $this->mapper->erase($filter); } }
/** * Delete object/s and reset ORM * @param $filter * @return bool */ public function erase($filter = null) { $filter = $this->queryParser->prepareFilter($filter, $this->dbsType, $this->db); if (!$filter) { if ($this->emit('beforeerase') === false) { return false; } if ($this->fieldConf) { // clear all m:m references foreach ($this->fieldConf as $key => $conf) { if (isset($conf['has-many']) && $conf['has-many']['hasRel'] == 'has-many') { $rel = $this->getRelInstance(null, array('db' => $this->db, 'table' => $this->mmTable($conf['has-many'], $key))); $id = $this->get($conf['has-many']['relPK'], true); $rel->erase(array($conf['has-many']['relField'] . ' = ?', $id)); } } } $this->mapper->erase(); $this->emit('aftererase'); } elseif ($filter) { $this->mapper->erase($filter); } return true; }
/** Delete current record @return bool @param $filter array **/ function erase($filter = NULL) { $db = $this->db; $now = microtime(TRUE); $data = $db->read($this->file); if ($filter) { $data = $this->find($filter, NULL, FALSE); foreach (array_keys(array_reverse($data)) as $id) { unset($data[$id]); } } elseif (isset($this->id)) { unset($data[$this->id]); parent::erase(); $this->skip(0); } else { return FALSE; } $db->write($this->file, $data); if ($filter) { $args = isset($filter[1]) && is_array($filter[1]) ? $filter[1] : array_slice($filter, 1, NULL, TRUE); $args = is_array($args) ? $args : array(1 => $args); foreach ($args as $key => $val) { $vals[] = \Base::instance()->stringify(is_array($val) ? $val[0] : $val); $keys[] = '/' . (is_numeric($key) ? '\\?' : preg_quote($key)) . '/'; } } $db->jot('(' . sprintf('%.1f', 1000.0 * (microtime(TRUE) - $now)) . 'ms) ' . $this->file . ' [erase] ' . ($filter ? preg_replace($keys, $vals, $filter[0], 1) : '')); return TRUE; }
/** Delete current record @return int @param $filter string|array **/ function erase($filter = NULL) { if ($filter) { $args = array(); if (is_array($filter)) { $args = isset($filter[1]) && is_array($filter[1]) ? $filter[1] : array_slice($filter, 1, NULL, TRUE); $args = is_array($args) ? $args : array(1 => $args); list($filter) = $filter; } return $this->db->exec('DELETE FROM ' . $this->table . ' WHERE ' . $filter . ';', $args); } $args = array(); $ctr = 0; $filter = ''; foreach ($this->fields as $key => &$field) { if ($field['pkey']) { $filter .= ($filter ? ' AND ' : '') . $key . '=?'; $args[$ctr + 1] = array($field['previous'], $field['pdo_type']); $ctr++; } $field['value'] = NULL; $field['changed'] = (bool) $field['default']; if ($field['pkey']) { $field['previous'] = NULL; } unset($field); } foreach ($this->adhoc as &$field) { $field['value'] = NULL; unset($field); } parent::erase(); $this->skip(0); return $this->db->exec('DELETE FROM ' . $this->table . ' WHERE ' . $filter . ';', $args); }
/** * Delete current record * @return bool * @param $filter array **/ function erase($filter = NULL) { if ($filter) { return $this->collection->remove($filter); } $result = $this->collection->remove(array('_id' => $this->document['_id'])); parent::erase(); $this->skip(0); return $result; }
/** * Delete current record * @return bool * @param $filter array **/ function erase($filter = NULL) { if ($filter) { return $this->collection->remove($filter); } $pkey = array('_id' => $this->document['_id']); $result = $this->collection->remove(array('_id' => $this->document['_id'])); parent::erase(); $this->skip(0); if (isset($this->trigger['erase'])) { \Base::instance()->call($this->trigger['erase'], array($this, $pkey)); } return $result; }
/** * Delete current record * @return bool * @param $filter array **/ function erase($filter = NULL) { if ($filter) { return $this->collection->remove($filter); } $pkey = array('_id' => $this->document['_id']); if (isset($this->trigger['beforeerase']) && \Base::instance()->call($this->trigger['beforeerase'], array($this, $pkey)) === FALSE) { return FALSE; } $result = $this->collection->remove(array('_id' => $this->document['_id'])); parent::erase(); if (isset($this->trigger['aftererase'])) { \Base::instance()->call($this->trigger['aftererase'], array($this, $pkey)); } return $result; }
/** * Delete current record * @return bool * @param $filter array **/ function erase($filter = NULL) { $db = $this->db; $now = microtime(TRUE); $data =& $db->read($this->file); $pkey = array('_id' => $this->id); if ($filter) { foreach ($this->find($filter, NULL, FALSE) as $mapper) { if (!$mapper->erase()) { return FALSE; } } return TRUE; } elseif (isset($this->id)) { unset($data[$this->id]); parent::erase(); } else { return FALSE; } if (isset($this->trigger['beforeerase']) && \Base::instance()->call($this->trigger['beforeerase'], array($this, $pkey)) === FALSE) { return FALSE; } $db->write($this->file, $data); if ($filter) { $args = isset($filter[1]) && is_array($filter[1]) ? $filter[1] : array_slice($filter, 1, NULL, TRUE); $args = is_array($args) ? $args : array(1 => $args); foreach ($args as $key => $val) { $vals[] = \Base::instance()->stringify(is_array($val) ? $val[0] : $val); $keys[] = '/' . (is_numeric($key) ? '\\?' : preg_quote($key)) . '/'; } } $db->jot('(' . sprintf('%.1f', 1000.0 * (microtime(TRUE) - $now)) . 'ms) ' . $this->file . ' [erase] ' . ($filter ? preg_replace($keys, $vals, $filter[0], 1) : '')); if (isset($this->trigger['aftererase'])) { \Base::instance()->call($this->trigger['aftererase'], array($this, $pkey)); } return TRUE; }
/** * Delete current record * @return int * @param $filter string|array **/ function erase($filter = NULL) { if ($filter) { $args = []; if (is_array($filter)) { $args = isset($filter[1]) && is_array($filter[1]) ? $filter[1] : array_slice($filter, 1, NULL, TRUE); $args = is_array($args) ? $args : [1 => $args]; list($filter) = $filter; } return $this->db->exec('DELETE FROM ' . $this->table . ' WHERE ' . $filter . ';', $args); } $args = []; $ctr = 0; $filter = ''; $pkeys = []; foreach ($this->fields as $key => &$field) { if ($field['pkey']) { $filter .= ($filter ? ' AND ' : '') . $this->db->quotekey($key) . '=?'; $args[$ctr + 1] = [$field['previous'], $field['pdo_type']]; $pkeys[$key] = $field['previous']; $ctr++; } $field['value'] = NULL; $field['changed'] = (bool) $field['default']; if ($field['pkey']) { $field['previous'] = NULL; } unset($field); } foreach ($this->adhoc as &$field) { $field['value'] = NULL; unset($field); } parent::erase(); if (isset($this->trigger['beforeerase']) && \Base::instance()->call($this->trigger['beforeerase'], [$this, $pkeys]) === FALSE) { return 0; } $out = $this->db->exec('DELETE FROM ' . $this->table . ' WHERE ' . $filter . ';', $args); if (isset($this->trigger['aftererase'])) { \Base::instance()->call($this->trigger['aftererase'], [$this, $pkeys]); } return $out; }
/** * Delete object/s and reset ORM * @param $filter * @return void */ public function erase($filter = null) { $filter = $this->queryParser->prepareFilter($filter, $this->dbsType); $this->mapper->erase($filter); }