also unlink temp. files, when deleting shares of type "Download link"

This commit is contained in:
Ralf Becker 2014-12-09 12:46:38 +00:00
parent efc14ee2dc
commit 7a4fb44240
2 changed files with 71 additions and 25 deletions

View File

@ -154,10 +154,12 @@ class filemanager_shares extends filemanager_ui
switch($content['nm']['action'])
{
case 'delete':
$where = $content['nm']['select_all'] ? array('share_owner' => $GLOBALS['egw_info']['user']['account_id']) :
array('share_id' => $content['nm']['selected']);
$deleted = egw_sharing::so()->delete($where);
egw_framework::message(lang('%1 shares deleted.', $deleted), 'success');
$where = array('share_owner' => $GLOBALS['egw_info']['user']['account_id']);
if (!$content['nm']['select_all'])
{
$where['share_id'] = $content['nm']['selected'];
}
egw_framework::message(lang('%1 shares deleted.', egw_sharing::delete($where)), 'success');
break;
default:
throw new egw_exception_wrong_parameter("Unknown action '{$content['nm']['action']}'!");

View File

@ -116,27 +116,6 @@ class egw_sharing
return $token;
}
/**
* so_sql instance for egw_sharing table
*
* @var so_sql
*/
protected static $so;
/**
* Get a so_sql instance initialised for shares
*/
public static function so()
{
if (!isset(self::$so))
{
self::$so = new so_sql('phpgwapi', self::TABLE, null, '', true);
self::$so->set_times('string');
}
return self::$so;
}
/**
* Create sharing session
*
@ -411,6 +390,71 @@ class egw_sharing
return $share;
}
/**
* so_sql instance for egw_sharing table
*
* @var so_sql
*/
protected static $so;
/**
* Get a so_sql instance initialised for shares
*/
public static function so()
{
if (!isset(self::$so))
{
self::$so = new so_sql('phpgwapi', self::TABLE, null, '', true);
self::$so->set_times('string');
}
return self::$so;
}
/**
* Delete specified shares and unlink temp. files
*
* @param int|array $keys
* @return int number of deleted shares
*/
public static function delete($keys)
{
self::$db = $GLOBALS['egw']->db;
if (is_scalar($keys)) $keys = array('share_id' => $keys);
// get all temp. files, to be able to delete them
$tmp_paths = array();
foreach(self::$db->select(self::TABLE, 'share_path', array(
"share_path LIKE '/home/%/.tmp/%'")+$keys, __LINE__, __FILE__, false) as $row)
{
$tmp_paths[] = $row['share_path'];
}
// delete specified shares
self::$db->delete(self::TABLE, $keys, __LINE__, __FILE__);
$deleted = self::$db->affected_rows();
// check if temp. files are used elsewhere
if ($tmp_paths)
{
foreach(self::$db->select(self::TABLE, 'share_path,COUNT(*) AS cnt', array(
'share_path' => $tmp_paths,
), __LINE__, __FILE__, false, 'GROUP BY share_path') as $row)
{
if (($key = array_search($row['share_path'], $tmp_paths)))
{
unset($tmp_paths[$key]);
}
}
// if not delete them
foreach($tmp_paths as $path)
{
egw_vfs::remove($path);
}
}
return $deleted;
}
/**
* Home long to keep temp. files: 100 day
*/