Skip to content

Instantly share code, notes, and snippets.

@webfed
Last active April 27, 2023 03:42
Show Gist options
  • Save webfed/b8d3235a8f4d6d6e064fadc17fc2cbc9 to your computer and use it in GitHub Desktop.
Save webfed/b8d3235a8f4d6d6e064fadc17fc2cbc9 to your computer and use it in GitHub Desktop.
Composer Drupal 7 prevent deleting files when doing composer update
{
"name": "drupal-composer/drupal-project",
"description": "Project template for Drupal 7 projects with composer",
"type": "project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "",
"role": ""
}
],
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/7"
},
{
"type": "package",
"package": {
"name": "ckeditor/ckeditor",
"version": "3.6.6.1",
"type": "drupal-library",
"dist": {
"url": "https://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.6.1/ckeditor_3.6.6.1.zip",
"type": "zip"
}
}
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-gd": "*",
"ext-json": "*",
"ext-openssl": "*",
"ext-pdo": "*",
"ext-xml": "*",
"ckeditor/ckeditor": "*",
"composer/installers": "^1.9",
"composer/semver": "^1.4",
"cweagans/composer-patches": "^1.7",
"druidfi/mona-plugin": "^2.0",
"drupal-composer/preserve-paths": "^0.1.6",
"drupal/admin_menu": "3.0-rc6",
"drupal/admin_menu_toolbar": "3.0-rc6",
"drupal/advanced_help": "1.6",
"drupal/antibot": "1.2",
"drupal/block_class": "2.4",
"drupal/ccl": "1.7",
"drupal/composer_autoloader": "^1.0",
"drupal/context": "3.11",
"drupal/context_layouts": "3.11",
"drupal/context_ui": "3.11",
"drupal/ctools": "1.20",
"drupal/delta": "3.0-beta11",
"drupal/delta_blocks": "3.0-beta11",
"drupal/delta_ui": "3.0-beta11",
"drupal/drupal": "^7.62",
"drupal/features": "2.14",
"drupal/flexslider": "2.0-rc2",
"drupal/flexslider_fields": "2.0-rc2",
"drupal/flexslider_views": "2.0-rc2",
"drupal/flexslider_views_slideshow": "2.x-dev",
"drupal/fontyourface": "2.8",
"drupal/fontyourface_ui": "2.8",
"drupal/globalredirect": "1.6",
"drupal/google_fonts_api": "2.8",
"drupal/libraries": "2.5",
"drupal/link": "1.11",
"drupal/logintoboggan": "1.5",
"drupal/matomo": "2.13",
"drupal/metatag": "1.30",
"drupal/module_filter": "2.2",
"drupal/page_title": "2.7",
"drupal/pathauto": "1.3",
"drupal/redirect": "1.0-rc4",
"drupal/resp_img": "1.3",
"drupal/responsive_images": "^1.0@beta",
"drupal/robotstxt": "1.4",
"drupal/smtp": "1.7",
"drupal/token": "1.9",
"drupal/transliteration": "3.2",
"drupal/views": "^3.25",
"drupal/views_slideshow": "^3.10",
"drupal/views_ui": "^3.25",
"drupal/webform": "^4.24",
"drupal/wysiwyg": "2.9",
"drupal/xmlsitemap": "2.6",
"drupal/xmlsitemap_engines": "2.6",
"drupal/xmlsitemap_node": "2.6",
"drush/drush": "^8.0",
"symfony/filesystem": "~2.7 || ^3",
"webflo/drupal-finder": "^1.2.1"
},
"conflict": {
"drupal/core": "8.*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"cweagans/composer-patches": true,
"drupal-composer/preserve-paths": true,
"druidfi/mona-plugin": true
}
},
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php"
]
},
"scripts": {
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"pre-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-create-project-cmd": [
"DrupalProject\\composer\\ScriptHandler::removeInternalFiles"
]
},
"extra": {
"installer-paths": {
"web/": ["type:drupal-core"],
"web/profiles/{$name}/": ["type:drupal-profile"],
"web/sites/all/drush/{$name}/": ["type:drupal-drush"],
"web/sites/all/libraries/{$name}/": ["type:drupal-library"],
"web/sites/all/modules/contrib/{$name}/": ["type:drupal-module"],
"web/sites/all/themes/contrib/{$name}/": ["type:drupal-theme"]
},
"patches-install-hooks": true,
"patches": {
"cweagans/composer-patches": {
"Call the preserve paths hooks" : "https://github.com/jcnventura/composer-patches/compare/1.x...jcnventura:fix-preserve-paths.diff"
}
},
"preserve-paths": [
"web/sites"
]
}
}
Last login: Tue Apr 25 19:53:28 2023 from ...
Linux webserver.example.tld 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[-----------------------------------------]
Gandi - Welcome to your new OS image.
Documentation :
[EN] https://docs.gandi.net/en/cloud/
[FR] https://docs.gandi.net/fr/cloud/
Configuration file for Gandi :
/etc/default/gandi or
/etc/sysconfig/gandi
[-----------------------------------------]
[root@webserver ~]# chown -R example:example /home/example/public_html
[root@webserver ~]# cd /home/example/public_html
[root@webserver public_html]# su example
[example@webserver public_html]$ chmod u+w web/sites/default
[example@webserver public_html]$ composer require druidfi/mona-plugin
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^2.0 for druidfi/mona-plugin
./composer.json has been updated
Running composer update druidfi/mona-plugin
Gathering patches for root package.
Removing package cweagans/composer-patches so that it can be re-installed and re-patched.
- Removing cweagans/composer-patches (1.7.2)
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking druidfi/mona-plugin (2.0.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing cweagans/composer-patches (1.7.2): Extracting archive
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
druidfi/mona-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "druidfi/mona-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
- Installing druidfi/mona-plugin (2.0.2): Extracting archive
Mona dependencies installed, now install project dependencies
Package druidfi/mona-plugin is abandoned, you should avoid using it. No replacement was suggested.
Package webmozart/path-util is abandoned, you should avoid using it. Use symfony/filesystem instead.
Generating autoload files
17 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Mona: Copying Drupal 7 core files and folders.
- Copying web//authorize.php to public/authorize.php
- Copying web//cron.php to public/cron.php
- Copying web//index.php to public/index.php
- Copying web//robots.txt to public/robots.txt
- Copying web//update.php to public/update.php
- Copying web//xmlrpc.php to public/xmlrpc.php
- Copying web//includes to public/includes
- Copying web//misc to public/misc
- Copying web//modules to public/modules
- Copying web//profiles to public/profiles
- Copying web//themes to public/themes
Mona: symlinking files and folders.
> DrupalProject\composer\ScriptHandler::createRequiredFiles
No security vulnerability advisories found
U hebt nieuwe post in /var/spool/mail/root
[example@webserver public_html]$ composer update
Mona dependencies installed, now install project dependencies
Gathering patches for root package.
Removing package cweagans/composer-patches so that it can be re-installed and re-patched.
- Removing cweagans/composer-patches (1.7.2)
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 14 updates, 0 removals
- Upgrading cweagans/composer-patches (1.7.2 => 1.7.3)
- Upgrading drupal/drupal (7.92.0 => 7.97.0)
- Upgrading drupal/views (3.27.0 => 3.29.0)
- Upgrading drupal/views_ui (3.27.0 => 3.29.0)
- Upgrading drupal/webform (4.24.0 => 4.25.0)
- Upgrading drush/drush (8.4.11 => 8.4.12)
- Upgrading nikic/php-parser (v4.15.1 => v4.15.4)
- Upgrading psy/psysh (v0.11.8 => v0.11.16)
- Upgrading symfony/console (v4.4.47 => v4.4.49)
- Upgrading symfony/polyfill-ctype (v1.26.0 => v1.27.0)
- Upgrading symfony/polyfill-mbstring (v1.26.0 => v1.27.0)
- Upgrading symfony/polyfill-php73 (v1.26.0 => v1.27.0)
- Upgrading symfony/polyfill-php80 (v1.26.0 => v1.27.0)
- Upgrading symfony/var-dumper (v5.4.14 => v5.4.22)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 13 updates, 0 removals
- Downloading psy/psysh (v0.11.16)
- Installing cweagans/composer-patches (1.7.3): Extracting archive
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Upgrading symfony/polyfill-ctype (v1.26.0 => v1.27.0): Extracting archive
- Upgrading symfony/polyfill-php80 (v1.26.0 => v1.27.0): Extracting archive
- Upgrading symfony/polyfill-mbstring (v1.26.0 => v1.27.0): Extracting archive
- Upgrading symfony/var-dumper (v5.4.14 => v5.4.22): Extracting archive
- Upgrading symfony/polyfill-php73 (v1.26.0 => v1.27.0): Extracting archive
- Upgrading symfony/console (v4.4.47 => v4.4.49): Extracting archive
- Upgrading nikic/php-parser (v4.15.1 => v4.15.4): Extracting archive
- Upgrading psy/psysh (v0.11.8 => v0.11.16): Extracting archive
- Upgrading drush/drush (8.4.11 => 8.4.12): Extracting archive
- Upgrading drupal/drupal (7.92.0 => 7.97.0): Extracting archive
- Upgrading drupal/views (3.27.0 => 3.29.0): Extracting archive
- Upgrading drupal/views_ui (3.27.0 => 3.29.0)
- Upgrading drupal/webform (4.24.0 => 4.25.0): Extracting archive
Files of installed package were overwritten with preserved path /home/example/public_html/web/sites!
Files of installed package were overwritten with preserved path /home/example/public_html/web/sites!
Package druidfi/mona-plugin is abandoned, you should avoid using it. No replacement was suggested.
Package webmozart/path-util is abandoned, you should avoid using it. Use symfony/filesystem instead.
Generating autoload files
17 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Mona: Copying Drupal 7 core files and folders.
- Copying web//authorize.php to public/authorize.php
- Copying web//cron.php to public/cron.php
- Copying web//index.php to public/index.php
- Copying web//robots.txt to public/robots.txt
- Copying web//update.php to public/update.php
- Copying web//xmlrpc.php to public/xmlrpc.php
- Copying web//includes to public/includes
- Copying web//misc to public/misc
- Copying web//modules to public/modules
- Copying web//profiles to public/profiles
- Copying web//themes to public/themes
Mona: symlinking files and folders.
> DrupalProject\composer\ScriptHandler::createRequiredFiles
Created a sites/default/files directory with chmod 0777
No security vulnerability advisories found
U hebt nieuwe post in /var/spool/mail/root
[example@webserver public_html]$
Result directories empty:
sites/default/files
sites/all/modules/contrib (exept views which was updated)
sites/all/themes
@back-2-95
Copy link

A few issues:

  • I think Mona and drupal-composer/preserve-paths conflict a bit so I removed it
  • Mona config in extra is in wrong place

So my version of composer.json is:

{
  "name": "drupal-composer/drupal-project",
  "description": "Project template for Drupal 7 projects with composer",
  "type": "project",
  "license": "GPL-2.0-or-later",
  "authors": [
    {
      "name": "",
      "role": ""
    }
  ],
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/7"
    },
    {
      "type": "package",
      "package": {
        "name": "ckeditor/ckeditor",
        "version": "3.6.6.1",
        "type": "drupal-library",
        "dist": {
          "url": "https://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.6.1/ckeditor_3.6.6.1.zip",
          "type": "zip"
        }
      }
    }
  ],
  "require": {
    "php": ">=5.3.3",
    "ext-curl": "*",
    "ext-gd": "*",
    "ext-json": "*",
    "ext-openssl": "*",
    "ext-pdo": "*",
    "ext-xml": "*",
    "ckeditor/ckeditor": "*",
    "composer/installers": "^1.9",
    "composer/semver": "^1.4",
    "cweagans/composer-patches": "^1.7",
    "druidfi/mona-plugin": "^2.0",
    "drupal/admin_menu": "3.0-rc6",
    "drupal/admin_menu_toolbar": "3.0-rc6",
    "drupal/advanced_help": "1.6",
    "drupal/antibot": "1.2",
    "drupal/block_class": "2.4",
    "drupal/ccl": "1.7",
    "drupal/composer_autoloader": "^1.0",
    "drupal/context": "3.11",
    "drupal/context_layouts": "3.11",
    "drupal/context_ui": "3.11",
    "drupal/ctools": "1.20",
    "drupal/delta": "3.0-beta11",
    "drupal/delta_blocks": "3.0-beta11",
    "drupal/delta_ui": "3.0-beta11",
    "drupal/drupal": "^7.62",
    "drupal/features": "2.14",
    "drupal/flexslider": "2.0-rc2",
    "drupal/flexslider_fields": "2.0-rc2",
    "drupal/flexslider_views": "2.0-rc2",
    "drupal/flexslider_views_slideshow": "2.x-dev",
    "drupal/fontyourface": "2.8",
    "drupal/fontyourface_ui": "2.8",
    "drupal/globalredirect": "1.6",
    "drupal/google_fonts_api": "2.8",
    "drupal/libraries": "2.5",
    "drupal/link": "1.11",
    "drupal/logintoboggan": "1.5",
    "drupal/matomo": "2.13",
    "drupal/metatag": "1.30",
    "drupal/module_filter": "2.2",
    "drupal/page_title": "2.7",
    "drupal/pathauto": "1.3",
    "drupal/redirect": "1.0-rc4",
    "drupal/resp_img": "1.3",
    "drupal/responsive_images": "^1.0@beta",
    "drupal/robotstxt": "1.4",
    "drupal/smtp": "1.7",
    "drupal/token": "1.9",
    "drupal/transliteration": "3.2",
    "drupal/views": "^3.25",
    "drupal/views_slideshow": "^3.10",
    "drupal/views_ui": "^3.25",
    "drupal/webform": "^4.24",
    "drupal/wysiwyg": "2.9",
    "drupal/xmlsitemap": "2.6",
    "drupal/xmlsitemap_engines": "2.6",
    "drupal/xmlsitemap_node": "2.6",
    "drush/drush": "^8.0",
    "symfony/filesystem": "~2.7 || ^3",
    "webflo/drupal-finder": "^1.2.1"
  },
  "conflict": {
    "drupal/core": "8.*"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "config": {
    "sort-packages": true,
    "allow-plugins": {
      "composer/installers": true,
      "cweagans/composer-patches": true,
      "druidfi/mona-plugin": true
    }
  },
  "extra": {
    "mona-plugin": {
      "composer-exit-on-patch-failure": true,
      "installer-paths": {
        "vendor/drupal": ["type:drupal-core"],
        "${webroot}/sites/all/libraries/{$name}": ["type:drupal-library"],
        "${webroot}/sites/all/modules/contrib/{$name}": ["type:drupal-module"],
        "${webroot}/sites/all/themes/{$name}": ["type:drupal-theme"],
        "${webroot}/sites/all/drush/{$name}": ["type:drupal-drush"]
      },
      "symlinks": {
      },
      "symlinks-force-create": false,
      "symlinks-skip-missing-target": false,
      "symlinks-absolute-path": false,
      "symlinks-throw-exception": true,
      "webroot": "web"
    },
    "patches-install-hooks": true
  }
}

I made this small test:

mkdir -p web/sites/default
touch web/sites/default/settings.php
composer install

@back-2-95
Copy link

web/sites/default/settings.php is not removed after running next composer update etc.

@back-2-95
Copy link

Mona install drupal core to vendor and then copies needed stuff to webroot. That's basically THE one thing which makes it not removing stuff we have added manually under webroot e.g. sites/default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment