1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

RFC Plugin installation wizards

Discussion in 'Contributing & RFCs' started by SOFe, Feb 5, 2017.

?

Should this be added?

  1. Agreed to a large extent

    44.4%
  2. Agreed

    44.4%
  3. Neutral (Why did you vote then?)

    11.1%
  4. Disagreed

    0 vote(s)
    0.0%
  5. Disagreed to a large extent

    0 vote(s)
    0.0%
  1. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Introduction
    Some plugins require configuration before being run the first time on the server. It gets awkward what the plugin should do the first time it is run -- you can't expect the user to priorly create config files, because default config files aren't created yet; you can't continue to run, because the config values are required; there are no default values, because you require something like MySQL credentials, online API tokens, or custom passwords, etc.; you don't want to stop the server completely, because users will yell "This plugin crashed my server upon installation" (usually with a bit worse English and "Sorry for bad English" behind that); you don't want to just disable your plugin, because users may not notice your alert on console and complain that your plugin isn't working.

    Proposal
    It is proposed that a first-run wizard API similar to the PocketMine installation wizard be exposed to plugins. It is expected that plugins can simply run a few lines to ask for necessary values:

    PHP:
    public function onEnable() {
        
    $special FirstRunWizard::init($this"special.yml"// will try to load dataFolder/special.yml if exists
            
    ->query("mysql.host""Please enter MySQL host""127.0.0.1"// will query for mysql.host if not present in special.yml
            
    ->query("mysql.user""Please enter MySQL username""root"// otherwise will just continue running
            
    ->query("mysql.password""Please enter MySQL password""", function(string $inputstring &$problem) : bool{
                if(
    strlen($input) > 4){
                    
    $problem "Password too short!";
                    return 
    false;
                }
                return 
    true;
            }) 
    // function to validate input
            
    ->query("server-password""Please enter the password to use this plugin"// no default value
            
    ->flush(); // store, if any, new values queried into special.yml
        // flush() returns the data in special
        
    $mysql = new mysqli($special["mysql"]["host"], $special["mysql"]["user"], $special["mysql"]["password"]);
    }
    There is necessity for an API to receive input from console directly, because there is right now no reliable method to query data from console without racing with the CommandReader thread.

    Also works well with updates, since only unused values are queried.

    P.S. Possible implementation of FirstRunWizard:
    PHP:
    class FirstRunWizard{
      public static function 
    init(Plugin $plugin$file) : FirstRunWizard{
        
    $data is_file($plugin->getDataFolder() . $file) ? yaml_parse_file($plugin->getDataFolder() . $file) : [];
        return new 
    FirstRunWizard($plugin$file$data);
      }
      private function 
    __construct($plugin$file$data){ /* skipped */ }
      public function 
    query(string $keystring $questionstring $default "", callable $validate null) : FirstRunWizard{
        if(!
    $this->exists($key)){ // similar implementation as Config
          
    velociraptor// https://xkcd.com/292
          
    echo $question" [$default] ";
          
    $input api_method_to_read_stdin();
          if(
    $validate !== null){
            if(!
    $validate($input$problem)){
              echo 
    $problem;
              goto 
    velociraptor;
            }
          }
          
    $this->set($key$input);
        }
        return 
    $this;
      }
      public function 
    flush(){
        
    yaml_emit_file($this->file$this->data;
        return 
    $this->data;
      }
    }
     
    Last edited: Feb 5, 2017
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Added RFC prefix.
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it somewhat works, to some extend
    but what about on multi craft as example?
    even if it works no one would expect they need to go on console and input some value
    i am expecting PM threads wont work until info have been entered which users would just complain it make the server worst, cant even be joined all without any realizition of input is needed via console
     
  4. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Then simply skip the wizard when the --no-wizard argument is passed in the startup params. Plugins should still be able to function without going through the wizard, it would exist as a way to help less advanced users get slightly more advanced plugins running quickly.
     
    falk likes this.
  5. Matthew

    Matthew Baby Zombie

    Messages:
    167
    GitHub:
    matthww
    It's really useful for not advanced people. But as Jack said there should be a '--no-wizard' argument.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Could you elaborate more? MultiCraft still has a console, right? It doesn't block the server when auto restarting; basically, it only blocks the server when a new plugin is installed. The trivial user should at least stay and see if the plugin works...
    Otherwise, the MultiCraft host can automatically generate the config files. They should either not let users apply these plugins directly, or force users to enter the required values and generate the config file at the appropriate location before installing the plugin.
    The main point of this RFC is that some configuration cannot have default values... I'm especially referring to plugins that completely depend on the configuration, such as MySQL database, or an online API access token. Say, I have a plugin that sends a message to my Slack channel every time someone joins (for whatever stupid reason). How could I put a default value for the API token used here? My point is that plugins that are unable to function without going through the wizard need installation wizards.
     
    jasonwynn10 likes this.
  7. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    And advanced users will know they need to edit the config files to setup the plugin so it will work won't they? A plugin installation wizard shouldn't be necessary, no matter what information is required for the plugin to run, there should be a way to skip it; even if it's simply to help with consistency between the included wizards within PocketMine.
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This has nothing to do with advanced users or not. I don't know why you keep mentioning advanced users. A wizard is supposed to help people setup, not to reserve features for advanced users.
    What is the logic of this? I'm not talking about consistency at all. A plugin requires a MySQL connection, and you must enter it before using the plugin. What's so controversial about this? A user normally looks at his console the first time he installs the plugin, unless the plugin is automatically updated, which then is the responsibility of the automatic updater.
     
    jasonwynn10 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.