Skip to content

Commit

Permalink
some more work on lockable behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ceeram committed Jan 6, 2010
1 parent ff009e7 commit a84833c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions infinitas/core/models/behaviors/lockable.php
Expand Up @@ -51,18 +51,19 @@ function setup(&$Model, $config = null) {
function lock(&$Model, $fields = null, $id = null){
$old_recursive = $Model->recursive;
$Model->recursive = -1;
$data = $Model->read(array('locked', 'locked_by', 'id'), $id);
$data = $Model->read($this->_defaults['fields'], $id);
$this->Session = new CakeSession();
$user_id = $this->Session->read('Auth.User.id');
if($data[$Model->name]['locked'] && $data[$Model->name]['locked_by'] != $user_id){
return false;
}
$data[$Model->name] = array(
'id' => $id,
'locked' => 1,
'locked_by' => $user_id,
'locked_since' => date('Y-m-d H:i:s')
);
$Model->save($data, array('validation' => false ));
$Model->save($data, array('validate' => false, 'callbacks' => false));
$Model->recursive = $old_recursive;
$data = $Model->read($fields, $id);
return $data;
Expand Down

0 comments on commit a84833c

Please sign in to comment.