snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

${var} deprecation error while upgrading to v7

Open DasRedy opened this issue 1 year ago • 2 comments

Debug mode

Describe the bug

While i was trying to upgrade to v7, i came across some errors with the {var} deprecation in newer php versions which i can´t figure out.

I started from ubuntu 20.04.06 LTS with php7.4 and snipe-it v6.4.2. Added the repository ppa:ondrej/php, ppa:ondrej/apache1 and ppa:ondrej/nginx and installed php8.3 with all used extras. I decided to update ubuntu to 22.04.4 LTS while im at it, which went smoothly. Up until this point, snipe-it was still up and running.

Cd into my installation path, git pull and php upgrade.php as per the upgrade guide. First run, i got some permission errors, so changed these with chmod.

--------------------------------------------------------
STEP 3: Checking directory permissions: 
--------------------------------------------------------

√ /var/www/html/snipeit/storage is writable 

--------------------------------------------------------
The following directories/files do not seem writable: 
--------------------------------------------------------
✘ PERMISSIONS ERROR: /var/www/html/snipeit/bootstrap/cache is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/logs is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/logs/laravel.log is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/framework is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/framework/cache is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/framework/sessions is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/framework/views is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/app is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/app/backups is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/app/backup-temp is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/storage/private_uploads is NOT writable
✘ PERMISSIONS ERROR: /var/www/html/snipeit/public/uploads is NOT writable
--------------------- !! ERROR !! ----------------------
Please check the permissions on the directories above and re-run this script.
------------------------- :( ---------------------------

Rerun the update after changing the permissions which led to the problems i´m now facing, log attached. Does anybody have any idea what went wrong?

--------------------------------------------------------
WELCOME TO THE SNIPE-IT UPGRADER! 
--------------------------------------------------------

This script will attempt to: 

- validate some very basic .env file settings 
- check your PHP version and extension requirements 
- check directory permissions 
- do a git pull to bring you to the latest version 
- run composer install to get your vendors up to date 
- run migrations to get your schema up to date 
- clear out old cache settings

Launching using branch: master
Found PHP requirements, will check for PHP > 8.1.0 and < 8.4.0
Proceed with upgrade? [y/N]: y

--------------------------------------------------------
STEP 1: Checking .env file: 
- Your .env is located at /var/www/html/snipeit/.env 
--------------------------------------------------------

√ Your APP_KEY is not blank. 
√ Your APP_URL is not null or blank. It is set to http://example.com
√ Your APP_URL is set to http://example.com and starts with the protocol (https:// or http://)
√ Your APP_URL (http://example.com) does not have a trailing slash.

--------------------------------------------------------
STEP 2: Checking PHP requirements: (Required PHP >=8.1.0 - <8.4.0) 
--------------------------------------------------------

√ Current PHP version: (8.3.8) is at least 8.1.0 and less than 8.4.0! Continuing... 
FYI: The php.ini used by this PHP is: /etc/php/8.3/cli/php.ini

Checking Required PHP extensions... 

√ bcmath is installed!
√ curl is installed!
√ exif is installed!
√ fileinfo is installed!
√ gd is installed!
√ json is installed!
√ ldap is installed!
√ mbstring is installed!
√ mysqli is installed!
√ openssl is installed!
√ PDO is installed!
√ sodium is installed!
√ tokenizer is installed!
√ xml is installed!
√ zip is installed!

--------------------------------------------------------
STEP 3: Checking directory permissions: 
--------------------------------------------------------

√ /var/www/html/snipeit/bootstrap/cache is writable 
√ /var/www/html/snipeit/storage is writable 
√ /var/www/html/snipeit/storage/logs is writable 
√ /var/www/html/snipeit/storage/logs/laravel.log is writable 
√ /var/www/html/snipeit/storage/framework is writable 
√ /var/www/html/snipeit/storage/framework/cache is writable 
√ /var/www/html/snipeit/storage/framework/sessions is writable 
√ /var/www/html/snipeit/storage/framework/views is writable 
√ /var/www/html/snipeit/storage/app is writable 
√ /var/www/html/snipeit/storage/app/backups is writable 
√ /var/www/html/snipeit/storage/app/backup-temp is writable 
√ /var/www/html/snipeit/storage/private_uploads is writable 
√ /var/www/html/snipeit/public/uploads is writable 

--------------------------------------------------------
STEP 4: Backing up database: 
--------------------------------------------------------

PHP Fatal error:  Uncaught Whoops\Exception\ErrorException: Using ${var} in strings is deprecated, use {$var} instead in /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
Stack trace:
#0 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): Whoops\Run->handleError()
#1 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): include()
#2 /var/www/html/snipeit/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile()
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(50): class_implements()
#5 [internal function]: Facade\Ignition\SolutionProviders\SolutionProviderRepository->Facade\Ignition\SolutionProviders\{closure}()
#6 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(717): array_filter()
#7 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(358): Illuminate\Support\Arr::where()
#8 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(49): Illuminate\Support\Collection->filter()
#9 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Adapters/Laravel/IgnitionSolutionsRepository.php(36): Facade\Ignition\SolutionProviders\SolutionProviderRepository->getSolutionsForThrowable()
#10 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(244): NunoMaduro\Collision\Adapters\Laravel\IgnitionSolutionsRepository->getFromThrowable()
#11 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(123): NunoMaduro\Collision\Writer->renderSolution()
#12 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Handler.php(39): NunoMaduro\Collision\Writer->write()
#13 /var/www/html/snipeit/vendor/filp/whoops/src/Whoops/Run.php(370): NunoMaduro\Collision\Handler->handle()
#14 [internal function]: Whoops\Run->handleException()
#15 {main}
  thrown in /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php on line 52
PHP Fatal error:  Uncaught Whoops\Exception\ErrorException: Using ${var} in strings is deprecated, use {$var} instead in /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
Stack trace:
#0 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): Whoops\Run->handleError()
#1 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): include()
#2 /var/www/html/snipeit/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile()
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(50): class_implements()
#5 [internal function]: Facade\Ignition\SolutionProviders\SolutionProviderRepository->Facade\Ignition\SolutionProviders\{closure}()
#6 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(717): array_filter()
#7 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(358): Illuminate\Support\Arr::where()
#8 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(49): Illuminate\Support\Collection->filter()
#9 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Adapters/Laravel/IgnitionSolutionsRepository.php(36): Facade\Ignition\SolutionProviders\SolutionProviderRepository->getSolutionsForThrowable()
#10 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(244): NunoMaduro\Collision\Adapters\Laravel\IgnitionSolutionsRepository->getFromThrowable()
#11 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(123): NunoMaduro\Collision\Writer->renderSolution()
#12 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Handler.php(39): NunoMaduro\Collision\Writer->write()
#13 /var/www/html/snipeit/vendor/filp/whoops/src/Whoops/Run.php(370): NunoMaduro\Collision\Handler->handle()
#14 [internal function]: Whoops\Run->handleException()
#15 {main}
  thrown in /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php on line 52
-- 
   TypeError

  Carbon\Carbon::setLastErrors(): Argument #1 ($lastErrors) must be of type array, false given, called in /var/www/html/snipeit/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php on line 98

  at vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:928
    924▕      * @param array $lastErrors
    925▕      *
    926▕      * @return void
    927▕      */
  ➜ 928▕     private static function setLastErrors(array $lastErrors)
    929▕     {
    930▕         static::$lastErrors = $lastErrors;
    931▕     }
    932▕

   Whoops\Exception\ErrorException

  Using ${var} in strings is deprecated, use {$var} instead

  at vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
     48▕     }
     49▕
     50▕     protected function getCurrentBranch(string $directory): string
     51▕     {
  ➜  52▕         $branch = "'".trim(shell_exec("cd ${directory}; git branch | grep \\* | cut -d ' ' -f2"))."'";
     53▕
     54▕         if ($branch === "''") {
     55▕             $branch = 'current branch';
     56▕         }

   Symfony\Component\ErrorHandler\Error\FatalError

  Uncaught Whoops\Exception\ErrorException: Using ${var} in strings is deprecated, use {$var} instead in /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
Stack trace:
#0 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): Whoops\Run->handleError()
#1 /var/www/html/snipeit/vendor/composer/ClassLoader.php(571): include()
#2 /var/www/html/snipeit/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile()
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass()
#4 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(50): class_implements()
#5 [internal function]: Facade\Ignition\SolutionProviders\SolutionProviderRepository->Facade\Ignition\SolutionProviders\{closure}()
#6 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(717): array_filter()
#7 /var/www/html/snipeit/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(358): Illuminate\Support\Arr::where()
#8 /var/www/html/snipeit/vendor/facade/ignition/src/SolutionProviders/SolutionProviderRepository.php(49): Illuminate\Support\Collection->filter()
#9 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Adapters/Laravel/IgnitionSolutionsRepository.php(36): Facade\Ignition\SolutionProviders\SolutionProviderRepository->getSolutionsForThrowable()
#10 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(244): NunoMaduro\Collision\Adapters\Laravel\IgnitionSolutionsRepository->getFromThrowable()
#11 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Writer.php(123): NunoMaduro\Collision\Writer->renderSolution()
#12 /var/www/html/snipeit/vendor/nunomaduro/collision/src/Handler.php(39): NunoMaduro\Collision\Writer->write()
#13 /var/www/html/snipeit/vendor/filp/whoops/src/Whoops/Run.php(370): NunoMaduro\Collision\Handler->handle()
#14 [internal function]: Whoops\Run->handleException()
#15 {main}
  thrown

  at vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
     48▕     }
     49▕
     50▕     protected function getCurrentBranch(string $directory): string
     51▕     {
  ➜  52▕         $branch = "'".trim(shell_exec("cd ${directory}; git branch | grep \\* | cut -d ' ' -f2"))."'";
     53▕
     54▕         if ($branch === "''") {
     55▕             $branch = 'current branch';
     56▕         }

   Whoops\Exception\ErrorException

  Using ${var} in strings is deprecated, use {$var} instead

  at vendor/facade/ignition/src/SolutionProviders/MergeConflictSolutionProvider.php:52
     48▕     }
     49▕
     50▕     protected function getCurrentBranch(string $directory): string
     51▕     {
  ➜  52▕         $branch = "'".trim(shell_exec("cd ${directory}; git branch | grep \\* | cut -d ' ' -f2"))."'";
     53▕
     54▕         if ($branch === "''") {
     55▕             $branch = 'current branch';
     56▕         }

Something went wrong with your backup. Aborting!

Reproduction steps

  1. Add repository ppa:ondrej/php
  2. Install php8.3
  3. Update to Ubuntu 22.04.4 LTS
  4. Run upgrader
  5. change folder permissions
  6. rerun upgrader

Expected behavior

Not sure what to expect but a smooth upgrade

Screenshots

No response

Snipe-IT Version

6.4.2 -> 7.0.7

Operating System

22.04.4

Web Server

apache

PHP Version

8.3

Operating System

No response

Browser

No response

Version

No response

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

No response

Additional context

No response

DasRedy avatar Jul 03 '24 09:07 DasRedy

I think the problem is that the php artisan snipeit:backup command is running on your old version of Snipe-IT, which doesn't support PHP 8.3. After that runs, it will try to run php artisan down which also will run on that old version.

You can downgrade to php v8.1 as a workaround, possibly? Or maybe comment those lines out in the upgrade script (if you're okay running without a backup, I'm hoping you have some other way of snapshotting or backing up!)

You might also try to turn off E_DEPRECATED in your php.ini, which might let you get through those Artisan commands, though I'm not sure if there might be some other PHP issue that could come up.

Another option might be to do the upgrade "by hand" - running git pull and composer install and so on (read the script for hints).

uberbrady avatar Jul 03 '24 10:07 uberbrady

Thanks, i´ll test it out. I have backups and snapshot from every step, so nothing will be lost.

Easiest would probably be to go back to the state before the php upgrade, upgrade to 8.1 instead of 8.3 and then doing the snipe-it upgrade. After that a upgrade to php8.3 should be possibly, even if it´s not necessary at that point, right?

DasRedy avatar Jul 03 '24 13:07 DasRedy

So, i figured it out and i´m all set and updated. I´m summing it up for anybody who might stumple upon the same thing:

As uberbrady suggested, first upgrade from php7.x to 8.1 (including every package you have). What i used for this was this command: dpkg -l | grep php7.x | cut -f3 -d' ' | xargs | sed 's/7.x/8.1/g' which gave me all my php packages in the new php version. Copy that into clipboard. Install ondrejs php repository with the extra apache2 or nginx repositorys if needed. install the packages you have in your clipboard and then run the snipeit upgrader. If needed change directory permissions.

if your ran into the same error as me after restarting the server Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.2". you probably forgot to disable the old php version and enable the new one. Just sudo a2dismod php7.x and sudo a2enmod php8.1 and then sudo service apache2 restart. Worked for me then.

After that, upgrade to php8.3 was easy.

DasRedy avatar Jul 05 '24 09:07 DasRedy