fixed delete_account hook, to deal correctly with multiple responsibles

This commit is contained in:
Ralf Becker 2008-10-22 06:15:37 +00:00
parent 214afe0bd5
commit 2d7f22e7ec
3 changed files with 25 additions and 36 deletions

View File

@ -64,14 +64,14 @@ class infolog_so
/** /**
* Constructor * Constructor
* *
* @param array $grants * @param array $grants=array()
* @return soinfolog * @return soinfolog
*/ */
function __construct( &$grants ) function __construct( $grants=array() )
{ {
$this->db = clone($GLOBALS['egw']->db); $this->db = clone($GLOBALS['egw']->db);
$this->db->set_app('infolog'); $this->db->set_app('infolog');
$this->grants =& $grants; $this->grants = $grants;
$this->user = $GLOBALS['egw_info']['user']['account_id']; $this->user = $GLOBALS['egw_info']['user']['account_id'];
$this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; $this->tz_offset = $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
@ -458,26 +458,36 @@ class infolog_so
/** /**
* changes or deletes entries with a spezified owner (for hook_delete_account) * changes or deletes entries with a spezified owner (for hook_delete_account)
* *
* @param $owner old owner * @param array $args hook arguments
* @param $new_owner new owner or 0 if entries should be deleted * @param int $args['account_id'] account to delete
* @param int $args['new_owner']=0 new owner
*/ */
function change_delete_owner($owner,$new_owner=0) // new_owner=0 means delete function change_delete_owner(array $args) // new_owner=0 means delete
{ {
if (!(int) $new_owner) if (!(int) $args['new_owner'])
{ {
$db2 = clone($this->db); // we need an extra result-set foreach($this->db->select($this->info_table,'info_id',array('info_owner'=>$args['account_id']),__LINE__,__FILE__,false,'','infolog') as $row)
$db2->select($this->info_table,'info_id',array('info_owner'=>$owner),__LINE__,__FILE__);
while($db2->next_record())
{ {
$this->delete($this->db->f(0),False); $this->delete($row['info_id'],False);
} }
} }
else else
{ {
$this->db->update($this->info_table,array('info_owner'=>$new_owner),array('info_owner'=>$owner),__LINE__,__FILE__); $this->db->update($this->info_table,array('info_owner'=>$args['new_owner']),array('info_owner'=>$args['account_id']),__LINE__,__FILE__,'infolog');
} }
// ToDo: does not work with multiple owners!!! foreach($this->db->select($this->info_table,'info_id,info_responsible',
$this->db->update($this->info_table,array('info_responsible'=>$new_owner),array('info_responsible'=>$owner),__LINE__,__FILE__); $this->db->concat("','",'info_responsible',"','").' LIKE '.$this->db->quote('%,'.(int)$args['account_id'].',%'),
__LINE__,__FILE__,false,'','infolog') as $row)
{
$new_responsible = explode(',',$row['info_responsible']);
unset($new_responsible[array_search($args['account_id'],$new_responsible)]);
if ((int)$args['new_owner']) $new_responsible[] = (int)$args['new_owner'];
$new_responsible = implode(',',$new_responsible);
$this->db->update($this->info_table,array(
'info_responsible' => $new_responsible,
),array('info_id' => $row['info_id']),__LINE__,__FILE__,'infolog');
}
} }
/** /**

View File

@ -1,21 +0,0 @@
<?php
/**
* InfoLog - delete account hook
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package infolog
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
// Delete all records for a user
if((int)$GLOBALS['hook_values']['account_id'] > 0)
{
$grants = array();
$info =& new infolog_so($grants);
$info->change_delete_owner((int)$GLOBALS['hook_values']['account_id'],(int)$_POST['new_owner']);
unset($info);
}

View File

@ -48,7 +48,7 @@ $setup_info['infolog']['hooks']['preferences'] = 'infolog_hooks::all_hooks';
$setup_info['infolog']['hooks']['settings'] = 'infolog_hooks::settings'; $setup_info['infolog']['hooks']['settings'] = 'infolog_hooks::settings';
$setup_info['infolog']['hooks']['verify_settings'] = 'infolog_hooks::verify_settings'; $setup_info['infolog']['hooks']['verify_settings'] = 'infolog_hooks::verify_settings';
$setup_info['infolog']['hooks']['admin'] = 'infolog_hooks::all_hooks'; $setup_info['infolog']['hooks']['admin'] = 'infolog_hooks::all_hooks';
$setup_info['infolog']['hooks'][] = 'deleteaccount'; $setup_info['infolog']['hooks']['deleteaccount'] = 'infolog.infolog_so.change_delete_owner';
$setup_info['infolog']['hooks'][] = 'home'; $setup_info['infolog']['hooks'][] = 'home';
$setup_info['infolog']['hooks']['addressbook_view'] = 'infolog.infolog_ui.hook_view'; $setup_info['infolog']['hooks']['addressbook_view'] = 'infolog.infolog_ui.hook_view';
$setup_info['infolog']['hooks']['projects_view'] = 'infolog.infolog_ui.hook_view'; $setup_info['infolog']['hooks']['projects_view'] = 'infolog.infolog_ui.hook_view';