如何使用Composer更新核心?


10

好的,我是一名作曲新手。因此,在我以前的站点中,我使用了作曲管理器来更新Drupal的核心。使用起来非常简单(只需运行“ composer drupal-update”)。但是,作曲经理现在表示已弃用。

由于Drupal 8.1的改进,该模块的Drupal 8版本已被弃用,不再需要。直接使用Composer获取所需的模块,该模块还将下载其所需的库。

因此,今天我收到警告,我需要对内核应用安全更新,但是找不到关于如何使用作曲家更新Drupal内核的任何文档。

这是通过Drupal Console,Drush完成的还是我需要运行的实际Composer命令?除了“从drupal.org下载最新版本的Drupal并手动替换所有文件”之外,我还不清楚首选的过程是什么。


您可以使用drush drush up drupal,我认为这可能会覆盖您的composer.json tho(和其他文件),因此请备份它并在需要时还原。使用composer update

“(和其他文件)”,是的,这是我担心的“其他文件”。到那时,我不妨从官方下载中手动替换它们并运行composer更新。似乎应该有一个更简单的过程。当目前没有其他选择时,弃用作曲管理器似乎没有多大意义。
DrupalMonster '16

Answers:


10

要使用Composer更新Drupal,您只需要将该"drupal/core": "~8.1"行从replace部分移至require部分。最后,composer.json文件的内容类似于以下内容。

{
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0+",
    "require": {
        "composer/installers": "^1.0.21",
        "wikimedia/composer-merge-plugin": "~1.3",
        "drupal/core": "~8.1"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php."
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json"
            ],
            "recurse": false,
            "replace": false,
            "merge-extra": false
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
    },
}

我曾经被用来drush upc更新Drupal,但是它覆盖了我的composer.json文件和供应商目录。因此,我应该一直运行composer update以更新供应商目录的内容。

现在,使用Composer更新Drupal,我也可以使用它来下载/更新我正在使用的模块。

我正在使用的composer.json文件是以下文件。

{
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0+",
    "require": {
        "composer/installers": "^1.0.21",
        "wikimedia/composer-merge-plugin": "~1.3",
        "drupal/core": "~8.1",
        "drupal/imagick": "8.1.*@dev",
        "drupal/mollom": "^8.1",
        "drupal/honeypot": "^8.1"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php."
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json"
            ],
            "recurse": false,
            "replace": false,
            "merge-extra": false
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
    },
    "repositories": {
        "drupal": {
            "type": "composer",
            "url": "https://packagist.drupal-composer.org"
        }
    }
}

除了像我说的那样移动那一行,我还执行了以下命令。

composer config repositories.drupal composer https://packagist.drupal-composer.org
composer require drupal/honeypot
composer require drupal/mollom
composer require drupal/imagick 8.1.*@dev

第一个允许我要求Drupal模块并更新它们。

我上次尝试时,Drupal官方存储库仍处于alpha阶段,这给我声明自己为Composer软件包但未设置软件包类型的模块(即drupal-module)带来问题。我希望他们现在解决了这个问题。对于Drupal Packager存储库,以下使用的命令。

composer config repositories.drupal composer https://packages.drupal.org/8
composer require drupal/honeypot
composer require drupal/mollom
composer require drupal/imagick 1.*@dev

如果您已经在使用https://packagist.drupal-composer.org,并且想要替换为官方Packagist网站,则需要将第一个命令替换为composer config repositories.0 composer https://packages.drupal.org/8,如果您没有其他存储库,则可以使用,这是基于使用packages.drupal.org

另请注意,packagist.drupal-composer.org计划于2017年1月弃用(或当Drupal.org的官方软件包系统信息库准备就绪时)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.