jackd248 / ddev-commands-collection

Collection of reusable DDEV commands
MIT License
3 stars 1 forks source link

dcc-config.sh overwritten #1

Open jackd248 opened 2 years ago

jackd248 commented 2 years ago

The dcc-config.sh gets overwritten on every composer update/install and all configuration gets lost.

Defcon0 commented 2 years ago

Hi there ;-)

Maybe thought too simple, but wouldn't this be enough to fix the issue (I can provide a PR if necessary)?

protected static function copyFiles()
{
    //...

    // add config file
    $files[] = $distCommands . 'dcc-config.sh';

    foreach($files as $fullPathFilename) {
        $relativePathFilename = str_replace($distCommands, '', $fullPathFilename);
        // Check for ignored files
        if (is_null(static::$config['ignoreFiles']) || !in_array($relativePathFilename, static::$config['ignoreFiles'])) {
            $targetFilePath = static::$config['ddevDir'] . '/commands/' . $relativePathFilename;

            // START FIX: skip dcc-config.sh if already existing
            if ($fullPathFilename === $distCommands . 'dcc-config.sh' && file_exists($targetFilePath)) {
              continue;
            }
            // END FIX

            // Overwrite/copy file
            static::$fs->copy(
                $fullPathFilename,
                $targetFilePath,
                true
            );
            $countCopied++;
            // Extend files with current app version
            $fileContents = file_get_contents($targetFilePath);
            $fileContents = str_replace("<version/>",static::getVersion(),$fileContents);
            file_put_contents($targetFilePath,$fileContents);
        }
    }

    //...
}