snipe-it/upgrade.php

197 lines
7.1 KiB
PHP
Raw Normal View History

2017-09-25 20:30:18 -07:00
<?php
(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])) && die('Access denied.');
2018-08-02 20:55:52 -07:00
$required_version = '7.1.3';
2017-11-08 20:28:18 -08:00
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
2017-12-12 09:10:05 -08:00
echo "Skipping user check as it is not supported on Windows\n";
2017-11-08 20:28:18 -08:00
} else {
2017-12-12 09:10:05 -08:00
$pwu_data = posix_getpwuid(posix_geteuid());
$username = $pwu_data['name'];
2017-12-12 09:10:05 -08:00
if (($username=='root') || ($username=='admin')) {
die("\nERROR: This script should not be run as root/admin. Exiting.\n\n");
}
}
2017-10-02 20:11:07 -07:00
// Check if a branch or tag was passed in the command line,
// otherwise just use master
(array_key_exists('1', $argv)) ? $branch = $argv[1] : $branch = 'master';
2017-10-02 20:11:07 -07:00
2017-09-25 20:30:18 -07:00
echo "Welcome to the Snipe-IT upgrader.\n\n";
2017-09-26 13:05:34 -07:00
echo "Please note that this script will not download the latest Snipe-IT \n";
2017-10-02 20:11:07 -07:00
echo "files for you unless you have git installed. \n";
echo "It simply runs the standard composer and artisan \n";
2017-11-16 16:50:16 -08:00
echo "commands needed to finalize the upgrade after. \n\n";
2017-09-25 20:30:18 -07:00
2017-09-26 13:05:34 -07:00
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
2017-11-16 16:50:16 -08:00
echo "!! If you have any encrypted custom fields, BE SURE TO run the recrypter if upgrading from v3 to v4. \n";
2017-09-26 13:05:34 -07:00
echo "!! See the Snipe-IT documentation for help: \n";
echo "!! https://snipe-it.readme.io/docs/upgrading-to-v4\n";
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "STEP 1: Checking PHP requirements: \n";
echo "--------------------------------------------------------\n\n";
echo "Current PHP version: " . PHP_VERSION . "\n\n";
if (version_compare(PHP_VERSION, $required_version, '<')) {
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
echo "This version of PHP is not compatible with Snipe-IT.\n";
echo "Snipe-IT requires PHP version ".$required_version." or greater. Please upgrade \n";
echo "your server's version of PHP (mod and cli) and try running this script again.\n\n\n";
exit;
} else {
echo "PHP version: " . PHP_VERSION . " is at least ".$required_version." - continuing... \n\n";
}
echo "--------------------------------------------------------\n";
echo "STEP 2: Backing up database: \n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
$backup = shell_exec('php artisan snipeit:backup');
2017-09-26 13:05:34 -07:00
echo '-- '.$backup."\n\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "STEP 3: Putting application into maintenance mode: \n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
$down = shell_exec('php artisan down');
2017-09-26 13:05:34 -07:00
echo '-- '.$down."\n\n";
2017-09-25 20:30:18 -07:00
2017-10-02 20:11:07 -07:00
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "STEP 4: Pulling latest from Git (".$branch." branch): \n";
2017-10-02 20:11:07 -07:00
echo "--------------------------------------------------------\n\n";
$git_version = shell_exec('git --version');
if ((strpos('git version', $git_version)) === false) {
echo "Git is installed. \n";
$git_fetch = shell_exec('git fetch');
2017-10-02 20:11:07 -07:00
$git_checkout = shell_exec('git checkout '.$branch);
$git_stash = shell_exec('git stash');
$git_pull = shell_exec('git pull');
echo '-- '.$git_fetch;
2017-10-02 20:32:42 -07:00
echo '-- '.$git_stash;
echo '-- '.$git_checkout;
echo '-- '.$git_pull;
2017-10-02 20:11:07 -07:00
} else {
echo "Git is NOT installed. You can still use this upgrade script to run common \n";
echo "migration commands, but you will have to manually download the updated files. \n\n";
}
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "Step 5: Cleaning up old cached files:\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
if (file_exists('bootstrap/cache/compiled.php')) {
2018-09-05 14:57:30 -07:00
echo "-- Deleting bootstrap/cache/compiled.php. It is no longer used.\n";
2017-09-25 20:30:18 -07:00
@unlink('bootstrap/cache/compiled.php');
} else {
echo "-- No bootstrap/cache/compiled.php, so nothing to delete.\n";
}
if (file_exists('bootstrap/cache/services.php')) {
echo "-- Deleting bootstrap/cache/services.php. It it no longer used.\n";
@unlink('bootstrap/cache/services.php');
} else {
echo "-- No bootstrap/cache/services.php, so nothing to delete.\n";
}
if (file_exists('bootstrap/cache/config.php')) {
echo "-- Deleting bootstrap/cache/config.php. It it no longer used.\n";
@unlink('bootstrap/cache/config.php');
} else {
echo "-- No bootstrap/cache/config.php, so nothing to delete.\n";
}
$config_clear = shell_exec('php artisan config:clear');
$cache_clear = shell_exec('php artisan cache:clear');
2017-09-26 13:05:34 -07:00
$route_clear = shell_exec('php artisan route:clear');
$view_clear = shell_exec('php artisan view:clear');
echo '-- '.$config_clear;
echo '-- '.$cache_clear;
echo '-- '.$route_clear;
echo '-- '.$view_clear;
2017-09-25 20:30:18 -07:00
echo "\n";
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "Step 6: Updating composer dependencies:\n";
2017-09-25 21:50:41 -07:00
echo "(This may take an moment.)\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
// Composer install
if (file_exists('composer.phar')) {
2017-09-26 13:05:34 -07:00
echo "-- Local composer.phar detected, so we'll use that.\n\n";
echo "-- Updating local composer.phar\n\n";
$composer_update = shell_exec('php composer.phar self-update');
echo $composer_update."\n\n";
2017-09-26 13:05:34 -07:00
$composer_dump = shell_exec('php composer.phar dump');
2017-11-09 13:25:44 -08:00
$composer = shell_exec('php composer.phar install --no-dev --prefer-source');
2017-09-26 13:05:34 -07:00
2017-09-25 20:30:18 -07:00
} else {
2017-09-26 13:05:34 -07:00
echo "-- We couldn't find a local composer.phar - trying globally.\n\n";
$composer_dump = shell_exec('composer dump');
$composer = shell_exec('composer install --no-dev --prefer-source');
2017-09-25 20:30:18 -07:00
}
2017-09-26 13:05:34 -07:00
echo $composer_dump."\n\n";
2017-09-25 20:30:18 -07:00
echo $composer."\n\n";
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "Step 7: Migrating database:\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
$migrations = shell_exec('php artisan migrate --force');
2017-09-26 13:05:34 -07:00
echo '-- '.$migrations."\n\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "Step 8: Checking for OAuth keys:\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
if ((!file_exists('storage/oauth-public.key')) || (!file_exists('storage/oauth-private.key'))) {
echo "- No OAuth keys detected. Running passport install now.\n\n";
$passport = shell_exec('php artisan passport:install');
echo $passport;
} else {
echo "- OAuth keys detected. Skipping passport install.\n\n";
}
echo "--------------------------------------------------------\n";
2018-08-02 20:55:52 -07:00
echo "Step 9: Caching routes and config:\n";
2017-09-26 13:05:34 -07:00
echo "--------------------------------------------------------\n\n";
$config_cache = shell_exec('php artisan config:cache');
$route_cache = shell_exec('php artisan route:cache');
echo '-- '.$config_cache;
echo '-- '.$route_cache;
echo "\n";
echo "--------------------------------------------------------\n";
[WIP] Added #5957 - Flysystem support (#6262) * Added AWS url to example env * Upgrader - added check for new storage path and attempt to move * Ignore symlink * Updated paths for models * Moved copy methods * Added AWS_URL support For some reasin, Flysystem was generating the wrong AWS url (with a region included) * Switch to Flysystem for image uploads * Nicer display of image preview * Updated image preview on edit blades to use Flysystem * Twiddled some more paths * Working filesystems config * Updated Asset Models and Departments to use Flysystem * Janky workaround for differing S3/local urls/paths * Try to smartly use S3 as public disk if S3 is configured * Use public disk Storage options for public files * Additional transformer edits for Flysystem * Removed debugging * Added missing use Storage directive * Updated seeders to use Flysystem * Default logo * Set a default width We can potentially override this in settings later * Use Flysystem for logo upload * Update downloadFile to use Flysystem * Updated AssetFilesController to use Flysystem * Updated acceptance signatures to use Flysystem * Updated signature view to use Flysystem This isn’t working 100% yet * Use Flysystem facade for displaying asset image * Set assets path Should clean all these up when we’re done here * Added Rackspace support for Flysystem * Added Flysystem migrator console command * Added use Storage directive for categories * Added user avatars to Flysystem * Added profile avatar to Flysystem * Added the option to delete local files with the migrator * Added a check to prevent people from trying to move from local to local * Fixed the selectlists for Flysystem * Fixed the getImageUrl method to reflect Flysystem * Fixed AWS copy process * Fixed models path * More selectlist updates for Flysystem * Updated example .envs with updated env variable names * *sigh* * Updated non-asset getImageUrl() methods to use Flysystem * Removed S3 hardcoding * Use Flysystem in email headers * Fixed typo * Removed camera support from asset file upload We’ll find a way to add this in later (and add that support to all of the other image uploads as well) * Fixed path for categories * WIP - Switched to standard handleImages for asset upload. This is currently broken as I refact the handleImages method. Because the assets store/create methods use their own Form Request, the handleImages method doesn’t exist in that Form Request so it wil error now. * Fixed css URL error * Updated Debugbar to latest version (#6265) v3.2 adds support for Laravel 5.7 * Fixed: Missing CSS file in basic.blade.php (#6264) * Fixed missing CSS file in basic.blade.php * Added * Changed stylesheet import for authorize.blade.php * Updated composer lock * Added AWS_BUCKET_ROOT as env variable * Use nicer image preview for logo upload * Removed AssetRequest form request * Removed asset form request, moved custom field validation into model * Added additional help text for logo upload * Increased the size of the image resize - should make this a setting tho * Few more formatting tweaks to logo section of branding blade preview * Use Flysystem for asset/license file uploads * Use Flysystem for removing images from models that have been deleted * Enable backups to use Flysystem This only handles part of the problem. This just makes it so we can ship files to S3 if we want, but does not account for how we backup files that are hosted on S3 * Use Flysystem to download license files * Updated audits to use Flysystem
2018-09-29 21:33:52 -07:00
echo "Step 10: Taking application out of maintenance mode:\n";
2017-09-25 20:30:18 -07:00
echo "--------------------------------------------------------\n\n";
$up = shell_exec('php artisan up');
2017-09-26 13:05:34 -07:00
echo '-- '.$up."\n\n";
2017-09-25 20:30:18 -07:00
[WIP] Added #5957 - Flysystem support (#6262) * Added AWS url to example env * Upgrader - added check for new storage path and attempt to move * Ignore symlink * Updated paths for models * Moved copy methods * Added AWS_URL support For some reasin, Flysystem was generating the wrong AWS url (with a region included) * Switch to Flysystem for image uploads * Nicer display of image preview * Updated image preview on edit blades to use Flysystem * Twiddled some more paths * Working filesystems config * Updated Asset Models and Departments to use Flysystem * Janky workaround for differing S3/local urls/paths * Try to smartly use S3 as public disk if S3 is configured * Use public disk Storage options for public files * Additional transformer edits for Flysystem * Removed debugging * Added missing use Storage directive * Updated seeders to use Flysystem * Default logo * Set a default width We can potentially override this in settings later * Use Flysystem for logo upload * Update downloadFile to use Flysystem * Updated AssetFilesController to use Flysystem * Updated acceptance signatures to use Flysystem * Updated signature view to use Flysystem This isn’t working 100% yet * Use Flysystem facade for displaying asset image * Set assets path Should clean all these up when we’re done here * Added Rackspace support for Flysystem * Added Flysystem migrator console command * Added use Storage directive for categories * Added user avatars to Flysystem * Added profile avatar to Flysystem * Added the option to delete local files with the migrator * Added a check to prevent people from trying to move from local to local * Fixed the selectlists for Flysystem * Fixed the getImageUrl method to reflect Flysystem * Fixed AWS copy process * Fixed models path * More selectlist updates for Flysystem * Updated example .envs with updated env variable names * *sigh* * Updated non-asset getImageUrl() methods to use Flysystem * Removed S3 hardcoding * Use Flysystem in email headers * Fixed typo * Removed camera support from asset file upload We’ll find a way to add this in later (and add that support to all of the other image uploads as well) * Fixed path for categories * WIP - Switched to standard handleImages for asset upload. This is currently broken as I refact the handleImages method. Because the assets store/create methods use their own Form Request, the handleImages method doesn’t exist in that Form Request so it wil error now. * Fixed css URL error * Updated Debugbar to latest version (#6265) v3.2 adds support for Laravel 5.7 * Fixed: Missing CSS file in basic.blade.php (#6264) * Fixed missing CSS file in basic.blade.php * Added * Changed stylesheet import for authorize.blade.php * Updated composer lock * Added AWS_BUCKET_ROOT as env variable * Use nicer image preview for logo upload * Removed AssetRequest form request * Removed asset form request, moved custom field validation into model * Added additional help text for logo upload * Increased the size of the image resize - should make this a setting tho * Few more formatting tweaks to logo section of branding blade preview * Use Flysystem for asset/license file uploads * Use Flysystem for removing images from models that have been deleted * Enable backups to use Flysystem This only handles part of the problem. This just makes it so we can ship files to S3 if we want, but does not account for how we backup files that are hosted on S3 * Use Flysystem to download license files * Updated audits to use Flysystem
2018-09-29 21:33:52 -07:00
2017-09-25 21:50:41 -07:00
echo "--------------------------------------------------------\n";
echo "FINISHED! Clear your browser cookies and re-login to use :\n";
echo "your upgraded Snipe-IT.\n";
echo "--------------------------------------------------------\n\n";
2017-09-25 20:30:18 -07:00