Skip to content
This repository has been archived by the owner on Jan 10, 2020. It is now read-only.

Wrong convertion __DIR__ to temporary deployment path #45

Open
fabio-paiva-sp opened this issue Aug 4, 2015 · 3 comments
Open

Wrong convertion __DIR__ to temporary deployment path #45

fabio-paiva-sp opened this issue Aug 4, 2015 · 3 comments

Comments

@fabio-paiva-sp
Copy link

fabio-paiva-sp commented Aug 4, 2015

The application.config.php was changed from:

    <?php return array (
                'module_listener_options' => array(
                    'config_glob_paths' => array(
                        __DIR__ . '/../config/autoload/{,*.}{global,local}.php',
                    ),
                )
            )

to

    <?php return array (
                'module_listener_options' => array(
                    'config_glob_paths' => array(
                        0 => 'C:\\Users\\Fabio-windows\\AppData\\Local\\Temp\\ZFDeploy_55c0ab9eb9c44\\config/../config/autoload/{,*.}{global,local}.php',
                    ),
                )
            )
@jbh
Copy link

jbh commented Sep 6, 2019

This seems to be expected behavior and takes place on line 574 of Deploy.php. Instead of copying the contents of the file, the contents get parsed. This means all constants and methods will be parsed instead of copied over as is.

This seems to cause issues. @weierophinney is there a reason the file is included instead of just having the contents copied over verbatim?

@jbh
Copy link

jbh commented Sep 6, 2019

If I comment out the contents of copyModules, the application.config.php never gets converted/parsed, so the built package has the same application.config.php, and seems to run fine then.

@jbh
Copy link

jbh commented Sep 8, 2019

After some playing around, this is my solution. I'm not sure how flexible it is, though.

protected function copyModules(array $modules, $applicationPath, $tmpDir)
{
    $tmpDir = str_replace('//', '/', $tmpDir);
    if (empty($modules)) {
        return;
    }

    // copy modules
    foreach ($modules as $module) {
        $normalized = str_replace('\\', '/', $module);
        self::recursiveCopy($applicationPath . '/module/' . $normalized, $tmpDir . '/module/' . $normalized);
    }

    // enable only the selected modules in the config/application.config.php
    if (file_exists($tmpDir . '/config/application.config.php')) {
        $config = include $tmpDir . '/config/application.config.php';
        $configTest = file_get_contents($tmpDir . '/config/application.config.php');
        // Remove a module if not present in $modules
        $tot = count($config['modules']);
        for ($i = 0; $i < $tot; $i++) {
            $normalized = str_replace('\\', '/', $config['modules'][$i]);
            if (is_dir($applicationPath . '/module/' . $normalized)
                && ! in_array($config['modules'][$i], $modules)
            ) {
                unset($config['modules'][$i]);
            }
        }

        $configExport = var_export($config, true);
        $configExport = str_replace("'" . $tmpDir . '/config', "realpath(__DIR__) . '", $configExport);
        file_put_contents(
            $tmpDir . '/config/application.config.php',
            '<?php return ' . $configExport . ';'
        );
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants