From 4f9fc04457049b3ac5e50d74257a6b33929c905a Mon Sep 17 00:00:00 2001 From: Daniel Kouba Date: Fri, 15 Jul 2016 16:21:17 +0200 Subject: [PATCH] adding server-side composer update --- public/composer.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/public/composer.php b/public/composer.php index 837c6da..1ed72ad 100644 --- a/public/composer.php +++ b/public/composer.php @@ -12,7 +12,6 @@ die('Access Denied - security token not provided'); } - echo '
   ______
   / ____/___  ____ ___  ____  ____  ________  _____
  / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
@@ -21,23 +20,21 @@
                     /_/
 
 ';
+
+//Configuration
 define('ROOT_DIR',realpath('../'));
 define('EXTRACT_DIRECTORY', ROOT_DIR. '/storage/composer');
 define('HOME_DIRECTORY', ROOT_DIR. '/storage/composer/home');
 define('COMPOSER_INITED', file_exists(ROOT_DIR.'/vendor'));
-
 set_time_limit(100);
 ini_set('memory_limit',-1);  //could be forbidden on server
-
-if (!getenv('HOME') && !getenv('COMPOSER_HOME')) {
-    putenv("COMPOSER_HOME=".HOME_DIRECTORY);
-}
+if (!getenv('HOME') && !getenv('COMPOSER_HOME')) {  putenv("COMPOSER_HOME=".HOME_DIRECTORY);  }
 
 
+//Extracting Composer library
 if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
     echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted.\n";
-}
-else{
+} else {
     $composerPhar = new Phar("../composer.phar");
     //php.ini setting phar.readonly must be set to 0
     $composerPhar->extractTo(EXTRACT_DIRECTORY);
@@ -46,8 +43,6 @@
 // change directory to root
 chdir(ROOT_DIR);
 
-
-
 //This requires the phar to have been extracted successfully.
 require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php');
 
@@ -65,9 +60,26 @@
 }
 $input = new ArrayInput($args);
 
+
 //Create the application and run it with the commands
 $application = new Application();
 $application->setAutoExit(false);
-$application->run($input);
+$application->setCatchExceptions(false);
+try {
+    //Running commdand php.ini allow_url_fopen=1
+    $exitCode = $application->run($input);
+} catch (\Exception $e) {
+    $exitCode = 1;
+    echo 'Error: '.$e->getMessage()."\n";
+}
+
 
-echo "Done
"; \ No newline at end of file +//Result message +if($exitCode ==0) { + echo "Successfully Done"; +} elseif($exitCode ==2) { + echo "Composer Failed due to dependency solving error"; +} else { + echo "Composer Failed due to generic error"; +} +die('');