Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul committed May 15, 2024
1 parent 2e6130c commit 50bbc9d
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ magento.rb export-ignore
.php_cs export-ignore
grumphp.yml export-ignore
phpcs.xml export-ignore
psalm.xml export-ignore
phpstan.neon export-ignore
48 changes: 48 additions & 0 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Static Test

on:
workflow_dispatch:
pull_request:
branches:
- v2.4
push:
branches:
- v2.4

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.1', '8.2', '8.3']
steps:
- uses: actions/checkout@v4

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, mysql
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- run: composer self-update --2
- run: echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGE_LOGIN}\",\"password\":\"${MAGE_PWD}\"}}}" > auth.json
env:
MAGE_LOGIN: ${{ secrets.MAGE_LOGIN }}
MAGE_PWD: ${{ secrets.MAGE_PWD }}
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- run: php vendor/bin/phpcs --config-set ignore_warnings_on_exit 1
- run: php vendor/bin/phpcs --config-set show_warnings 0
- name: Run Tests
run: php vendor/bin/grumphp run
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
/composer.lock
.DS_Store
.php_cs.cache

.php-cs-fixer.cache
auth.json
/generate
15 changes: 15 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
$header = <<<EOF
@author Mygento Team
@copyright 2017-2024 Mygento (https://www.mygento.com)
@package Mygento_Configsync
EOF;

$finder = PhpCsFixer\Finder::create()
->in('.')
->exclude('Test/tmp')
->name('*.phtml')
->ignoreVCSIgnored(true);
$config = new \Mygento\CS\Config\Module($header);
$config->setFinder($finder);
return $config;
11 changes: 0 additions & 11 deletions .php_cs

This file was deleted.

24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

12 changes: 7 additions & 5 deletions Console/Command/Dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @author Mygento Team
* @copyright 2017-2020 Mygento (https://www.mygento.ru)
* @copyright 2017-2024 Mygento (https://www.mygento.com)
* @package Mygento_Configsync
*/

Expand All @@ -12,7 +12,7 @@

class Dump extends \Symfony\Component\Console\Command\Command
{
const CONFIG_DIR = 'config';
private const CONFIG_DIR = 'config';

/**
* @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface
Expand Down Expand Up @@ -91,15 +91,16 @@ protected function configure()
protected function execute(
\Symfony\Component\Console\Input\InputInterface $input,
\Symfony\Component\Console\Output\OutputInterface $output
) {
): int {
$this->output = $output;
$section = $input->getArgument('section');
$env = $input->getArgument('env');
$filename = $input->getArgument('filename');

$this->output->writeln("<info>Starting dump. Section: {$section}. Env: {$env}</info>");

$conf = $this->scopeConfig->get('system', 'default/' . $section);
/** @var \Magento\Framework\App\Config $c */
$c = $this->scopeConfig;
$conf = $c->get('system', 'default/' . $section);

if (empty($conf)) {
throw new \Exception('No config.');
Expand Down Expand Up @@ -128,6 +129,7 @@ protected function execute(

//Should we overwrite the file?
if ($this->file->fileExists($filename)) {
/** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'File already exists! Overwrite?',
Expand Down
21 changes: 10 additions & 11 deletions Console/Command/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

/**
* @author Mygento Team
* @copyright 2017-2020 Mygento (https://www.mygento.ru)
* @copyright 2017-2024 Mygento (https://www.mygento.com)
* @package Mygento_Configsync
*/

namespace Mygento\Configsync\Console\Command;

class Sync extends \Symfony\Component\Console\Command\Command
{
const DELETE = '%DELETE%';
private const DELETE = '%DELETE%';

/**
* @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface
Expand Down Expand Up @@ -70,7 +70,7 @@ protected function configure()
protected function execute(
\Symfony\Component\Console\Input\InputInterface $input,
\Symfony\Component\Console\Output\OutputInterface $output
) {
): int {
$this->output = $output;

$envData = $this->getEnvData(
Expand Down Expand Up @@ -115,8 +115,7 @@ protected function execute(
$line = sprintf(
'<info>[%s] %s -> DELETED</info>',
$scopeKey,
$path,
$newValue ?: 'null'
$path
);

$this->output->writeln($line);
Expand Down Expand Up @@ -172,18 +171,18 @@ private function getEnvData($yamlFile, $env)
if (!$this->isFileCorrect($data)) {
throw new \Exception(
"File format is incorrect.\r\n\r\n"
. "For example the correct format:\r\n\r\n"
. "production:\r\n"
. " default:\r\n"
. " web/secure/base_url: https://domain.com/\r\n"
. ' web/secure/use_in_frontend: 1'
. "For example the correct format:\r\n\r\n"
. "production:\r\n"
. " default:\r\n"
. " web/secure/base_url: https://domain.com/\r\n"
. ' web/secure/use_in_frontend: 1'
);
}

if (!isset($data[$env])) {
$this->output->writeln(
'<info>The environment doesn\'t exists in the file.'
. ' Nothing to import</info>'
. ' Nothing to import</info>'
);

return 0;
Expand Down
38 changes: 21 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

A module to store Magento configuration with multiple environments in the version control


[![Build Status](https://travis-ci.com/mygento/configsync.svg?branch=v2.4)](https://travis-ci.com/mygento/configsync)
[![Build Status](https://github.com/mygento/configsync/actions/workflows/grumphp.yml/badge.svg)](https://github.com/mygento/configsync/actions/workflows/grumphp.yml)
[![Latest Stable Version](https://poser.pugx.org/mygento/module-configsync/v/stable)](https://packagist.org/packages/mygento/module-configsync)
[![Total Downloads](https://poser.pugx.org/mygento/module-configsync/downloads)](https://packagist.org/packages/mygento/module-configsync)

## File Syntax

The configuration values are stored in a YAML file. The format of the file is as follows:
The configuration values are stored in a YAML file. The format of the file is as follows:

environment:
scope_key:
Expand All @@ -32,30 +31,35 @@ For example:

Valid scope keys are:

* default
* stores-`$id`
* websites-`$id`

- default
- stores-`$id`
- websites-`$id`

Use ```%DELETE%``` to delete config path
Use `%DELETE%` to delete config path

## Usage

#### Sync config from file

php bin/magento setup:config:sync [options] [--] <env> <config_yaml_file>

Arguments:
* **env** - environment for import.
* **config_yaml_file** - the YAML file containing the configuration settings.
Arguments:

Options:
* **--detailed** - display detailed information (1 - display, otherwise - not display).
- **env** - environment for import.
- **config_yaml_file** - the YAML file containing the configuration settings.

Options:

- **--detailed** - display detailed information (1 - display, otherwise - not display).

#### Dump config

php bin/magento setup:config:dump [--] <env> <section> <filename>

Note: only `default` scope is implemented

Arguments:
* **env** - environment name.
* **section** - name of the section to export its config.
* **filename** - name of the output file (Optional).
Arguments:

- **env** - environment name.
- **section** - name of the section to export its config.
- **filename** - name of the output file (Optional).
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
"name": "mygento/module-configsync",
"description": "A module to store Magento configuration with multiple environments in the version control",
"type": "magento2-module",
"version": "2.4.0",
"license": "OSL-3.0",
"authors": [{
"name": "Nikita Tarasov",
"email": "nikita@mygento.ru"
"email": "nikita@mygento.com"
}],
"keywords": [
"magento",
Expand All @@ -17,7 +16,7 @@
"mustangostang/spyc": "^0.6.2"
},
"require-dev": {
"mygento/coding-standard": "~2.14.0-beta1"
"mygento/coding-standard": "~2.14.0"
},
"autoload": {
"files": [
Expand All @@ -32,5 +31,12 @@
"type": "composer",
"url": "https://repo.magento.com"
}
]
],
"config": {
"allow-plugins": {
"magento/composer-dependency-version-audit-plugin": false,
"magento/magento-composer-installer": false,
"phpro/grumphp": true
}
}
}
41 changes: 22 additions & 19 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
parameters:
git_dir: .
bin_dir: vendor/bin
tasks:
composer:
no_check_lock: true
git_blacklist:
keywords:
- "die("
- "var_dump("
- "exit;"
phplint:
phpcsfixer2:
config: '.php_cs'
phpmd:
ruleset: ['vendor/mygento/coding-standard/Mygento-Mage2/phpmd.xml']
phpcs:
warning_severity: null
xmllint:
grumphp:
tasks:
composer:
no_check_lock: true
git_blacklist:
keywords:
- 'die('
- 'var_dump('
- 'exit;'
phplint:
phpcsfixer:
config: '.php-cs-fixer.php'
phpmd:
ruleset: ['vendor/mygento/coding-standard/Mygento-Mage2/phpmd.xml']
exclude: ['Test']
phpcs:
warning_severity: 0
xmllint:
phpstan:
autoload_file: 'vendor/mygento/coding-standard/stan/autoload.php'
ignore_patterns: ['Test']
level: 2
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Mygento-Mage2MOD">
<rule ref="./vendor/mygento/coding-standard/Mygento-Mage2"/>
<rule ref="./vendor/magento/magento-coding-standard/Magento2"/>
</ruleset>
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- vendor/mygento/coding-standard/stan/extension.neon

parameters:
bootstrapFiles:
- 'vendor/mygento/coding-standard/stan/autoload.php'
2 changes: 1 addition & 1 deletion registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @author Mygento Team
* @copyright 2017-2020 Mygento (https://www.mygento.ru)
* @copyright 2017-2024 Mygento (https://www.mygento.com)
* @package Mygento_Configsync
*/

Expand Down

0 comments on commit 50bbc9d

Please sign in to comment.