mautic / recommended-project

This project template provides a starter kit for managing your Mautic dependencies with Composer.
https://www.mautic.org
8 stars 14 forks source link

`app/config/local.php` gets removed by `composer update` #33

Open dennisameling opened 1 year ago

dennisameling commented 1 year ago

Consider a Mautic installation created as follows:

composer create-project mautic/recommended-project:^4 some-dir --no-interaction

In the root directory, I have a .gitignore which is the default but with the following lines added:

/docroot/app/*
/docroot/plugins/*
/docroot/themes/*

This is based on this recommendation to not check those files into Git (as I haven't modified them):

The Mautic Composer Scaffold plugin can download the scaffold files (like index.php, .htaccess, …) to the docroot/ directory of your project. If you have not customized those files you could choose to not check them into your version control system (e.g. git)

This is problematic when updating Mautic to the latest version (composer update). It removes /docroot/app/config/local.php.

Before composer update, the local.php file in the folder tree below:

After running composer update to update Mautic, the file is gone:

I fixed it by storing local.php in config/local.php (in the root of my Mautic installation) and pointing Mautic to that file through paths_local.php as follows:

 "extra": {
    "mautic-scaffold": {
      "locations": {
        "web-root": "docroot/",
      },
      "file-mapping": {
        "[web-root]/app/config/paths_local.php": "scaffold-files/paths_local.php"
      }
    },

The contents of scaffold-files/paths_local.php are as follows:

<?php

$paths['local_config'] = '%kernel.root_dir%/../../config/local.php';

This basically means that I can just store local.php in the config folder in the root directory of my Mautic instance.

Just wanted to report this here in case someone is running into the same issue. Curious to hear from others whether they have a better approach to this 👍🏼

--- Want to back this issue? **[Post a bounty on it!](https://app.bountysource.com/issues/123767332-app-config-local-php-gets-removed-by-composer-update?utm_campaign=plugin&utm_content=tracker%2F195904152&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://app.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F195904152&utm_medium=issues&utm_source=github).
RCheesley commented 1 year ago

@mollux could you share your approach? Would be great if we can get this addressed!

Moongazer commented 1 year ago

I run into the same issue and tried to build a post-composer hook to symlink the local.php from a shared/ folder in project-root (similar to the approach which Deployer does):

project-root
  .ddev/
  packages/
  docroot/
    app/
      config/
        local.php -> ../../../shared/config/local.php
        media/ -> ../../../shared/media/
  shared/
    media/
    config/
      local.php

But because of lacking Composer insights, I was not able yet to bring this setup to life.

It would be great if this issue would be addressed in a generic/recommended way for every Mautic project-setup using composer.

mollux commented 9 months ago

@dennisameling @Moongazer in Mautic 5 this was addressed by splitting up application and local config (see https://github.com/mautic/mautic/pull/11561 for more details).

So in M5, when running composer commands, the ./config folder is not changed by default.