Plugin init order issue

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a plugin, which is using another plugin. The issue is that, I am calling some other plugin information in the init function, and I do receive sometimes this error:



2018-11-07 11:44:57 [-][-][k91hcavi6st542afnhsvhdp61u][error][yiibaseErrorException:8] yiibaseErrorException: Trying to get property 'mobileDetectService' of non-object in /home/forge/plugins/releases/20181106223004/src/services/CacheService.php:193
Stack trace:
#0 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yiibaseErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193)
#1 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(193): craftwebErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193, Array)
#2 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(126): trendspublishingcraftpluginservicesCacheService->_generateUri('/hubs/bathroom')
#3 /home/forge/plugins/releases/20181106223004/src/Plugin.php(90): trendspublishingcraftpluginservicesCacheService->uriToFilePath('/hubs/bathroom')
#4 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/BaseObject.php(109): trendspublishingcraftpluginPlugin->init()
#5 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/Module.php(158): yiibaseBaseObject->__construct(Array)
#6 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/base/Plugin.php(113): yiibaseModule->__construct('craftplugin', Object(craftwebApplication), Array)
#7 [internal function]: craftbasePlugin->__construct('craftplugin', Object(craftwebApplication), Array)


This is the error in question:



$mobile_detect = MobileDetect::$plugin->mobileDetectService;


I am not able to replicate it, sometimes a simple database reload is helping sometimes not. So that's why I am only guessing, because I do invoke this call from the plugin init function, that's why the other plugin is not ready yet...
Any thought, best practice on this one?










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have a plugin, which is using another plugin. The issue is that, I am calling some other plugin information in the init function, and I do receive sometimes this error:



    2018-11-07 11:44:57 [-][-][k91hcavi6st542afnhsvhdp61u][error][yiibaseErrorException:8] yiibaseErrorException: Trying to get property 'mobileDetectService' of non-object in /home/forge/plugins/releases/20181106223004/src/services/CacheService.php:193
    Stack trace:
    #0 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yiibaseErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193)
    #1 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(193): craftwebErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193, Array)
    #2 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(126): trendspublishingcraftpluginservicesCacheService->_generateUri('/hubs/bathroom')
    #3 /home/forge/plugins/releases/20181106223004/src/Plugin.php(90): trendspublishingcraftpluginservicesCacheService->uriToFilePath('/hubs/bathroom')
    #4 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/BaseObject.php(109): trendspublishingcraftpluginPlugin->init()
    #5 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/Module.php(158): yiibaseBaseObject->__construct(Array)
    #6 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/base/Plugin.php(113): yiibaseModule->__construct('craftplugin', Object(craftwebApplication), Array)
    #7 [internal function]: craftbasePlugin->__construct('craftplugin', Object(craftwebApplication), Array)


    This is the error in question:



    $mobile_detect = MobileDetect::$plugin->mobileDetectService;


    I am not able to replicate it, sometimes a simple database reload is helping sometimes not. So that's why I am only guessing, because I do invoke this call from the plugin init function, that's why the other plugin is not ready yet...
    Any thought, best practice on this one?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a plugin, which is using another plugin. The issue is that, I am calling some other plugin information in the init function, and I do receive sometimes this error:



      2018-11-07 11:44:57 [-][-][k91hcavi6st542afnhsvhdp61u][error][yiibaseErrorException:8] yiibaseErrorException: Trying to get property 'mobileDetectService' of non-object in /home/forge/plugins/releases/20181106223004/src/services/CacheService.php:193
      Stack trace:
      #0 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yiibaseErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193)
      #1 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(193): craftwebErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193, Array)
      #2 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(126): trendspublishingcraftpluginservicesCacheService->_generateUri('/hubs/bathroom')
      #3 /home/forge/plugins/releases/20181106223004/src/Plugin.php(90): trendspublishingcraftpluginservicesCacheService->uriToFilePath('/hubs/bathroom')
      #4 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/BaseObject.php(109): trendspublishingcraftpluginPlugin->init()
      #5 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/Module.php(158): yiibaseBaseObject->__construct(Array)
      #6 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/base/Plugin.php(113): yiibaseModule->__construct('craftplugin', Object(craftwebApplication), Array)
      #7 [internal function]: craftbasePlugin->__construct('craftplugin', Object(craftwebApplication), Array)


      This is the error in question:



      $mobile_detect = MobileDetect::$plugin->mobileDetectService;


      I am not able to replicate it, sometimes a simple database reload is helping sometimes not. So that's why I am only guessing, because I do invoke this call from the plugin init function, that's why the other plugin is not ready yet...
      Any thought, best practice on this one?










      share|improve this question













      I have a plugin, which is using another plugin. The issue is that, I am calling some other plugin information in the init function, and I do receive sometimes this error:



      2018-11-07 11:44:57 [-][-][k91hcavi6st542afnhsvhdp61u][error][yiibaseErrorException:8] yiibaseErrorException: Trying to get property 'mobileDetectService' of non-object in /home/forge/plugins/releases/20181106223004/src/services/CacheService.php:193
      Stack trace:
      #0 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yiibaseErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193)
      #1 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(193): craftwebErrorHandler->handleError(8, 'Trying to get p...', '/home/forge/plu...', 193, Array)
      #2 /home/forge/plugins/releases/20181106223004/src/services/CacheService.php(126): trendspublishingcraftpluginservicesCacheService->_generateUri('/hubs/bathroom')
      #3 /home/forge/plugins/releases/20181106223004/src/Plugin.php(90): trendspublishingcraftpluginservicesCacheService->uriToFilePath('/hubs/bathroom')
      #4 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/BaseObject.php(109): trendspublishingcraftpluginPlugin->init()
      #5 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/yiisoft/yii2/base/Module.php(158): yiibaseBaseObject->__construct(Array)
      #6 /home/forge/new.trendsideas.com/releases/20181106223038/vendor/craftcms/cms/src/base/Plugin.php(113): yiibaseModule->__construct('craftplugin', Object(craftwebApplication), Array)
      #7 [internal function]: craftbasePlugin->__construct('craftplugin', Object(craftwebApplication), Array)


      This is the error in question:



      $mobile_detect = MobileDetect::$plugin->mobileDetectService;


      I am not able to replicate it, sometimes a simple database reload is helping sometimes not. So that's why I am only guessing, because I do invoke this call from the plugin init function, that's why the other plugin is not ready yet...
      Any thought, best practice on this one?







      plugin-development






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Visky Máté

      11710




      11710




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          What I do is I listen for the Plugins::EVENT_AFTER_LOAD_PLUGINS event, and then do my code that relies on other plugins being loaded:



           // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
          Event::on(
          Plugins::class,
          Plugins::EVENT_AFTER_LOAD_PLUGINS,
          function ()
          // Do stuff only after all other plugins have loaded

          );





          share|improve this answer




















          • Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
            – Visky Máté
            28 mins ago











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "563"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28332%2fplugin-init-order-issue%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote













          What I do is I listen for the Plugins::EVENT_AFTER_LOAD_PLUGINS event, and then do my code that relies on other plugins being loaded:



           // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
          Event::on(
          Plugins::class,
          Plugins::EVENT_AFTER_LOAD_PLUGINS,
          function ()
          // Do stuff only after all other plugins have loaded

          );





          share|improve this answer




















          • Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
            – Visky Máté
            28 mins ago















          up vote
          3
          down vote













          What I do is I listen for the Plugins::EVENT_AFTER_LOAD_PLUGINS event, and then do my code that relies on other plugins being loaded:



           // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
          Event::on(
          Plugins::class,
          Plugins::EVENT_AFTER_LOAD_PLUGINS,
          function ()
          // Do stuff only after all other plugins have loaded

          );





          share|improve this answer




















          • Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
            – Visky Máté
            28 mins ago













          up vote
          3
          down vote










          up vote
          3
          down vote









          What I do is I listen for the Plugins::EVENT_AFTER_LOAD_PLUGINS event, and then do my code that relies on other plugins being loaded:



           // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
          Event::on(
          Plugins::class,
          Plugins::EVENT_AFTER_LOAD_PLUGINS,
          function ()
          // Do stuff only after all other plugins have loaded

          );





          share|improve this answer












          What I do is I listen for the Plugins::EVENT_AFTER_LOAD_PLUGINS event, and then do my code that relies on other plugins being loaded:



           // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
          Event::on(
          Plugins::class,
          Plugins::EVENT_AFTER_LOAD_PLUGINS,
          function ()
          // Do stuff only after all other plugins have loaded

          );






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 29 mins ago









          andrew.welch

          7,4291223




          7,4291223











          • Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
            – Visky Máté
            28 mins ago

















          • Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
            – Visky Máté
            28 mins ago
















          Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
          – Visky Máté
          28 mins ago





          Yes, we have this event, and it is working like charm, but in this case is not good. I have to make a decision in realtime (routing decision for cache). Is there any way to manually instantiate the plugin and store it into the proper place? I am trying to use something like this... but guess this is not the best method:( $mobile_detect = (new superbigmobiledetectservicesMobileDetectService())->getMobileDetect();
          – Visky Máté
          28 mins ago


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcraftcms.stackexchange.com%2fquestions%2f28332%2fplugin-init-order-issue%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery