OpencartSetup.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Hestia\WebApp\Installers\Opencart;
  3. use \Hestia\WebApp\Installers\BaseSetup as BaseSetup;
  4. class OpencartSetup extends BaseSetup {
  5. protected $appInfo = [
  6. 'name' => 'Opencart',
  7. 'group' => 'ecommerce',
  8. 'enabled' => true,
  9. 'version' => '3.0.3.3',
  10. 'thumbnail' => 'opencart-thumb.png'
  11. ];
  12. protected $appname = 'opencart';
  13. protected $extractsubdir="/tmp-opencart";
  14. protected $config = [
  15. 'form' => [
  16. 'opencart_account_username' => ['value'=>'ocadmin'],
  17. 'opencart_account_email' => 'text',
  18. 'opencart_account_password' => 'password',
  19. ],
  20. 'database' => true,
  21. 'resources' => [
  22. 'archive' => [ 'src' => 'https://github.com/opencart/opencart/releases/download/3.0.3.3/opencart-3.0.3.3.zip' ],
  23. ],
  24. ];
  25. public function install(array $options = null) : bool
  26. {
  27. parent::install($options);
  28. $this->appcontext->runUser('v-copy-fs-directory',[
  29. $this->getDocRoot($this->extractsubdir . "/upload/."),
  30. $this->getDocRoot()], $result);
  31. $this->appcontext->runUser('v-copy-fs-file',[$this->getDocRoot("config-dist.php"), $this->getDocRoot("config.php")]);
  32. $this->appcontext->runUser('v-copy-fs-file',[$this->getDocRoot("admin/config-dist.php"), $this->getDocRoot("admin/config.php")]);
  33. $this->appcontext->runUser('v-copy-fs-file',[$this->getDocRoot(".htaccess.txt"), $this->getDocRoot(".htaccess")]);
  34. $this->appcontext->runUser('v-run-cli-cmd', [
  35. "/usr/bin/php",
  36. $this->getDocRoot("/install/cli_install.php"),
  37. "install",
  38. "--db_username " . $this->appcontext->user() . '_' .$options['database_user'],
  39. "--db_password " . $options['database_password'],
  40. "--db_database " . $this->appcontext->user() . '_' .$options['database_name'],
  41. "--username " . $options['opencart_account_username'],
  42. "--password " . $options['opencart_account_password'],
  43. "--email " . $options['opencart_account_email'],
  44. "--http_server " . "http://" . $this->domain . "/"], $status);
  45. // After install, 'storage' folder must be moved to a location where the web server is not allowed to serve file
  46. // - Opencart Nginx template and Apache ".htaccess" forbids acces to /storage folder
  47. $this->appcontext->runUser('v-move-fs-directory', [$this->getDocRoot("system/storage"), $this->getDocRoot()], $result);
  48. $this->appcontext->runUser('v-run-cli-cmd', [ "sed", "-i", "s/'storage\//'..\/storage\// ", $this->getDocRoot("config.php") ], $status);
  49. $this->appcontext->runUser('v-run-cli-cmd', [ "sed", "-i", "s/'storage\//'..\/storage\// ", $this->getDocRoot("admin/config.php") ], $status);
  50. $this->appcontext->runUser('v-run-cli-cmd', [ "sed", "-i", "s/\^system\/storage\//^\/storage\// ", $this->getDocRoot(".htaccess") ], $status);
  51. $this->appcontext->runUser('v-change-fs-file-permission',[$this->getDocRoot("config.php"), '640']);
  52. $this->appcontext->runUser('v-change-fs-file-permission',[$this->getDocRoot("admin/config.php"), '640']);
  53. // remove install folder
  54. $this->appcontext->runUser('v-delete-fs-directory', [$this->getDocRoot("/install")]);
  55. $this->cleanup();
  56. return ($status->code === 0);
  57. }
  58. }