• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Plugin hook deploy problem

    Scheduled Pinned Locked Moved
    General
    2
    2
    591
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • andyb2000A
      andyb2000
      last edited by andyb2000

      Hi all,
      FOG Running Version 1.4.4 SVN Revision: 6077

      Working on a plugin, I’m using the hooks method to call code on GROUP_DEPLOY_HOST:

      ->register(
                      'GROUP_DEPLOY_POST',
                      array(
                          $this,
                          'groupDeployPost'
                      )
                  )
      

      So then my function “groupDeployPost” contains code like this:

       public function groupDeployPost($arguments)
         {
              global $node;
              global $sub;
              global $id;
              global $type;
      
              if (!in_array($this->node, (array)self::$pluginsinstalled)) {
                  return;
              }
      		self::getClass('MyPluginClass')->myclass_setvlan(113,"666",0);
      	}
      

      (Note I’ve obviously cut a lot of it down, just to give an example.)
      Now in MyPluginClass I have the function myclass_setvlan and I can call that from pretty much anywhere else (I do on the host display screens, other php pages, etc) so I know that calling the class and the function work great.
      However, in this hook it doesn’t work, in fact there are a lot of defined variables, functions, etc that DO NOT work just in this GROUP_DEPLOY_POST hook, which makes me think this is different somehow. (e.g. it works on HOST_TASKING_COMPLETE or HOST_FIELDS etc)

      I get the failure:

      [Wed Jan 31 12:21:04.094317 2018] [php7:error] [pid 23333] [client x.x.x.x:12990] PHP Fatal error:  Uncaught Error: Call to a member function getClass() on null in /var/www/fog/lib/plugins/myplugin/class/myplugin.class.php:49\nStack trace:\n#0 /var/www/fog/lib/plugins/myplugin/hooks/addmypluginhost.hook.php(461): MyPluginClass->myclass_setvlan('113', '666', 0)\n#1 /var/www/fog/lib/fog/hookmanager.class.php(83): AddMyPluginHost->groupDeployPost(Array)\n#2 /var/www/fog/lib/fog/fogpage.class.php(1372): HookManager->processEvent('GROUP_DEPLOY_PO...')\n#3 /var/www/fog/lib/fog/fogpagemanager.class.php(257): FOGPage->deployPost()\n#4 /var/www/fog/management/index.php(58): FOGPageManager->render()\n#5 {main}\n  thrown in /var/www/fog/lib/plugins/myplugin/class/myplugin.class.php on line 49, referer: http://x.x.x.x/fog/management/index.php?node=group&sub=deploy&type=8&id=18
      

      This makes me think there is something missing from the core code hook that’s not passing variables/classes through? Is there a quick and dirty way of forcing this to work, perhaps by referencing my class/php file directly as an include at this point? Just to get me working!

      Thanks in advance.

      Regards,
      Andy
      http://www.thebmwz3.co.uk/
      https://github.com/andyb2000

      1 Reply Last reply Reply Quote 0
      • S
        Sebastian Roth Moderator
        last edited by

        @andyb2000 said in Plugin hook deploy problem:

        function groupDeployPost($arguments)

        I guess you need to give us more context. Hooks are usually

        getClass is defined in class FOGBase (ref) which is inherited by EventManager, which is inherited by Event, which is inherited by Hook. So if you do class myOwnDeployPostHook extends Hook you should be able to use self::getClass(...

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post

        141

        Online

        12.0k

        Users

        17.3k

        Topics

        155.2k

        Posts
        Copyright © 2012-2024 FOG Project