DrupalSetup.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hestia\WebApp\Installers\Drupal;
  4. use Hestia\WebApp\BaseSetup;
  5. use Hestia\WebApp\InstallationTarget\InstallationTarget;
  6. use function sprintf;
  7. class DrupalSetup extends BaseSetup
  8. {
  9. protected array $info = [
  10. 'name' => 'Drupal',
  11. 'group' => 'cms',
  12. 'version' => 'latest',
  13. 'thumbnail' => 'drupal-thumb.png',
  14. ];
  15. protected array $config = [
  16. 'form' => [
  17. 'username' => ['type' => 'text', 'value' => 'admin'],
  18. 'password' => 'password',
  19. 'email' => 'text',
  20. ],
  21. 'database' => true,
  22. 'resources' => [
  23. 'composer' => ['src' => 'drupal/recommended-project', 'dst' => '/'],
  24. ],
  25. 'server' => [
  26. 'nginx' => [
  27. 'template' => 'drupal-composer',
  28. ],
  29. 'php' => [
  30. 'supported' => ['8.1', '8.2', '8.3'],
  31. ],
  32. ],
  33. ];
  34. protected function setupApplication(InstallationTarget $target, array $options): void
  35. {
  36. $this->appcontext->createFile(
  37. $target->getDocRoot('.htaccess'),
  38. '<IfModule mod_rewrite.c>
  39. RewriteEngine On
  40. RewriteRule ^(.*)$ web/$1 [L]
  41. </IfModule>',
  42. );
  43. $this->appcontext->runComposer($options['php_version'], [
  44. 'require',
  45. '-d',
  46. $target->getDocRoot(),
  47. 'drush/drush',
  48. ]);
  49. $databaseUrl = sprintf(
  50. 'mysql://%s:%s@%s:3306/%s',
  51. $target->database->user,
  52. $target->database->password,
  53. $target->database->host,
  54. $target->database->name,
  55. );
  56. $this->appcontext->runPHP(
  57. $options['php_version'],
  58. $target->getDocRoot('/vendor/drush/drush/drush.php'),
  59. [
  60. 'site-install',
  61. 'standard',
  62. '--db-url=' . $databaseUrl,
  63. '--account-name=' . $options['username'],
  64. '--account-pass=' . $options['password'],
  65. '--site-name=Drupal', // Sadly even when escaped spaces are splitted up
  66. '--site-mail=' . $options['email'],
  67. ],
  68. );
  69. }
  70. }