Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A VERY quick and rough tool to check your project for SilverStripe upgradability
<?php
/**
* Test (roughly) your SilverStripe 4 upgradability. Ensure you run "composer require composer/semver" first.
*
* @author Robbie Averill <robbie@silverstripe.com>
*/
require_once __DIR__ . '/vendor/autoload.php';
use Composer\Semver\Semver;
$composerConfig = @file_get_contents(__DIR__ . '/composer.json');
if ($composerConfig === false || !json_decode($composerConfig)) {
echo 'composer.json not found or invalid. Please run this from your project root.', PHP_EOL;
exit(1);
}
$composerConfig = json_decode($composerConfig);
echo 'Checking your dependencies for SilverStripe 4 compatibility...', PHP_EOL;
$results = [
'pass' => 0,
'fail' => 0,
'skipped' => 0
];
foreach ($composerConfig->require as $package => $constraint) {
echo ' * Testing ' . $package . '... ';
if (in_array($package, ['silverstripe/framework', 'silverstripe/cms'])) {
$results['pass']++;
echo 'Pass.', PHP_EOL;
continue;
}
$result = @file_get_contents('https://packagist.org/p/' . $package . '.json');
if ($result === false || !json_decode($result)) {
$results['skipped']++;
echo 'Skipped - not found.', PHP_EOL;
continue;
}
$result = json_decode($result);
if (empty($result->packages->$package->{'dev-master'})) {
$results['skipped']++;
echo 'Skipped - master branch not found.', PHP_EOL;
continue;
}
$valid = false;
$master = $result->packages->$package->{'dev-master'};
foreach ($master->require as $required => $version) {
if (!in_array($required, ['silverstripe/framework', 'silverstripe/cms'])) {
continue;
}
if (Semver::satisfies('4.0.0', $version)) {
$results['pass']++;
echo 'Pass.', PHP_EOL;
continue 2;
}
$results['fail']++;
echo 'Fail.', PHP_EOL;
continue;
}
}
echo PHP_EOL;
echo <<<RESULTS
Results:
---
Compatible: {$results['pass']}
Non-compatible: {$results['fail']}
Skipped: {$results['skipped']}
RESULTS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment