mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-25 20:31:31 +02:00
invalidating/deleting et2-select-cat's cache on adding, updating or deleting categories
Also pushing cat-changes as app "api-cats" to client-side ToDo: client-side code to update category list in admin or preferences
This commit is contained in:
parent
5031631dc4
commit
caef7296ce
@ -167,6 +167,39 @@ egw.extend('utils', egw.MODULE_GLOBAL, function()
|
|||||||
return cache[_name];
|
return cache[_name];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate / delete given part of the cache
|
||||||
|
*
|
||||||
|
* @param {string} _name unique name of cache-object
|
||||||
|
* @param {string|RegExp|undefined} _attr undefined: invalidate/unset whole object or just the given attribute _attr or matching RegExp _attr
|
||||||
|
*/
|
||||||
|
invalidateCache: function(_name, _attr)
|
||||||
|
{
|
||||||
|
// string with regular expression like "/^something/i"
|
||||||
|
if (typeof _attr === 'string' && _attr[0] === '/', _attr.indexOf('/', 1) !== -1)
|
||||||
|
{
|
||||||
|
let parts = _attr.split('/');
|
||||||
|
parts.shift();
|
||||||
|
const flags = parts.pop();
|
||||||
|
_attr = new RegExp(parts.join('/'), flags);
|
||||||
|
}
|
||||||
|
if (typeof _attr === 'undefined' || typeof cache[_name] === 'undefined')
|
||||||
|
{
|
||||||
|
delete cache[_name];
|
||||||
|
}
|
||||||
|
else if (typeof _attr === 'object' && _attr.constructor.name === 'RegExp')
|
||||||
|
{
|
||||||
|
for(const attr in cache[_name])
|
||||||
|
{
|
||||||
|
if (attr.match(_attr)) delete cache[_name][attr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete cache[_name][_attr];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
ajaxUrl: function(_menuaction) {
|
ajaxUrl: function(_menuaction) {
|
||||||
if(_menuaction.indexOf('menuaction=') >= 0)
|
if(_menuaction.indexOf('menuaction=') >= 0)
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
namespace EGroupware\Api;
|
namespace EGroupware\Api;
|
||||||
|
|
||||||
|
use EGroupware\Api\Json\Push;
|
||||||
|
use EGroupware\Api\Json\Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class to manage categories in eGroupWare
|
* class to manage categories in eGroupWare
|
||||||
*
|
*
|
||||||
@ -98,6 +101,11 @@ class Categories
|
|||||||
*/
|
*/
|
||||||
const GLOBAL_ACCOUNT = 0;
|
const GLOBAL_ACCOUNT = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* App name used to push category changes
|
||||||
|
*/
|
||||||
|
const PUSH_APP = 'api-cats';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owners for global accounts
|
* Owners for global accounts
|
||||||
*
|
*
|
||||||
@ -463,6 +471,17 @@ class Categories
|
|||||||
// update cache accordingly
|
// update cache accordingly
|
||||||
self::invalidate_cache(Db::strip_array_keys($cat, 'cat_'));
|
self::invalidate_cache(Db::strip_array_keys($cat, 'cat_'));
|
||||||
|
|
||||||
|
// push category change
|
||||||
|
$push = new Push($cat['cat_access'] === 'public' || (int)$cat['cat_owner'] <= 0 ? Push::ALL : (int)$cat['cat_owner']);
|
||||||
|
$push->apply("egw.push", [[
|
||||||
|
'app' => self::PUSH_APP,
|
||||||
|
'id' => $id,
|
||||||
|
'type' => empty($values['id']) ? 'add' : 'edit',
|
||||||
|
// assuming there is nothing private about a cat, thought private cats are only pushed to that account
|
||||||
|
'acl' => Db::strip_array_keys($cat, 'cat_'),
|
||||||
|
'account_id' => $GLOBALS['egw_info']['user']['account_id']
|
||||||
|
]]);
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,6 +656,21 @@ class Categories
|
|||||||
|
|
||||||
// update cache accordingly
|
// update cache accordingly
|
||||||
self::invalidate_cache($modify_subs ? null : $where['cat_id']);
|
self::invalidate_cache($modify_subs ? null : $where['cat_id']);
|
||||||
|
|
||||||
|
// push category change
|
||||||
|
$push = new Push(Push::ALL);
|
||||||
|
$push->apply("egw.push", [[
|
||||||
|
'app' => self::PUSH_APP,
|
||||||
|
'id' => $where['cat_id'], // can be an array, if $drop_subs
|
||||||
|
'type' => 'delete',
|
||||||
|
// sending parameters and new parent, probably client-side will do a full reload, if modify_subs is true
|
||||||
|
'acl' => [
|
||||||
|
'modify_subs' => $modify_subs,
|
||||||
|
'new_parent' => $new_parent,
|
||||||
|
],
|
||||||
|
'account_id' => $GLOBALS['egw_info']['user']['account_id']
|
||||||
|
]]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -662,6 +696,16 @@ class Categories
|
|||||||
),__LINE__,__FILE__);
|
),__LINE__,__FILE__);
|
||||||
$cat['level'] = $values['level'] + 1;
|
$cat['level'] = $values['level'] + 1;
|
||||||
self::invalidate_cache($cat['id']);
|
self::invalidate_cache($cat['id']);
|
||||||
|
// push category change
|
||||||
|
$push = new Push($cat['cat_access'] === 'public' || (int)$cat['cat_owner'] <= 0 ? Push::ALL : (int)$cat['cat_owner']);
|
||||||
|
$push->apply("egw.push", [[
|
||||||
|
'app' => self::PUSH_APP,
|
||||||
|
'id' => $cat['id'],
|
||||||
|
'type' => 'edit',
|
||||||
|
// assuming there is nothing private about a cat, thought private cats are only pushed to that account
|
||||||
|
'acl' => Db::strip_array_keys($cat, 'cat_'),
|
||||||
|
'account_id' => $GLOBALS['egw_info']['user']['account_id']
|
||||||
|
]]);
|
||||||
$this->adapt_level_in_subtree($cat);
|
$this->adapt_level_in_subtree($cat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -753,6 +797,17 @@ class Categories
|
|||||||
// update cache accordingly
|
// update cache accordingly
|
||||||
self::invalidate_cache(Db::strip_array_keys($cat, 'cat_'));
|
self::invalidate_cache(Db::strip_array_keys($cat, 'cat_'));
|
||||||
|
|
||||||
|
// push category change
|
||||||
|
$push = new Push($cat['cat_access'] === 'public' || (int)$cat['cat_owner'] <= 0 ? Push::ALL : (int)$cat['cat_owner']);
|
||||||
|
$push->apply("egw.push", [[
|
||||||
|
'app' => self::PUSH_APP,
|
||||||
|
'id' => $values['id'],
|
||||||
|
'type' => 'edit',
|
||||||
|
// assuming there is nothing private about a cat, thought private cats are only pushed to that account
|
||||||
|
'acl' => Db::strip_array_keys($cat, 'cat_'),
|
||||||
|
'account_id' => $GLOBALS['egw_info']['user']['account_id']
|
||||||
|
]]);
|
||||||
|
|
||||||
return (int)$values['id'];
|
return (int)$values['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -998,9 +1053,15 @@ class Categories
|
|||||||
{
|
{
|
||||||
//error_log(__METHOD__."(".array2string($cat).') '.function_backtrace());
|
//error_log(__METHOD__."(".array2string($cat).') '.function_backtrace());
|
||||||
|
|
||||||
// allways invalidate instance-global cache, as updating our own cache is not perfect and does not help other sessions
|
// always invalidate instance-global cache, as updating our own cache is not perfect and does not help other sessions
|
||||||
Cache::unsetInstance(self::CACHE_APP, self::CACHE_NAME);
|
Cache::unsetInstance(self::CACHE_APP, self::CACHE_NAME);
|
||||||
|
|
||||||
|
// update client-side eT2 cache
|
||||||
|
if (Response::isJSONResponse())
|
||||||
|
{
|
||||||
|
Response::get()->call('egw.invalidateCache', 'Et2Select', '/^ET2-SELECT-CAT/');
|
||||||
|
}
|
||||||
|
|
||||||
// if cat given update our own cache, to work around failed sitemgr install via setup (cant read just added categories)
|
// if cat given update our own cache, to work around failed sitemgr install via setup (cant read just added categories)
|
||||||
if ($cat)
|
if ($cat)
|
||||||
{
|
{
|
||||||
|
@ -46,6 +46,7 @@ $setup_info[TIMESHEET_APP]['hooks']['pm_cumulate'] = 'timesheet_hooks::cumulate'
|
|||||||
$setup_info[TIMESHEET_APP]['hooks']['deleteaccount'] = 'timesheet.timesheet_bo.deleteaccount';
|
$setup_info[TIMESHEET_APP]['hooks']['deleteaccount'] = 'timesheet.timesheet_bo.deleteaccount';
|
||||||
$setup_info[TIMESHEET_APP]['hooks']['acl_rights'] = 'timesheet_hooks::acl_rights';
|
$setup_info[TIMESHEET_APP]['hooks']['acl_rights'] = 'timesheet_hooks::acl_rights';
|
||||||
$setup_info[TIMESHEET_APP]['hooks']['topmenu_info'] = 'timesheet_hooks::add_timer';
|
$setup_info[TIMESHEET_APP]['hooks']['topmenu_info'] = 'timesheet_hooks::add_timer';
|
||||||
|
$setup_info[TIMESHEET_APP]['hooks']['config_validate'] = 'EGroupware\\Timesheet\\Events::config_validate';
|
||||||
|
|
||||||
/* Dependencies for this app to work */
|
/* Dependencies for this app to work */
|
||||||
$setup_info[TIMESHEET_APP]['depends'][] = array(
|
$setup_info[TIMESHEET_APP]['depends'][] = array(
|
||||||
|
@ -339,7 +339,7 @@ class Events extends Api\Storage\Base
|
|||||||
public static function workingTimeCat()
|
public static function workingTimeCat()
|
||||||
{
|
{
|
||||||
$config = Api\Config::read(self::APP);
|
$config = Api\Config::read(self::APP);
|
||||||
if (empty($config['working_time_cat']))
|
if (empty($config['working_time_cat']) || !Api\Categories::read($config['working_time_cat']))
|
||||||
{
|
{
|
||||||
$cats = new Api\Categories(Api\Categories::GLOBAL_ACCOUNT, Api\Categories::GLOBAL_APPNAME);
|
$cats = new Api\Categories(Api\Categories::GLOBAL_ACCOUNT, Api\Categories::GLOBAL_APPNAME);
|
||||||
Api\Config::save_value('working_time_cat', $config['working_time_cat'] = $cats->add([
|
Api\Config::save_value('working_time_cat', $config['working_time_cat'] = $cats->add([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user