]> git.mxchange.org Git - friendica.git/commitdiff
reload plugins if they change
authorFriendika <info@friendika.com>
Wed, 9 Mar 2011 10:12:32 +0000 (02:12 -0800)
committerFriendika <info@friendika.com>
Wed, 9 Mar 2011 10:12:32 +0000 (02:12 -0800)
boot.php
database.sql
include/poller.php
update.php

index d3380a395b6815e73ed826d6c7152d2c79bb4e07..37cd4259238a9fb77d234dd091c3fdfca3c09fb3 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -2,8 +2,8 @@
 
 set_time_limit(0);
 
-define ( 'BUILD_ID',               1039   );
-define ( 'FRIENDIKA_VERSION',      '2.10.0910' );
+define ( 'BUILD_ID',               1040   );
+define ( 'FRIENDIKA_VERSION',      '2.10.0912' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.1'  );
 
 define ( 'EOL',                    "<br />\r\n"     );
@@ -512,22 +512,70 @@ function check_config(&$a) {
                foreach($plugins_arr as $p) {
                        if(! in_array($p,$installed_arr)) {
                                logger("Addons: installing " . $p);
+                               $t = filemtime('addon/' . $p . '/' . $p . '.php');
                                @include_once('addon/' . $p . '/' . $p . '.php');
                                if(function_exists($p . '_install')) {
                                        $func = $p . '_install';
                                        $func();
-                                       $r = q("INSERT INTO `addon` (`name`, `installed`) VALUES ( '%s', 1 ) ",
-                                               dbesc($p)
+                                       $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`) VALUES ( '%s', 1, %d ) ",
+                                               dbesc($p),
+                                               intval($t)
                                        );
                                }
                        }
                }
        }
+
+
        load_hooks();
 
        return;
 }}
 
+// reload all updated plugins
+
+if(! function_exists('reload_plugins')) {
+function reload_plugins() {
+       $plugins = get_config('system','addon');
+       if(strlen($plugins)) {
+
+               $r = q("SELECT * FROM `addon` WHERE `installed` = 1");
+               if(count($r))
+                       $installed = $r;
+               else
+                       $installed = array();
+
+               $parr = explode(',',$plugins);
+               if(count($parr)) {
+                       foreach($parr as $pl) {
+                               $pl = trim($pl);
+                               
+                               $t = filemtime('addon/' . $pl . '/' . $pl . '.php');
+                               foreach($installed as $i) {
+                                       if(($i['name'] == $pl) && ($i['timestamp'] != $t)) {    
+                                               logger('Reloading plugin: ' . $i['name']);
+                                               @include_once('addon/' . $pl . '/' . $pl . '.php');
+
+                                               if(function_exists($pl . '_uninstall')) {
+                                                       $func = $pl . '_uninstall';
+                                                       $func();
+                                               }
+                                               if(function_exists($pl . '_install')) {
+                                                       $func = $pl . '_install';
+                                                       $func();
+                                               }
+                                               q("UPDATE `addon` SET `timestamp` = %d WHERE `id` = %d LIMIT 1",
+                                                       intval($t),
+                                                       intval($i['id'])
+                                               );
+                                       }
+                               }
+                       }
+               }
+       }
+}}
+                               
+
 
 // This is our template processor.
 // $s is the string requiring macro substitution.
index 93e444b6b80254053be81b07479dc17d130e7052..f47a5967eabf047394750c8c434524742f80d232 100644 (file)
@@ -451,7 +451,8 @@ CREATE TABLE IF NOT EXISTS `addon` (
 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
 `name` CHAR( 255 ) NOT NULL ,
 `version` CHAR( 255 ) NOT NULL ,
-`installed` TINYINT( 1 ) NOT NULL DEFAULT '0' 
+`installed` TINYINT( 1 ) NOT NULL DEFAULT '0' ,
+`timestamp` BIGINT NOT NULL DEFAULT '0'
 ) ENGINE = MYISAM DEFAULT CHARSET=utf8;
 
 
index fd02e01984d89bb525abc96f2fb548e5a0af6400..a093190a60e9b1f02784f5f6b288e404938ca119 100644 (file)
@@ -47,6 +47,11 @@ function poller_run($argv, $argc){
 
        $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
 
+       $d = datetime_convert();
+       call_hooks('cron', $d);
+
+       reload_plugins();
+
        $contacts = q("SELECT `id` FROM `contact` 
                WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
                $sql_extra 
index 131014d4a4424864b81f85abc19463c685066cb1..422c27c7b273d493fac1d222b7420ae1366a5fcc 100644 (file)
@@ -374,3 +374,6 @@ function update_1038() {
  q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
 }
 
+function update_1039() {
+       q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
+}
\ No newline at end of file