Skip to content

Commit 485941f

Browse files
authored
Merge pull request hestiacp#1911 from jaapmarcus/fix/composer-version
Update default version composer
2 parents 620332a + d5db080 commit 485941f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

bin/v-add-user-composer

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# Argument definition
1717
user=$1
18+
version=${2-2}
1819

1920
if [ -z "$HESTIA" ]; then
2021
HESTIA="/usr/local/hestia"
@@ -31,8 +32,9 @@ source $HESTIA/conf/hestia.conf
3132
# Verifications #
3233
#----------------------------------------------------------#
3334

34-
check_args '1' "$#" 'USER'
35+
check_args '1' "$#" 'USER [VERSION]'
3536
is_format_valid 'user'
37+
is_number_format_valid 'version' "$version"
3638
is_object_valid 'user' 'USER' "$user"
3739
is_object_unsuspended 'user' 'USER' "$user"
3840

@@ -78,7 +80,7 @@ if [[ "$signature" != $(sha384sum $COMPOSER_SETUP_FILE | cut -f 1 -d " ") ]]; th
7880
check_result $E_INVALID "Composer signature does not match"
7981
fi
8082

81-
COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --1 --quiet --install-dir="$COMPOSER_DIR" --filename=composer
83+
COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --quiet "--$version" --install-dir="$COMPOSER_DIR" --filename=composer
8284
check_result $? "Composer install failed"
8385

8486
[ -f "$COMPOSER_SETUP_FILE" ] && rm -f "$COMPOSER_SETUP_FILE"

web/src/app/System/HestiaApp.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function runUser(string $cmd, $args, &$cmd_result=null) : bool
4747
return $this->run($cmd, $args, $cmd_result);
4848
}
4949

50-
public function installComposer()
50+
public function installComposer($version)
5151
{
5252
exec("curl https://composer.github.io/installer.sig", $output);
5353

@@ -69,22 +69,28 @@ public function installComposer()
6969
}
7070

7171
$install_folder = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer';
72-
$this->runUser('v-run-cli-cmd', ["/usr/bin/php", $composer_setup, "--1", "--quiet", "--install-dir=".$install_folder, "--filename=composer" ], $status);
72+
$this->runUser('v-run-cli-cmd', ["/usr/bin/php", $composer_setup, "--quiet", "--install-dir=".$install_folder, "--filename=composer", "--$version" ], $status);
7373

7474
unlink($composer_setup);
7575

7676
if ($status->code !== 0 ) {
7777
throw new \Exception("Error installing composer");
7878
}
7979
}
80+
81+
public function updateComposer($version){
82+
$this->runUser('v-run-cli-cmd', ["composer", "selfupdate","--$version"]);
83+
}
8084

81-
public function runComposer($args, &$cmd_result=null) : bool
85+
public function runComposer($args, &$cmd_result=null,$version=1) : bool
8286
{
8387
$composer = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'composer';
8488
if(!is_file($composer)) {
85-
$this->installComposer();
89+
$this->installComposer($version);
90+
}else{
91+
$this->updateComposer($version);
8692
}
87-
93+
8894
if (!empty($args) && is_array($args)) {
8995
array_unshift($args, 'composer');
9096
} else {

web/src/app/WebApp/Installers/Laravel/LaravelSetup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class LaravelSetup extends BaseSetup {
2121
],
2222
'database' => true,
2323
'resources' => [
24-
'composer' => [ 'src' => 'laravel/laravel', 'dst' => '/' ],
25-
],
24+
'composer' => [ 'src' => 'laravel/laravel', 'dst' => '/'],
25+
],
2626
];
2727

2828
public function install(array $options=null) : bool

web/src/app/WebApp/Installers/Resources/ComposerResource.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ public function __construct(HestiaApp $appcontext, $data, $destination)
1515
$this->folder = dirname($destination);
1616
$this->project = basename($destination);
1717
$this->appcontext = $appcontext;
18-
19-
$this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status);
18+
if (empty($data['version'])){
19+
$data['version'] = 2;
20+
}
21+
22+
$this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status, $data['version']);
2023

2124
if($status->code !== 0){
2225
throw new \Exception("Error fetching Composer resource: " . $status->text);

0 commit comments

Comments
 (0)