/** * overwritten to allow for soft-deleting a record * * The schema of the relevant model needs a field defined in schema called `deleted`. * As soon as this is the case, the record does not get deleted right away but instead * marked for deletion, i.e. setting a timestamp into the `deleted` field. Unless you make * use of the `force` option, then the record will get deleted without further ado. * * @param object $entity current instance * @param array $options Possible options are: * - `force`: set to true to delete record, anyway * @return boolean true on success, false otherwise */ public function delete($entity, array $options = array()) { $options += array('force' => false); $deleted = $entity->schema('deleted'); // TODO: use $deleted = $entity->hasField('deleted'); if (is_null($deleted) || $options['force']) { unset($options['force']); $result = parent::delete($entity, $options); $versions = static::meta('versions'); if ($versions === true || is_callable($versions) && $versions($entity, $options)) { if ($entity->version_id) { $key = Versions::key(); $conditions = array($key => $entity->version_id); Versions::update(array('status' => 'deleted'), $conditions); } } return $result; } $entity->deleted = time(); return $entity->save(); }