Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize Update License Command #15437

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions src/PrestaShopBundle/Command/UpdateLicensesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class UpdateLicensesCommand extends Command
* International Registered Trademark & Property of PrestaShop SA
*/';

/**
* @var string
*/
private $license;

private $aflLicense = array(
Expand All @@ -69,13 +72,19 @@ class UpdateLicensesCommand extends Command
'modules/',
);

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('prestashop:licenses:update')
->setDescription('Rewrite your licenses to be up-to-date');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->text = str_replace('{currentYear}', date('Y'), $this->text);
Expand All @@ -95,6 +104,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

/**
* @param OutputInterface $output
* @param string $ext
*/
private function findAndCheckExtension(OutputInterface $output, $ext)
{
$finder = new Finder();
Expand Down Expand Up @@ -136,15 +149,6 @@ private function findAndCheckExtension(OutputInterface $output, $ext)
'tests/E2E/',
'tests/Unit/Resources/assets/',
'tests/puppeteer/',
// ->exclude() only exclude directories, no files
// @todo: but we would like to ignore the following files too:
'composer.json',
'package.json',
'admin-dev/themes/default/css/font.css',
'admin-dev/themes/new-theme/package.json',
'tools/build/Library/InstallUnpacker/content/js-runner.js',
'themes/classic/_dev/package.json',
'tools/build/composer.json',
))
->ignoreDotFiles(false);
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
Expand All @@ -154,10 +158,24 @@ private function findAndCheckExtension(OutputInterface $output, $ext)
$progress->start();
$progress->setRedrawFrequency(20);

$filesToIgnore = [
'composer.json',
'package.json',
'admin-dev/themes/default/css/font.css',
'admin-dev/themes/new-theme/package.json',
'tools/build/Library/InstallUnpacker/content/js-runner.js',
'themes/classic/_dev/package.json',
'tools/build/composer.json',
];

foreach ($finder as $file) {
$this->license = $this->text;
$this->makeGoodLicense($file);

if (in_array($file->getRelativePathName(), $filesToIgnore)) {
continue;
}

switch ($file->getExtension()) {
case 'php':
try {
Expand Down Expand Up @@ -245,6 +263,11 @@ private function makeAFLLicense()
$this->license = str_replace('{licenseLink}', 'https://opensource.org/licenses/AFL-3.0', $this->license);
}

/**
* @param SplFileInfo $file
* @param string $startDelimiter
* @param string $endDelimiter
*/
private function addLicenseToFile($file, $startDelimiter = '\/', $endDelimiter = '\/')
{
$content = $file->getContents();
Expand Down