Explorar o código

Add a ComposerResource class which is responsible with fetching projects

Robert Zollner %!s(int64=6) %!d(string=hai) anos
pai
achega
6ef78b4c8f

+ 18 - 3
web/add/webapp/installer/BaseSetup.php

@@ -1,5 +1,7 @@
 <?php
 <?php
 
 
+require_once("Resources.php");
+
 function join_paths() {
 function join_paths() {
     $paths = array();
     $paths = array();
 
 
@@ -56,9 +58,22 @@ abstract class BaseSetup {
     }
     }
 
 
     public function retrieveResources() {
     public function retrieveResources() {
-        return $this->appcontext->archiveExtract(
-            $this->getConfig('url'),
-            $this->getDocRoot($this->extractsubdir), 1);
+
+        foreach ($this->getConfig('resources') as $res_type => $res_data) {
+
+            if (!empty($res_data['dst']) && is_string($res_data['dst'])) {
+                $resource_destination = $this->getDocRoot($res_data['dst']);
+            } else {
+                $resource_destination = $this->getDocRoot($this->extractsubdir);
+            }
+
+            if ($res_type === 'composer') {
+                new ComposerResource($this->appcontext, $res_data, $resource_destination);
+            } else {
+                $this->appcontext->archiveExtract($res_data['src'], $resource_destination, 1); 
+            }
+        }
+        return true;
     }
     }
 
 
     public function install($options) {
     public function install($options) {

+ 3 - 5
web/add/webapp/installer/OpencartSetup.php

@@ -8,16 +8,14 @@ class OpencartSetup extends BaseSetup {
 
 
     protected $config = [
     protected $config = [
         'form' => [
         'form' => [
-            'protocol' => [
-                'type' => 'select',
-                'options' => ['http','https'],
-            ],
             'opencart_account_username' => ['value'=>'ocadmin'],
             'opencart_account_username' => ['value'=>'ocadmin'],
             'opencart_account_email' => 'text',
             'opencart_account_email' => 'text',
             'opencart_account_password' => 'password',
             'opencart_account_password' => 'password',
             ],
             ],
         'database' => true,
         'database' => true,
-        'url' => 'https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip'
+        'resources' => [
+            'archive'  => [ 'src' => 'https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip' ],
+        ],
     ];
     ];
 
 
     public function install(array $options) : bool {
     public function install(array $options) : bool {

+ 4 - 5
web/add/webapp/installer/PrestashopSetup.php

@@ -8,17 +8,16 @@ class PrestashopSetup extends BaseSetup {
 
 
     protected $config = [
     protected $config = [
         'form' => [
         'form' => [
-            'protocol' => [
-                'type' => 'select',
-                'options' => ['http','https'],
-            ],
             'prestashop_account_first_name' => ['value'=>'John'],
             'prestashop_account_first_name' => ['value'=>'John'],
             'prestashop_account_last_name' => ['value'=>'Doe'],
             'prestashop_account_last_name' => ['value'=>'Doe'],
             'prestashop_account_email' => 'text',
             'prestashop_account_email' => 'text',
             'prestashop_account_password' => 'password',
             'prestashop_account_password' => 'password',
             ],
             ],
         'database' => true,
         'database' => true,
-        'url' => 'https://github.com/PrestaShop/PrestaShop/releases/download/1.7.6.0/prestashop_1.7.6.0.zip'
+        'resources' => [
+            'archive'  => [ 'src' => 'https://github.com/PrestaShop/PrestaShop/releases/download/1.7.6.0/prestashop_1.7.6.0.zip' ],
+        ],
+
     ];
     ];
 
 
     public function install(array $options) : bool {
     public function install(array $options) : bool {

+ 31 - 0
web/add/webapp/installer/Resources.php

@@ -0,0 +1,31 @@
+<?php
+
+
+class FileResource {
+
+}
+
+class ArchiveResource {
+
+}
+
+class ComposerResource
+{
+    private $project;
+    private $folder;
+    private $appcontext;
+
+    public function __construct(HestiaApp $appcontext, $data, $destination) {
+
+        $this->folder = dirname($destination);
+        $this->project = basename($destination);
+        $this->appcontext = $appcontext;
+
+        $this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status);
+
+        if($status->code !== 0){
+            throw new Exception("Error fetching Composer resource: " . $status->text);
+        }
+
+    }
+}

+ 8 - 5
web/add/webapp/installer/WordpressSetup.php

@@ -6,10 +6,10 @@ class WordpressSetup extends BaseSetup {
     protected $appname = 'wordpress';
     protected $appname = 'wordpress';
     protected $config = [
     protected $config = [
         'form' => [
         'form' => [
-            'protocol' => [ 
-                'type' => 'select',
-                'options' => ['http','https'],
-            ],
+            //'protocol' => [ 
+            //    'type' => 'select',
+            //    'options' => ['http','https'],
+            //],
             'site_name' => ['type'=>'text', 'value'=>'Wordpress Blog'],
             'site_name' => ['type'=>'text', 'value'=>'Wordpress Blog'],
             'site_description' => ['value'=>'Another wordpresss site'],
             'site_description' => ['value'=>'Another wordpresss site'],
             'wordpress_account_username' => ['value'=>'wpadmin'],
             'wordpress_account_username' => ['value'=>'wpadmin'],
@@ -17,7 +17,10 @@ class WordpressSetup extends BaseSetup {
             'wordpress_account_password' => 'password',
             'wordpress_account_password' => 'password',
             ],
             ],
         'database' => true,
         'database' => true,
-        'url' => 'https://wordpress.org/wordpress-5.2.2.tar.gz'
+        'resources' => [
+            'archive'  => [ 'src' => 'https://wordpress.org/wordpress-5.2.2.tar.gz' ],
+        ],
+        
     ];
     ];
 
 
     public function install(array $options) : bool {
     public function install(array $options) : bool {