silverstripe / sspak

Tool for managing bundles of db/assets from Silverstripe environments
http://silverstripe.github.io/sspak/
BSD 3-Clause "New" or "Revised" License
47 stars 34 forks source link

sspak-sniffter doesn't work with SS4 app object #59

Open sminnee opened 7 years ago

sminnee commented 7 years ago

https://github.com/silverstripe/sspak/blob/master/src/sspak-sniffer.php relies on Core.php and global $databaseConfig. For SilverStripe 4 this will need to change.

Ideally, the pre-app-object support for SS4 will still work.

mikenz commented 7 years ago

Our quick fix is:

} else if(file_exists(BASE_PATH.'/framework/src/Core/CoreKernel.php')) {
    //SS 4 OO
    use SilverStripe\Control\HTTPApplication;
    use SilverStripe\Control\HTTPRequest;
    use SilverStripe\Core\CoreKernel;

    require_once(BASE_PATH. '/vendor/autoload.php');

    if (!file_exists($autoloadPath = BASE_PATH. '/vendor/autoload.php')) {
        exit;
    }

    require_once $autoloadPath;

    // Mock request
    $request = new HTTPRequest('GET', '/');
    $request->setSession(new Session([])));
    $kernel = new CoreKernel(BASE_PATH);
    $app = new HTTPApplication($kernel);

    $app->execute($request, function (HTTPRequest $request) {
        global $databaseConfig;
        $output = array();
        foreach($databaseConfig as $k => $v) {
            $output['db_' . $k] = $v;
        }
        $output['assets_path'] = ASSETS_PATH;

        echo serialize($output);
        echo "\n";

    });
    exit;
} else {
phptek commented 6 years ago

The branch ss4rc1-compat works in Dev, but I have only tested the save command. Our sysadmins use sspak with Fabricdeploy so will ensure it works for their use-cases and report back...sometime.

Thanks to @mikenz that formed the basis of this.

dhensby commented 6 years ago

see #64

LABCAT commented 5 years ago

This code seems to be very SS3 centric because there is no mention of

vendor/silverstripe/framework/core.php or something like that.

https://github.com/silverstripe/sspak/blob/master/src/DataExtractor/DatabaseConnector.php#L28-L44