detect and automatically repair duplicate plugin hook scenarios.
This commit is contained in:
parent
c5ce9b0699
commit
bc4a92b702
@ -109,11 +109,16 @@ function install_plugin($plugin) {
|
|||||||
|
|
||||||
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
|
$plugin_admin = (function_exists($plugin . '_plugin_admin') ? 1 : 0);
|
||||||
|
|
||||||
q("INSERT INTO addon (aname, installed, tstamp, plugin_admin) VALUES ( '%s', 1, %d , %d ) ",
|
$d = q("select * from addon where aname = '%s' limit 1",
|
||||||
dbesc($plugin),
|
dbesc($plugin)
|
||||||
intval($t),
|
|
||||||
$plugin_admin
|
|
||||||
);
|
);
|
||||||
|
if(! $d) {
|
||||||
|
q("INSERT INTO addon (aname, installed, tstamp, plugin_admin) VALUES ( '%s', 1, %d , %d ) ",
|
||||||
|
dbesc($plugin),
|
||||||
|
intval($t),
|
||||||
|
$plugin_admin
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
load_plugin($plugin);
|
load_plugin($plugin);
|
||||||
}
|
}
|
||||||
@ -366,28 +371,47 @@ function unregister_hook($hook, $file, $function) {
|
|||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
//
|
* @brief loads all active hooks into memory
|
||||||
// It might not be obvious but themes can manually add hooks to the App::$hooks
|
* alters: App::$hooks
|
||||||
// array in their theme_init() and use this to customise the app behaviour.
|
* Called during initialisation
|
||||||
// UPDATE: use insert_hook($hookname,$function_name) to do this
|
* Duplicated hooks are removed and the duplicates ignored
|
||||||
//
|
*
|
||||||
|
* It might not be obvious but themes can manually add hooks to the App::$hooks
|
||||||
|
* array in their theme_init() and use this to customise the app behaviour.
|
||||||
|
* use insert_hook($hookname,$function_name) to do this.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
function load_hooks() {
|
function load_hooks() {
|
||||||
|
|
||||||
App::$hooks = array();
|
App::$hooks = [];
|
||||||
|
|
||||||
$r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC");
|
$r = q("SELECT * FROM hook WHERE true ORDER BY priority DESC");
|
||||||
if($r) {
|
if($r) {
|
||||||
foreach($r as $rr) {
|
|
||||||
if(! array_key_exists($rr['hook'],App::$hooks))
|
|
||||||
App::$hooks[$rr['hook']] = array();
|
|
||||||
|
|
||||||
App::$hooks[$rr['hook']][] = array($rr['file'],$rr['fn'],$rr['priority'],$rr['hook_version']);
|
foreach($r as $rv) {
|
||||||
|
$duplicated = false;
|
||||||
|
if(! array_key_exists($rv['hook'],App::$hooks)) {
|
||||||
|
App::$hooks[$rv['hook']] = [];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foreach(App::$hooks[$rv['hook']] as $h) {
|
||||||
|
if($h[0] === $rv['file'] && $h[1] === $rv['fn']) {
|
||||||
|
$duplicated = true;
|
||||||
|
q("delete from hook where id = %d",
|
||||||
|
intval($rv['id'])
|
||||||
|
);
|
||||||
|
logger('duplicate hook ' . $h[1] . ' removed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(! $duplicated) {
|
||||||
|
App::$hooks[$rv['hook']][] = [ $rv['file'], $rv['fn'], $rv['priority'], $rv['hook_version']];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//logger('hooks: ' . print_r(App::$hooks,true));
|
// logger('hooks: ' . print_r(App::$hooks,true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user