PHP check lists all PHP modules + linted

This commit is contained in:
Shlee 2022-06-25 12:03:00 +09:30 committed by GitHub
parent 13a86ab2b5
commit e0307babf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,10 +66,9 @@ class Installer extends Command
$this->envCreate();
$this->installType();
if($this->installType === 'Advanced') {
if ($this->installType === 'Advanced') {
$this->info('Installer: Advanced...');
$this->checkPHPRequiredDependencies();
$this->checkPHPOptionalDependencies();
$this->checkFFmpegDependencies();
$this->checkOptimiseDependencies();
$this->checkDiskPermissions();
@ -101,7 +100,7 @@ class Installer extends Command
protected function envCheck()
{
if( file_exists(base_path('.env')) &&
if (file_exists(base_path('.env')) &&
filesize(base_path('.env')) !== 0 &&
!$this->option('dangerously-overwrite-env')
) {
@ -117,7 +116,7 @@ class Installer extends Command
{
$this->line('');
$this->info('Creating .env if required');
if(!file_exists(app()->environmentFilePath())) {
if (!file_exists(app()->environmentFilePath())) {
exec('cp .env.example .env');
}
}
@ -140,23 +139,6 @@ class Installer extends Command
'json',
'mbstring',
'openssl',
];
foreach($extensions as $ext) {
if(extension_loaded($ext) == false) {
$this->error("- \"{$ext}\" Required PHP Extension not found, aborting installation");
exit;
}
}
$this->info("- Required PHP extensions found!");
}
protected function checkPHPOptionalDependencies()
{
$this->line(' ');
$this->info('Checking For Optional PHP Extensions...');
$extensions = [
'gd',
'intl',
'xml',
@ -164,13 +146,20 @@ class Installer extends Command
'redis',
];
foreach($extensions as $ext) {
if(extension_loaded($ext) == false) {
foreach ($extensions as $ext) {
if (extension_loaded($ext) == false) {
$this->error("- \"{$ext}\" PHP extension not found");
} else {
$this->info ("- \"{$ext}\" PHP extension found");
$this->info("- \"{$ext}\" PHP extension found");
}
}
$continue = $this->choice('Do you wish to continue?', ['no', 'yes'], 0);
if ($this->continue === 'no') {
$this->info('Exiting Installer.');
exit;
}
}
protected function checkFFmpegDependencies()
@ -179,7 +168,7 @@ class Installer extends Command
$this->info('Checking for Required FFmpeg dependencies...');
$ffmpeg = exec('which ffmpeg');
if(empty($ffmpeg)) {
if (empty($ffmpeg)) {
$this->error("- \"{$ext}\" FFmpeg not found, aborting installation");
exit;
} else {
@ -199,12 +188,12 @@ class Installer extends Command
'gifsicle',
];
foreach($dependencies as $dep) {
foreach ($dependencies as $dep) {
$which = exec("which $dep");
if(empty($which)) {
if (empty($which)) {
$this->error("- \"{$dep}\" not found");
} else {
$this->info ("- \"{$dep}\" found");
$this->info("- \"{$dep}\" found");
}
}
}
@ -217,11 +206,11 @@ class Installer extends Command
$paths = [
base_path('bootstrap'),
base_path('storage')
base_path('storage'),
];
foreach($paths as $path) {
if(is_writeable($path) == false) {
foreach ($paths as $path) {
if (is_writeable($path) == false) {
$this->error("- Invalid permission found! Aborting installation.");
$this->error(" Please make the following path writeable by the web server:");
$this->error(" $path");
@ -282,7 +271,6 @@ class Installer extends Command
$redis_password = $this->ask('Set redis password', 'null');
$redis_port = $this->ask('Set redis port', 6379);
$this->updateEnvFile('REDIS_CLIENT', $redis_client);
$this->updateEnvFile('REDIS_SCHEME', 'tcp');
$this->updateEnvFile('REDIS_HOST', $redis_host);
@ -291,7 +279,7 @@ class Installer extends Command
$this->info('Testing Redis...');
$redis = Redis::connection();
if($redis->ping()) {
if ($redis->ping()) {
$this->info('- Connected to Redis Successfully!');
} else {
$this->error('Cannot connect to Redis, check your details and try again');
@ -307,15 +295,15 @@ class Installer extends Command
$domain = $this->ask('Site Domain [ex: pixelfed.com]');
$domain = strtolower($domain);
if(empty($domain)) {
if (empty($domain)) {
$this->error('You must set the site domain');
exit;
}
if(starts_with($domain, 'http')) {
if (starts_with($domain, 'http')) {
$this->error('The site domain cannot start with https://, you must use the FQDN (eg: example.org)');
exit;
}
if(strpos($domain, '.') == false) {
if (strpos($domain, '.') == false) {
$this->error('You must enter a valid site domain');
exit;
}
@ -381,11 +369,11 @@ class Installer extends Command
$this->info('Media Settings:');
$optimize_media = $this->choice('Optimize media uploads? Requires jpegoptim and other dependencies!', ['false', 'true'], 1);
$image_quality = $this->ask('Set image optimization quality between 1-100. Default is 80%, lower values use less disk space at the expense of image quality.', '80');
if($image_quality < 1) {
if ($image_quality < 1) {
$this->error('Min image quality is 1. You should avoid such a low value, 60 at minimum is recommended.');
exit;
}
if($image_quality > 100) {
if ($image_quality > 100) {
$this->error('Max image quality is 100');
exit;
}
@ -393,17 +381,17 @@ class Installer extends Command
$max_photo_size = $this->ask('Max photo upload size in kilobytes. Default 15000 which is equal to 15MB', '15000');
$max_caption_length = $this->ask('Max caption limit. Default to 500, max 5000.', '500');
if($max_caption_length > 5000) {
if ($max_caption_length > 5000) {
$this->error('Max caption length is 5000 characters.');
exit;
}
$max_album_length = $this->ask('Max photos allowed per album. Choose a value between 1 and 10.', '4');
if($max_album_length < 1) {
if ($max_album_length < 1) {
$this->error('Min album length is 1 photos per album.');
exit;
}
if($max_album_length > 10) {
if ($max_album_length > 10) {
$this->error('Max album length is 10 photos per album.');
exit;
}
@ -421,7 +409,7 @@ class Installer extends Command
$this->info('Note: We recommend running database migrations now!');
$confirm = $this->choice('Do you want to run the database migrations?', ['Yes', 'No'], 0);
if($confirm === 'Yes') {
if ($confirm === 'Yes') {
sleep(3);
$this->line('');
$this->info('Migrating DB:');
@ -437,7 +425,7 @@ class Installer extends Command
$this->call('passport:keys', ['--force' => true]);
$confirm = $this->choice('Do you want to create an admin account?', ['Yes', 'No'], 0);
if($confirm === 'Yes') {
if ($confirm === 'Yes') {
$this->call('user:create');
}
}
@ -458,8 +446,8 @@ class Installer extends Command
}
#####
# Installer Functions
#####
# Installer Functions
#####
protected function checkEnvKeys($key, $error)
{
@ -502,13 +490,13 @@ class Installer extends Command
fclose($file);
}
protected function parseSize($size) {
protected function parseSize($size)
{
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
$size = preg_replace('/[^0-9\.]/', '', $size);
if ($unit) {
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
}
else {
} else {
return round($size);
}
}