-
Notifications
You must be signed in to change notification settings - Fork 4
/
composer.php
85 lines (69 loc) · 2.41 KB
/
composer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Performs server-side composer update
* @author Daniel Kouba <dan@brainz.cz>
*
*/
//Access Check - TODO! implement better solution - i.e. IP whitelist
date_default_timezone_set('CET');
if( @$_GET['date']==!date('Y-m-d',time()) ) {
die('Access Denied - security token not provided');
}
echo '<pre> ______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ UPDATE
/_/
';
//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); }
//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 {
$composerPhar = new Phar("../composer.phar");
//php.ini setting phar.readonly must be set to 0
$composerPhar->extractTo(EXTRACT_DIRECTORY);
}
// change directory to root
chdir(ROOT_DIR);
//This requires the phar to have been extracted successfully.
require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php');
//Use the Composer classes
use Composer\Console\Application;
use Composer\Command\UpdateCommand;
use Symfony\Component\Console\Input\ArrayInput;
//Create the commands
$args = array('command' => 'update');
if(!COMPOSER_INITED) {
echo "This is first composer run: --no-scripts option is applies\n";
$args['--no-scripts']=true;
}
$input = new ArrayInput($args);
//Create the application and run it with the commands
$application = new Application();
$application->setAutoExit(false);
$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";
}
//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('</pre>');