Community
    • Categories
    • Recent
    • Popular
    • Users
    • Search
    • Register
    • Login

    Commands im Add-on nutzen

    Scheduled Pinned Locked Moved Entwicklung
    4 Posts 2 Posters 139 Views
    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.
    • cherifC Offline
      cherif
      last edited by

      Hallo zusammen,

      ich versuche, einen Console-Command in einem Add-on zu implementieren, stoße dabei jedoch auf ein Problem mit den Klassen.

      In der Command-Klasse (rot markiert) versuche ich, auf eine Methode der Manager-Klasse (grün markiert) zuzugreifen. Beim Ausführen des Befehls
      php console.php tools:sync
      erhalte ich jedoch die unten stehende Fehlermeldung.

      Offenbar ist es mir aktuell nicht möglich, auf eine Klasse außerhalb zuzugreifen. In der GUI sind die Klassen jedoch erreichbar.

      Könnte mir bitte jemand dabei helfen oder einen Hinweis geben, woran das liegen könnte?

      Vielen Dank im Voraus!

      Cherif

      PHP Fatal error: Uncaught Error: Class "idoit\Module\tools\Manager\MyManager" not found in /var/www/i-doit/src/classes/modules/tools/src/Console/Command/MyCommand.php:88
      Stack trace:
      #0 /var/www/i-doit/vendor/symfony/console/Command/Command.php(326): idoit\Module\tools\Console\Command\MyCommand->execute()
      #1 /var/www/i-doit/vendor/symfony/console/Application.php(1088): Symfony\Component\Console\Command\Command->run()
      #2 /var/www/i-doit/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand()
      #3 /var/www/i-doit/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun()
      #4 /var/www/i-doit/console.php(26): Symfony\Component\Console\Application->run()
      #5 {main}

      in init.php
      Psr4AutoloaderClass::factory() ->addNamespace('idoit\Module\tools', DIR . '/src/');

      in der MyCommand.php:
      namespace idoit\Module\tools\Console\Command;

      use idoit\Console\Command\AbstractCommand;
      use Symfony\Component\Console\Command\Command;
      use Symfony\Component\Console\Input\InputDefinition;
      use Symfony\Component\Console\Input\InputInterface;
      use Symfony\Component\Console\Input\InputOption;
      use Symfony\Component\Console\Output\OutputInterface;
      use idoit\Module\tools\Manager\MyManager;

      class MyCommand extends AbstractCommand
      {
      ...

      in der MyManager.php
      namespace idoit\Module\tools\Manager;

      use Exception;
      use isys_application;
      use isys_component_dao_result;
      use isys_exception_dao;
      use isys_exception_database;
      use isys_cmdb_dao;

      class MyManager extends isys_cmdb_dao
      {
      ...

      18336614-518d-414e-ac35-287ecd3e8046-image.jpeg

      LFischerL 1 Reply Last reply Reply Quote 0
      • LFischerL Offline
        LFischer @cherif
        last edited by

        Hey @cherif das klingt nach einem Problem mit dem Autoloader, ein offensichtliches Problem springt mir hier aber nicht ins Auge 🤔

        Was mir aber auffällt: Dein Namespace beinhaltet tool mit kleinem t - üblicherweise werden Namespaces im "CamelCase" Format geschrieben.

        Oder hast du inzwischen schon eine eigene Lösung gefunden?

        Viele Grüße
        Leo

        cherifC 1 Reply Last reply Reply Quote 0
        • cherifC Offline
          cherif @LFischer
          last edited by

          Hey @LFischer
          Ich habe bis jetzt leider keine Lösung gefunden.

          Danke für deine Antwort. Leider liegt das Problem nicht am kleinen „t“ in Namespace. Ich habe es auch mit Tools versucht – leider ebenfalls ohne Erfolg.

          An anderer Stelle funktioniert es, nur in der Command-Klasse gibt es dieses Problem.
          in der Command-Klasse funktioniert es auch mit isys_auth_tools nicht.

          Nochmal danke für deine Unterstützung!

          VG, Cherif

          in init.php
          use idoit\Psr4AutoloaderClass;

          if (isys_module_manager::instance()->is_active('tools')) {

          # Initialize autoloader
          if (file_exists(__DIR__ . '/isys_module_tools_autoload.class.php') && (include_once __DIR__ . '/isys_module_tools_autoload.class.php'))
          {
              spl_autoload_register('isys_module_tools_autoload::init');
          }
          
          Psr4AutoloaderClass::factory()
              ->addNamespace('idoit\Module\Tools', __DIR__ . '/src/');
          

          }

          in isys_module_tools_autoload.php

          class isys_module_tools_autoload extends isys_module_manager_autoload
          {
          /**
          * Autoloader
          *
          * @param string $className
          * @return boolean
          */
          public static function init($className)
          {
          $addOnPath = '/src/classes/modules/tools/';

              $classList = [
                  'isys_auth_tools'  => 'auth/isys_auth_tools.class.php',
          
                  #Manager
                  'idoit\\Module\\Tools\\Manager\\ADSyncManager' => 'src/Manager/ADSyncManager.php',
                  'idoit\\Module\\Tools\\Manager\\AbstractManager' => 'src/Manager/AbstractManager.php',
          
              ];
              
              
              if (isset($classList[$className]) && parent::include_file($addOnPath . $classList[$className])) {
                  isys_caching::factory('autoload')->set($className, $addOnPath . $classList[$className]);
          
                  return true;
              }
              
              return false;
          }
          

          }

          in ADSyncManager
          namespace idoit\Module\Tools\Manager;

          use Exception;
          use isys_cmdb_dao;

          class ADSyncManager extends isys_cmdb_dao
          {
          ...
          }

          in ADSyncCommand
          namespace idoit\Module\Tools\Console\Command;

          use idoit\Console\Command\AbstractCommand;
          use Symfony\Component\Console\Command\Command;
          use idoit\Module\Tools\Manager\ADSyncManager;
          class ADSyncCommand extends AbstractCommand
          {
          ...
          protected function execute(InputInterface $input, OutputInterface $output): int
          {
          $mngr= ADSyncManager($database);
          }
          }

          LFischerL 1 Reply Last reply Reply Quote 0
          • LFischerL Offline
            LFischer @cherif
            last edited by

            Hey @cherif

            das ist tatsächlich merkwürdig. Kannst du ggf. in deiner init.php eine Debug Ausgabe machen um zu prüfen ob diese durchlaufen wird BEVOR der Command seine Logik ausführt?

            Setzt dein Command den Login voraus (-u admin -p admin ...)? Die Prüfung if (isys_module_manager::instance()->is_active('tools')) { ... } in der init.php kann nur funktionieren, wenn du (auch über die CLI) eingeloggt bist.

            Zum debuggen kannst du die Funktion print_ar_file('xyz'); nutzen - diese schreibt dann im Hintergrund eine Datei ins i-doit Temp Verzeichnis: temp/debug_output.txt.

            Viele Grüße
            Leo

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post