Laravel – How to revert back composer update

composer-phplaravel

Today I ran composer update and the update broke my site completely. I found in the php.log the following information:

72.15.153.139 – – [11/Nov/2015:21:01:45 -0500] "GET / HTTP/1.1" 500 – "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"
[Wed Nov 11 21:01:48 2015] [error] [client 127.7.179.129] PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\ (T_NS_SEPARATOR) in /var/lib/openshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danielstjules/stringy/tests/CreateTest.php on line 5
72.15.153.139 – – [11/Nov/2015:21:01:48 -0500] "GET / HTTP/1.1" 500 – "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0"

Seems that "danielstjules/stringy" is the one to blame. But how can I revert back to an older version (or using a news version?) of this package? I tried to modify composer.lock file, and changed

            "require": {
            "danielstjules/stringy": "~1.8",

to

        "require": {
            "danielstjules/stringy": "~1.9",

and run composer update again, but it gave the information:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \ (T_NS_SEPARATOR) in /var/lib/openshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danielstjules/stringy/tests/CreateTest.php on line 5
Script php artisan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException]
Error Output: PHP Parse error: syntax error, unexpected 'function' (T_FUNC
TION), expecting identifier (T_STRING) or \ (T_NS_SEPARATOR) in /var/lib/o
penshift/55c481747628e14556000188/app-root/runtime/repo/config/vendor/danie
lstjules/stringy/tests/CreateTest.php on line 5

How can I rollback this package? Thanks.

EDIT 2:

composer install will modify composer.lock automatically. I modified composer.json instead, and it fetched the old version 1.8 successfully.

But the build still failed. This issue description had the reason. But after I rm -rf test/, the problem was still there.

EDIT 3:

I tried the following:

  1. rm -rf vendor/
  2. composer update

The problem was gone.

Best Answer

How to revert an update? Easy: Restore the composer.lock file from your version control system that was used before you updated.

The composer.lock exactly records which software was installed. So it is paramount to commit this file into version control in order to be able to go back to a working version in case of update failure.

Running composer install will always install the software versions recorded in composer.lock, it will only act like update if this file is not present.

Related Topic