Просмотр исходного кода

Merge pull request #1911 from jaapmarcus/fix/composer-version

Update default version composer
Raphael Schneeberger 4 лет назад
Родитель
Сommit
485941f6de

+ 4 - 2
bin/v-add-user-composer

@@ -15,6 +15,7 @@
 
 
 # Argument definition
 # Argument definition
 user=$1
 user=$1
+version=${2-2}
 
 
 if [ -z "$HESTIA" ]; then
 if [ -z "$HESTIA" ]; then
     HESTIA="/usr/local/hestia"
     HESTIA="/usr/local/hestia"
@@ -31,8 +32,9 @@ source $HESTIA/conf/hestia.conf
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-check_args '1' "$#" 'USER'
+check_args '1' "$#" 'USER [VERSION]'
 is_format_valid 'user'
 is_format_valid 'user'
+is_number_format_valid 'version' "$version"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 
 
@@ -78,7 +80,7 @@ if [[ "$signature" != $(sha384sum $COMPOSER_SETUP_FILE | cut -f 1 -d " ") ]]; th
     check_result $E_INVALID "Composer signature does not match"
     check_result $E_INVALID "Composer signature does not match"
 fi
 fi
 
 
-COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --1 --quiet --install-dir="$COMPOSER_DIR" --filename=composer
+COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php "$COMPOSER_SETUP_FILE" --quiet "--$version" --install-dir="$COMPOSER_DIR" --filename=composer
 check_result $? "Composer install failed"
 check_result $? "Composer install failed"
 
 
 [ -f "$COMPOSER_SETUP_FILE" ] && rm -f "$COMPOSER_SETUP_FILE"
 [ -f "$COMPOSER_SETUP_FILE" ] && rm -f "$COMPOSER_SETUP_FILE"

+ 11 - 5
web/src/app/System/HestiaApp.php

@@ -47,7 +47,7 @@ class HestiaApp {
         return $this->run($cmd, $args, $cmd_result);
         return $this->run($cmd, $args, $cmd_result);
     }
     }
 
 
-    public function installComposer()
+    public function installComposer($version)
     {
     {
         exec("curl https://composer.github.io/installer.sig", $output);
         exec("curl https://composer.github.io/installer.sig", $output);
 
 
@@ -69,7 +69,7 @@ class HestiaApp {
         }
         }
 
 
         $install_folder = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer';
         $install_folder = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer';
-        $this->runUser('v-run-cli-cmd', ["/usr/bin/php", $composer_setup, "--1", "--quiet", "--install-dir=".$install_folder, "--filename=composer" ], $status);
+        $this->runUser('v-run-cli-cmd', ["/usr/bin/php", $composer_setup, "--quiet", "--install-dir=".$install_folder, "--filename=composer", "--$version" ], $status);
 
 
         unlink($composer_setup);
         unlink($composer_setup);
 
 
@@ -77,14 +77,20 @@ class HestiaApp {
             throw new \Exception("Error installing composer");
             throw new \Exception("Error installing composer");
         }
         }
     }
     }
+    
+    public function updateComposer($version){
+        $this->runUser('v-run-cli-cmd', ["composer", "selfupdate","--$version"]);
+    }
 
 
-    public function runComposer($args, &$cmd_result=null) : bool
+    public function runComposer($args, &$cmd_result=null,$version=1) : bool
     {
     {
         $composer = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'composer';
         $composer = $this->getUserHomeDir() . DIRECTORY_SEPARATOR . '.composer' . DIRECTORY_SEPARATOR . 'composer';
         if(!is_file($composer)) {
         if(!is_file($composer)) {
-            $this->installComposer();
+            $this->installComposer($version);
+        }else{
+            $this->updateComposer($version);
         }
         }
-
+        
         if (!empty($args) && is_array($args)) {
         if (!empty($args) && is_array($args)) {
             array_unshift($args, 'composer');
             array_unshift($args, 'composer');
         } else {
         } else {

+ 2 - 2
web/src/app/WebApp/Installers/Laravel/LaravelSetup.php

@@ -21,8 +21,8 @@ class LaravelSetup extends BaseSetup {
         ],
         ],
         'database' => true,
         'database' => true,
         'resources' => [
         'resources' => [
-            'composer' => [ 'src' => 'laravel/laravel', 'dst' => '/' ],
-        ],
+            'composer' => [ 'src' => 'laravel/laravel', 'dst' => '/'],
+        ],   
     ];
     ];
 
 
     public function install(array $options=null) : bool
     public function install(array $options=null) : bool

+ 5 - 2
web/src/app/WebApp/Installers/Resources/ComposerResource.php

@@ -15,8 +15,11 @@ class ComposerResource
         $this->folder = dirname($destination);
         $this->folder = dirname($destination);
         $this->project = basename($destination);
         $this->project = basename($destination);
         $this->appcontext = $appcontext;
         $this->appcontext = $appcontext;
-
-        $this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status);
+        if (empty($data['version'])){
+            $data['version'] = 2;
+        }
+        
+        $this->appcontext->runComposer(["create-project", "--no-progress", "--prefer-dist", $data['src'], "-d " . $this->folder, $this->project ], $status, $data['version']);
 
 
         if($status->code !== 0){
         if($status->code !== 0){
             throw new \Exception("Error fetching Composer resource: " . $status->text);
             throw new \Exception("Error fetching Composer resource: " . $status->text);