Switch to composer mode in running instance
Asked Answered
I

5

7

How can I switch an existing project easily to composer? This project is updated from 6.1 to 8.7 now and should run in composer. A fresh composer setup is not a problem. For the last project I created a new host, installed TYPO3 via composer, installed the extensions via composer and migrated the db, fileadmin and uploads. Is there an easier way?

Icecap answered 27/9, 2017 at 14:40 Comment(0)
S
18

Migrating TYPO3 from Classic Mode to Composer Mode requires at least the following steps:

  1. Write down the current version of TYPO3 and all extensions
  2. Remove all embedded TYPO3 and extension code incl. Git submodules
  3. Add a Composer manifest
  4. Add the Composer vendor-dir (and bin-dir if custom) to your .gitignore
  5. Require TYPO3 and all extensions with the versions and --prefer-lowest, e.g.

    composer require typo3/cms:^8.7.7 --prefer-lowest
    

    This ensures that you don't accidentally perform updates before completing the switch.

Since no further changes to user files or database data is required you will be running TYPO3 in Composer Mode now.

Afterward you will most likely also need to adapt your deployment workflow to ensure at least one composer install is executed after deploying a new version.

Sepulchral answered 27/9, 2017 at 14:47 Comment(0)
M
1

There is no real other way, at least no automatic way, as you also upgrade maybe to newer versions or sometimes to the exact same version

Mckinnon answered 27/9, 2017 at 14:43 Comment(0)
M
1

This is now documented in the "Installation and Upgrade Guide": https://docs.typo3.org/m/typo3/guide-installation/master/en-us/MigrateToComposer/Index.html

The steps are already outlined in the accepted answer.

As an alternative, you might want to create an installation from scratch with Composer and then use the generated composer.json for your system.

Manville answered 9/10, 2019 at 16:39 Comment(0)
L
0

It generally makes sense to have your docroot in a subdirectory before you start so you have, for example:

/var/www/mysite (here, the composer.json will be created)
└──public/
   ├── fileadmin
   ├── typo3
   └── typo3_src

You can have a look at my extension migrate2composer. However, this will only take care of creating the composer.json file. You have to take care of the rest of the steps yourself.

What it basically does is:

  1. generated a list of all extension with the existing version
  2. dump a sample composer.json file

If you want to do this yourself in your source code, you can take a look at TYPO3\CMS\Core\Package\PackageManager. This worked for TYPO3 v9 and v10 but may change in later versions:

public function getInstalledPackages(string $versionConstraintType = self::VERSION_CONSTRAINT_CARET) : array
{
        $packagesInfo = [];
        $this->errors = [];
        $this->setVersionConstraintType($versionConstraintType);

        // collect information about active extensions
        $packages = $this->packageManager->getAvailablePackages();
        foreach ($packages as $package) {
            $key = $package->getPackageKey();

            if (!$this->packageManager->isPackageActive($key)) {
                // ignore inactive packages
                continue;
            }
            if ($package->getValueFromComposerManifest('type') === 'typo3-cms-framework') {
                $type = 'system';
            } else {
                $type = 'local';
            }
            $name = $package->getValueFromComposerManifest('name');
            // ....   

By now the procedure for migrating to Composer is well documented in the official documentation.

Additional steps you must perform yourself:

mv public/typo3conf/sites config/sites
mv public/typo3conf/l10n var/labels
Laboratory answered 5/12, 2022 at 17:46 Comment(0)
C
-2

I have tried to generate a composer.json file from the PackageState.php successfully for a docker instance.

I loop through the PackageState.php, then parse each extension for its version and generate a composer.json from this aggregated information.

This is my script: https://github.com/geri777/typo3-composerize

Camellia answered 31/5, 2022 at 13:3 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewUnskillful
@Joooeey, right I have changed my answer and describe what I am doing in my scriptCamellia

© 2022 - 2024 — McMap. All rights reserved.