Mautic Community Forums

As a developer I want to be able to apply patches and upgrade mautic/core within the existing composer.json

Right now it is not possible to run composer update and update mautic.

For example, in Drupal the command is the following:

composer update drupal/core --with-dependencies

Within the current mautic composer.json it is not possible to upgrade mautic. It is, because this is not possible, also not possible to apply patches like this in the composer.json. Not having this makes it very difficult to maintain patches in production. It would also require to disable upgrading within the source code. Our hosting setup doesn’t allow to modify the PHP files from within the application other than the media files. We only want to update using GIT and make sure changes are kept in git. This is the defacto regular workflow that is needed to move this to a QA flow so we can have a flow for updates that is compatible with git and multiple environments. Using Pull Request is fun for development but not an option if you want to work with a stable branch from the original source + a patch that you verified.

    "extra": {
            "patches": {
                "mautic/core": {
                    "#8352 Allow custom fields in search for companies": "https://github.com/mautic/mautic/pull/8352.patch"
                }
            }
        }

Therefor I suggest we discuss how we can add mautic/core as a new composer package using the type mautic-core, similar as to how Drupal is structured.

Drupal example project structure:

Important snippet:

 "require": {
        "composer/installers": "^1.0.24",
        "drupal/core": "self.version",
        "drupal/core-project-message": "self.version",
        "drupal/core-vendor-hardening": "self.version",
        "wikimedia/composer-merge-plugin": "^1.4"
    },

Drupal core composer example:

Important snippet:
"type": "drupal-core",

I tried to make this work using the existing sources but because the project is setup as composer type:project it is not possible to move the app folder somewhere else, nor is it possible to move the vendor folder outside of the docroot without making a fork of the project, causing a split from the authoritative source, which I do not want.

I’m sure that people within Acquia can help to add more feedback here, as what I’m suggesting is quite normal in the Drupal world :slight_smile:

4 Likes

Hey @Nick_vh! Sounds like a great idea to me, would make it easier for companies that forked Mautic to apply patches as necessary. Would also help them to stay in sync with the community version more easily and vice versa.

I don’t know all the specifics about Mautic’s update system (yet), but e.g. what the CLI update command (php app/console mautic:update:apply) does also includes things like clearing cache & performing database migrations. So I guess, if we were to introduce an update system through Composer, it would involve having a post-update-cmd command event which would trigger the CLI command above? Would that be a viable option? Maybe @escopecz could elaborate a bit more on that :slight_smile:

1 Like

Yep, this is great idea. As I tested that we can already install Mautic with Composer right now. However as @Nick_vh pointed out, that’s not optimal. I played with doing it the proper way a couple months back but we’d have to change the folder structure a little. But that change would complicate life to users who installed Mautic to shared hostings. I don’t know if anyone does that. It would be good to discus that in the community.

2 Likes

If it helps, I will attend some hours in the community sprint. Can we maybe talk about that in virtual at a specific time? Also willing to help and spent some time in getting a hacky version together. I alsready created a couple helper repo’s similar to Drupal here: https://github.com/nickveenhof/mautic-project & https://github.com/nickveenhof/mautic-finder & https://github.com/nickveenhof/mautic-core-composer-scaffold but need to make a specific branch of Mautic to get this up and running where the app folder also has a composer.json file similar to Drupal’s core folder.

1 Like

Thanks @Nick_vh for just sharing your POC during the Mautic Community Sprint! The recording can be found here:

Let’s continue the discussion about this feature here in this topic :slight_smile: thanks a lot so far!!

1 Like

My comments on the POC so far (based on what @Nick_vh explained):

  • We’d need to add the Mautic version to composer.json (e.g. 2.16.1)
  • Move index.php into a separate folder (e.g. public/index.php) so that index.php and the vendor folder are not in the same directory. Take insipration from Drupal here, where apparently it’s possible to choose during installation if you want index.php in the same folder as vendor (which might be needed on shared hosting platforms)
  • The type in composer.json needs to be changed from project to e.g. mautic-core, otherwise Composer won’t work

Let’s continue the discussion here :slight_smile: according to Nick, it might be already a quick fix to change the type in composer.json, but not sure if that would have any unwanted side-effects. @escopecz what do you think?

1 Like

So, here is an update.

Right now it’s possible to install mautic through composer AND patch it AND update it through the following command. It is also possible to patch mautic. See the composer.json from the mautic-project repository.

“composer update mautic/core --with-dependencies”

How to test it yourselves?

COMPOSER_MEMORY_LIMIT=-1 composer create-project nickveenhof/mautic-project:3.x-dev my-local-mautic-folder --no-interaction

How does it work?

The main magic is in this small PR:

The other magic is in the composer project, and mainly in the composer.json file.

More magic can be found in the accompanying projects:

And

How to proceed? I’m not sure why, but the config_override.php does not want to take effect from the start. When it is defined in local.php it does work but it seems silly that this is needed. I would love some help understanding config_override.php and why I can’t set the cache, tmp & other folders more easily. To reproduce this, use the command above, and see that even though the config_override.php is in the correct spot, the cache is being built up from app/…/var/cache instead of the configured app/…/…/var/cache.

1 Like

https://www.youtube.com/watch?v=SicommdDH7M also shows this in action.

1 Like

Also added the possibility to install 2.x now

COMPOSER_MEMORY_LIMIT=-1 composer create-project nickveenhof/mautic-project:2.x-dev my-local-mautic-folder --no-interaction

Source:

Same single line change is needed in the develop branch to support this flow

1 Like