Skip to content

Commit 6ef78b4

Browse files
committed
Add a ComposerResource class which is responsible with fetching projects
1 parent 1d4ca7f commit 6ef78b4

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

web/add/webapp/installer/BaseSetup.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
require_once("Resources.php");
4+
35
function join_paths() {
46
$paths = array();
57

@@ -56,9 +58,22 @@ public function getDocRoot($docrelative=null) : string {
5658
}
5759

5860
public function retrieveResources() {
59-
return $this->appcontext->archiveExtract(
60-
$this->getConfig('url'),
61-
$this->getDocRoot($this->extractsubdir), 1);
61+
62+
foreach ($this->getConfig('resources') as $res_type => $res_data) {
63+
64+
if (!empty($res_data['dst']) && is_string($res_data['dst'])) {
65+
$resource_destination = $this->getDocRoot($res_data['dst']);
66+
} else {
67+
$resource_destination = $this->getDocRoot($this->extractsubdir);
68+
}
69+
70+
if ($res_type === 'composer') {
71+
new ComposerResource($this->appcontext, $res_data, $resource_destination);
72+
} else {
73+
$this->appcontext->archiveExtract($res_data['src'], $resource_destination, 1);
74+
}
75+
}
76+
return true;
6277
}
6378

6479
public function install($options) {

web/add/webapp/installer/OpencartSetup.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ class OpencartSetup extends BaseSetup {
88

99
protected $config = [
1010
'form' => [
11-
'protocol' => [
12-
'type' => 'select',
13-
'options' => ['http','https'],
14-
],
1511
'opencart_account_username' => ['value'=>'ocadmin'],
1612
'opencart_account_email' => 'text',
1713
'opencart_account_password' => 'password',
1814
],
1915
'database' => true,
20-
'url' => 'https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip'
16+
'resources' => [
17+
'archive' => [ 'src' => 'https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip' ],
18+
],
2119
];
2220

2321
public function install(array $options) : bool {

web/add/webapp/installer/PrestashopSetup.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ class PrestashopSetup extends BaseSetup {
88

99
protected $config = [
1010
'form' => [
11-
'protocol' => [
12-
'type' => 'select',
13-
'options' => ['http','https'],
14-
],
1511
'prestashop_account_first_name' => ['value'=>'John'],
1612
'prestashop_account_last_name' => ['value'=>'Doe'],
1713
'prestashop_account_email' => 'text',
1814
'prestashop_account_password' => 'password',
1915
],
2016
'database' => true,
21-
'url' => 'https://github.com/PrestaShop/PrestaShop/releases/download/1.7.6.0/prestashop_1.7.6.0.zip'
17+
'resources' => [
18+
'archive' => [ 'src' => 'https://github.com/PrestaShop/PrestaShop/releases/download/1.7.6.0/prestashop_1.7.6.0.zip' ],
19+
],
20+
2221
];
2322

2423
public function install(array $options) : bool {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
4+
class FileResource {
5+
6+
}
7+
8+
class ArchiveResource {
9+
10+
}
11+
12+
class ComposerResource
13+
{
14+
private $project;
15+
private $folder;
16+
private $appcontext;
17+
18+
public function __construct(HestiaApp $appcontext, $data, $destination) {
19+
20+
$this->folder = dirname($destination);
21+
$this->project = basename($destination);
22+
$this->appcontext = $appcontext;
23+
24+
$this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status);
25+
26+
if($status->code !== 0){
27+
throw new Exception("Error fetching Composer resource: " . $status->text);
28+
}
29+
30+
}
31+
}

web/add/webapp/installer/WordpressSetup.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ class WordpressSetup extends BaseSetup {
66
protected $appname = 'wordpress';
77
protected $config = [
88
'form' => [
9-
'protocol' => [
10-
'type' => 'select',
11-
'options' => ['http','https'],
12-
],
9+
//'protocol' => [
10+
// 'type' => 'select',
11+
// 'options' => ['http','https'],
12+
//],
1313
'site_name' => ['type'=>'text', 'value'=>'Wordpress Blog'],
1414
'site_description' => ['value'=>'Another wordpresss site'],
1515
'wordpress_account_username' => ['value'=>'wpadmin'],
1616
'wordpress_account_email' => 'text',
1717
'wordpress_account_password' => 'password',
1818
],
1919
'database' => true,
20-
'url' => 'https://wordpress.org/wordpress-5.2.2.tar.gz'
20+
'resources' => [
21+
'archive' => [ 'src' => 'https://wordpress.org/wordpress-5.2.2.tar.gz' ],
22+
],
23+
2124
];
2225

2326
public function install(array $options) : bool {

0 commit comments

Comments
 (0)