PrestaShopSetup.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Hestia\WebApp\Installers\Prestashop;
  3. use Hestia\WebApp\Installers\BaseSetup as BaseSetup;
  4. use function Hestiacp\quoteshellarg\quoteshellarg;
  5. class PrestaShopSetup extends BaseSetup {
  6. protected $appInfo = [
  7. "name" => "PrestaShop",
  8. "group" => "ecommerce",
  9. "enabled" => true,
  10. "version" => "8.1.0",
  11. "thumbnail" => "prestashop-thumb.png",
  12. ];
  13. protected $appname = "prestashop";
  14. protected $extractsubdir = "/tmp-prestashop";
  15. protected $config = [
  16. "form" => [
  17. "prestashop_account_first_name" => ["value" => "John"],
  18. "prestashop_account_last_name" => ["value" => "Doe"],
  19. "prestashop_account_email" => "text",
  20. "prestashop_account_password" => "password",
  21. ],
  22. "database" => true,
  23. "resources" => [
  24. "archive" => [
  25. "src" =>
  26. "https://github.com/PrestaShop/PrestaShop/releases/download/8.1.0/prestashop_8.1.0.zip",
  27. ],
  28. ],
  29. "server" => [
  30. "nginx" => [
  31. "template" => "prestashop",
  32. ],
  33. "php" => [
  34. "supported" => ["8.0", "8.1"],
  35. ],
  36. ],
  37. ];
  38. public function install(array $options = null): bool {
  39. parent::install($options);
  40. parent::setup($options);
  41. $this->appcontext->archiveExtract(
  42. $this->getDocRoot($this->extractsubdir . "/prestashop.zip"),
  43. $this->getDocRoot(),
  44. );
  45. //check if ssl is enabled
  46. $this->appcontext->run(
  47. "v-list-web-domain",
  48. [$this->appcontext->user(), $this->domain, "json"],
  49. $status,
  50. );
  51. if ($status->code !== 0) {
  52. throw new \Exception("Cannot list domain");
  53. }
  54. if ($status->json[$this->domain]["SSL"] == "no") {
  55. $ssl_enabled = 0;
  56. } else {
  57. $ssl_enabled = 1;
  58. }
  59. $php_version = $this->appcontext->getSupportedPHP(
  60. $this->config["server"]["php"]["supported"],
  61. );
  62. $this->appcontext->runUser(
  63. "v-run-cli-cmd",
  64. [
  65. "/usr/bin/php" . $options["php_version"],
  66. quoteshellarg($this->getDocRoot("/install/index_cli.php")),
  67. "--db_server=" . quoteshellarg($options["database_host"]),
  68. "--db_user=" .
  69. quoteshellarg($this->appcontext->user() . "_" . $options["database_user"]),
  70. "--db_password=" . quoteshellarg($options["database_password"]),
  71. "--db_name=" .
  72. quoteshellarg($this->appcontext->user() . "_" . $options["database_name"]),
  73. "--firstname=" . quoteshellarg($options["prestashop_account_first_name"]),
  74. "--lastname=" . quoteshellarg($options["prestashop_account_last_name"]),
  75. "--password=" . quoteshellarg($options["prestashop_account_password"]),
  76. "--email=" . quoteshellarg($options["prestashop_account_email"]),
  77. "--domain=" . quoteshellarg($this->domain),
  78. "--ssl=" . (int) $ssl_enabled,
  79. ],
  80. $status,
  81. );
  82. // remove install folder
  83. $this->appcontext->runUser("v-delete-fs-directory", [$this->getDocRoot("/install")]);
  84. $this->cleanup();
  85. return $status->code === 0;
  86. }
  87. }