From d6c600ce112d29cc05dc241246c5124c9447f321 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Mon, 23 Jul 2012 15:35:31 +0200 Subject: [PATCH 1/3] Hooks now have a 'priority' value, default to 0. The hooks are retrieved from the database by descending priority. As a result they are run in the same order. --- include/plugin.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/plugin.php b/include/plugin.php index ffa562273..d6f81b817 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -111,7 +111,7 @@ function reload_plugins() { if(! function_exists('register_hook')) { -function register_hook($hook,$file,$function) { +function register_hook($hook,$file,$function,$priority=0) { $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", dbesc($hook), @@ -121,10 +121,11 @@ function register_hook($hook,$file,$function) { if(count($r)) return true; - $r = q("INSERT INTO `hook` (`hook`, `file`, `function`) VALUES ( '%s', '%s', '%s' ) ", + $r = q("INSERT INTO `hook` (`hook`, `file`, `function`, `priority`) VALUES ( '%s', '%s', '%s', '%s' ) ", dbesc($hook), dbesc($file), - dbesc($function) + dbesc($function), + dbesc($priority) ); return $r; }} @@ -145,7 +146,7 @@ if(! function_exists('load_hooks')) { function load_hooks() { $a = get_app(); $a->hooks = array(); - $r = q("SELECT * FROM `hook` WHERE 1"); + $r = q("SELECT * FROM `hook` WHERE 1 ORDER BY `priority` DESC"); if(count($r)) { foreach($r as $rr) { if(! array_key_exists($rr['hook'],$a->hooks)) @@ -161,6 +162,7 @@ function call_hooks($name, &$data = null) { $a = get_app(); if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) { + logger('call_hooks ' . print_r($a->hooks[$name],true) , LOGGER_DEBUG); foreach($a->hooks[$name] as $hook) { @include_once($hook[0]); if(function_exists($hook[1])) { From 35f1081bfe834d268744e091c24d730cda2064c4 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Mon, 23 Jul 2012 20:16:06 +0200 Subject: [PATCH 2/3] Removed the debug statement --- include/plugin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/include/plugin.php b/include/plugin.php index d6f81b817..f60a7d296 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -162,7 +162,6 @@ function call_hooks($name, &$data = null) { $a = get_app(); if((is_array($a->hooks)) && (array_key_exists($name,$a->hooks))) { - logger('call_hooks ' . print_r($a->hooks[$name],true) , LOGGER_DEBUG); foreach($a->hooks[$name] as $hook) { @include_once($hook[0]); if(function_exists($hook[1])) { From c052c6afca08eff24c0b4b95c7bde1e9ee2c4e31 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Tue, 24 Jul 2012 01:21:02 +0200 Subject: [PATCH 3/3] Database can now be automatically updated --- boot.php | 2 +- database.sql | 1 + update.php | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index 3a541a272..bcff5dddd 100644 --- a/boot.php +++ b/boot.php @@ -12,7 +12,7 @@ require_once('include/cache.php'); define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_VERSION', '3.0.1412' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1153 ); +define ( 'DB_UPDATE_VERSION', 1154 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index 1d0a32176..80ce05ba0 100644 --- a/database.sql +++ b/database.sql @@ -456,6 +456,7 @@ CREATE TABLE IF NOT EXISTS `hook` ( `hook` char(255) NOT NULL, `file` char(255) NOT NULL, `function` char(255) NOT NULL, + `priority` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/update.php b/update.php index d752eaa6d..9442f825b 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@