Silent Installer

Say a “friend” was building a silent installer… :slight_smile: Assuming we can capture everything that would normally be in the first time setup form what would be the method of “installing” Omeka S. Are there database migrations and/or other areas that get touched as part of that process?

1 Like

If you poke around a bit, I think you’ll find the installer is already pretty well adapted to a “silent” approach, it just doesn’t have basically the little interface bits in place. My goal was to make it so the Installer would be easily applicable to more than just our default web-based install.

Everything the installer does is encapsulated in “task” classes, which are all just registered in the base configuration file: see here. The “pre” tasks are all just checks for system requirements and similar things, while the regular tasks handle the actual install process.

If you look at the installer class itself you’ll see it’s not coupled with the form or a web request at all, and the part that does interface with the form and request is just a tiny bit of glue ferrying variables into the appropriate tasks.

As for the specific question about migrations, no migrations actually happen at install, but we do record all the existing migrations as “done” so we’ll know which ones are new when they’re added.

I think your best bet would be to actually try to use the existing Installer class as is, so it will run through the same tasks and should give you the same results. The bit of the controller I linked above should tell you what data needs to be sent to what tasks, and beyond that, it should just be a case of a little script bootstrapping the application, getting the Installer from the service manager, and setting the variables.

Perfect, I’ll give it a shot. Thanks John!

For anyone else that might be interested I figured I’d share what I came up with that worked. A single PHP page that is accessed via CURL with the following code (inserting your own variables at the top). I’m a total hack when it comes to PHP and programming so apologies to anyone that looks at my code soup and just groans, but it works! :slight_smile:

<?php
  
  $email = "your@email.com";
  $password = "yourpass";
  $name = "yourname";
  $sitetitle = "Your Installation Title";
  $siteurl = "https://yourinstall.com";
  $timezone = 'America/New_York';
  $locale = 'Default';
  
  use Omeka\Installation\Installer;
  require 'bootstrap.php';
  $config = require OMEKA_PATH . '/application/config/application.config.php';
  $application = Zend\Mvc\Application::init($config);
  $services = $application->getServiceManager();
  $router = $services->get('Router');
  $router->setRequestUri(new \Zend\Uri\Http($siteurl));
  $installer = new Installer($services);
  $installer->registerTask('Omeka\Installation\Task\DestroySessionTask');
  $installer->registerTask('Omeka\Installation\Task\ClearCacheTask');
  $installer->registerTask('Omeka\Installation\Task\InstallSchemaTask');
  $installer->registerTask('Omeka\Installation\Task\RecordMigrationsTask');
  $installer->registerTask('Omeka\Installation\Task\InstallDefaultVocabulariesTask');
  $installer->registerTask('Omeka\Installation\Task\InstallDefaultTemplatesTask');
  $installer->registerTask('Omeka\Installation\Task\CreateFirstUserTask');
  $installer->registerTask('Omeka\Installation\Task\AddDefaultSettingsTask');
  $installer->registerVars(
                    'Omeka\Installation\Task\AddDefaultSettingsTask',
                    [
                        'administrator_email' => $email,
                        'installation_title' => $sitetitle,
                        'time_zone' => $timezone,
                        'locale' => $locale,
                    ]
                );
                
  $installer->registerVars(
                    'Omeka\Installation\Task\CreateFirstUserTask',
                    [
                        'name' => $name,
                        'email' => $email,
                        'password' => $password
                    ]
                );

  $runinstall = $installer->install();

?>

Hey @jflatnes, looks like our installer is broken in 1.4 as a result of https://github.com/omeka/omeka-s/commit/61add085dab42154d65557276c44d168f44bfb21. The password we set is not getting saved presumably because of the change in variable name. What would I change this to for it to use password-confirm[password]?

$installer->registerVars(
                    'Omeka\Installation\Task\CreateFirstUserTask',
                    [
                        'name' => \$name,
                        'email' => \$email,
                        'password' => \$password
                    ]
                );

Just

'password-confirm' => [
    'password' => $password,
]

in that existing array should work.

Perfect, thanks a lot!