TransWikia.com

Upgrading Craft CMS fails

Craft CMS Asked on March 11, 2021

I’m trying to upgrade from 3.3.15 -> 3.5.5 from control panel.

I run it via docker so all I need is to update the composer.lock file to have the correct dependencies and everything should be fine the next time I rebuild the image, but something strange is happening.

After selecting the upgrade, it runs for a few minutes and then just gets an internal server error. It logs the following:

craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "Stack trace:"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#0 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): yiivalidatorsIpValidator->init()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#1 /app/vendor/yiisoft/yii2/web/Request.php(345): yiibaseBaseObject->__construct()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#2 /app/vendor/yiisoft/yii2/web/Request.php(1877): yiiwebRequest->getIpValidator()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#3 /app/vendor/yiisoft/yii2/web/Request.php(1859): yiiwebRequest->getSecureForwardedHeaderTrustedParts()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#4 /app/vendor/yiisoft/yii2/web/Request.php(1084): yiiwebRequest->getSecureForwardedHeaderTrustedPart('proto')"
craft_1        | 2020/08/21 07:38:50 [error] 139#139: *4 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218

which is a bit odd, why would a dependency disappear when upgrading like this? After this attempted upgrade, the install is left in a broken state, giving 500 errors (and the same error, Yii not found) for all requests. Reverting the composer.json + composer.lock file and reinstalling dependencies restores functionality.

I had the same issue when trying to upgrade to 3.4, but postponed the upgrade at that point because I had other priorities.

I can add, remove and upgrade plugins from the store without problems with this image. I have composer.json and composer.lock writable, as well as the vendor folder, storage, and migrations.

EDIT: It actually seems like the change in 3.3.16 is causing this, the upgrade of yii to 2.0.30. Doing this:

bash-4.4# composer require craftcms/cms:3.3.16
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - craftcms/cms 3.3.16 requires yiisoft/yii2 ~2.0.30.0 -> satisfiable by yiisoft/yii2[2.0.30].
    - Installation request for craftcms/cms 3.3.16 -> satisfiable by craftcms/cms[3.3.16].
    - Installation request for yiisoft/yii2 (locked at 2.0.21) -> satisfiable by yiisoft/yii2[2.0.21].


Installation failed, reverting ./composer.json to its original content.

I don’t understand why it complains about yii2 being locked to that version. Nothing in composer.lock is explicitly stating that version, they all use ~ versions.

But even when I delete the lock file, the vendor folder, and runs a composer install it seems to successfully install 2.0.30 of Yii2 but I still get that message, I’m starting to get very frustrated at composer…

EDIT 2: This is my composer file:

{
  "repositories": [
    {
      "type": "artifact",
      "url": "composer-artifacts/"
    }
  ],
  "require": {
    "aws/aws-sdk-php": "^3.112",
    "carlcs/craft-redactorcustomstyles": "3.0.2",
    "codemix/yii2-streamlog": "^1.2",
    "craftcms/aws-s3": "^1.2",
    "craftcms/cms": "^3.3.15",
    "craftcms/redactor": "2.3.3.2",
    "dolphiq/redirect": "1.0.24",
    "mmikkel/retcon": "2.0.12",
    "thejoshsmith/craft-title-to-sidebar": "1.0.1",
    "verbb/super-table": "2.3.3",
    "vlucas/phpdotenv": "^3.4.0"
  },
  "autoload": {
    "psr-4": {
      "rexcraftmodules": "modules/"
    }
  },
  "config": {
    "sort-packages": true,
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    },
    "github-oauth": {
      "github.com": "xxxxxx"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r "file_exists('.env') || copy('.env.example', '.env');""
    ]
  }
}

EDIT 3: I used the same setup on a completely brand new 3.5.5 setup and did the upgrade to 3.5.6 without a hickup. Seems like there is some issues with 3.3.15 and upgrades, or perhaps some of the plugins (although I tried removing them from composer.json and it still fails).

EDIT 4: I tried running ./craft update all within the container now, and the output just states:

bash-5.0# ./craft update all
Fetching available updates ... done
Performing 6 updates:

    - craft 3.3.15 => 3.5.9
    - aws-s3 1.2.5 => 1.2.11
    - redactor 2.3.3.2 => 2.4.0
    - redactor-custom-styles 3.0.2 => 3.0.4
    - redirect 1.0.24 => 1.1.1
    - retcon 2.0.12 => 2.2.1

Backup the database? (yes|no) [yes]:no
Skipping database backup.
Performing update with Composer ... error: An error occurred

Output:

<warning>Package "craftcms/vue-asset" listed for update is not installed. Ignoring.</warning>
<warning>Package "danielstjules/stringy" listed for update is not installed. Ignoring.</warning>
<warning>Package "yiisoft/yii2-shell" listed for update is not installed. Ignoring.</warning>
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for carlcs/craft-redactorcustomstyles 3.0.4 -> satisfiable by carlcs/craft-redactorcustomstyles[3.0.4].
    - carlcs/craft-redactorcustomstyles 3.0.4 requires craftcms/redactor ^2.7.0 -> satisfiable by craftcms/redactor[2.7.4, 2.7.3, 2.7.2, 2.7.1, 2.7.0] but these conflict with your requirements or minimum-stability.

<warning>Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.</warning>


Revert the Composer changes? (yes|no) [yes]:

EDIT 5:

I have found the culprit, but don’t really understand why this works in some versions but not in others.

In general.php, I’m using yiiwebRequest to figure out the "local" hostname

use yiiwebRequest;
$request = new Request;

... 

'@baseUrlPrefix' => getenv('BASE_URL_PREFIX') ?: $request->getHostInfo(),

when setting an alias. That fails for some reason, on certain versions (of Yii? don’t know).

2 Answers

Did you try removing composer.lock file and the vendor directory and then doing a fresh composer install?

Answered by Matt Jenkins on March 11, 2021

You can't create an new yiiwebRequest instance in general.php because Craft isn't fully initialized yet. It worked in previous versions but the Craft team seem to have changed the loading order.

You must find another way to define you site base URL.

Answered by nstCactus on March 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP