Skip to content

Commit

Permalink
Issue #125: Fix deprecated locale function calls.
Browse files Browse the repository at this point in the history
By @laryn, @drupix, and @indigoxela (GHA code).
  • Loading branch information
laryn authored Oct 3, 2024
1 parent 4dc440e commit cc3c8bc
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 41 deletions.
93 changes: 93 additions & 0 deletions .github/misc/Github.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace PHP_CodeSniffer\Reports;

use PHP_CodeSniffer\Files\File;
/**
*
*/
class Github implements Report {

/**
* Generate a partial report for a single processed file.
*
* Function should return TRUE if it printed or stored data about the file
* and FALSE if it ignored the file. Returning TRUE indicates that the file and
* its data should be counted in the grand totals.
*
* @param array $report
* Prepared report data.
* @param \PHP_CodeSniffer\File $phpcsFile
* The file being reported on.
* @param bool $showSources
* Show sources?
* @param int $width
* Maximum allowed line width.
*
* @return bool
*/
public function generateFileReport($report, File $phpcsFile, $showSources=FALSE, $width=80)
{
if ($report['errors'] === 0 && $report['warnings'] === 0) {
// Nothing to print.
return FALSE;
}

foreach ($report['messages'] as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
$type = strtolower($error['type']);
$file = $report['filename'];
$message = $error['message'];
echo "::$type file=$file,line=$line,col=$column::$message" . PHP_EOL;
}
}
}

return TRUE;

}//end generateFileReport()


/**
* Generates a GitHub Actions report.
*
* @param string $cachedData
* Any partial report data that was returned from
* generateFileReport during the run.
* @param int $totalFiles
* Total number of files processed during the run.
* @param int $totalErrors
* Total number of errors found during the run.
* @param int $totalWarnings
* Total number of warnings found during the run.
* @param int $totalFixable
* Total number of problems that can be fixed.
* @param bool $showSources
* Show sources?
* @param int $width
* Maximum allowed line width.
* @param bool $interactive
* Are we running in interactive mode?
* @param bool $toScreen
* Is the report being printed to screen?
*
* @return void
*/
public function generate(
$cachedData,
$totalFiles,
$totalErrors,
$totalWarnings,
$totalFixable,
$showSources=FALSE,
$width=80,
$interactive=FALSE,
$toScreen=TRUE
) {
echo $cachedData;

}//end generate()


}//end class
13 changes: 13 additions & 0 deletions .github/misc/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<VirtualHost *:80>
# Variables in this file will be substituted in step "Setup Apache".
DocumentRoot _PWD

<Directory _PWD>
AllowOverride All
Require all granted
</Directory>

<FilesMatch ".+\.php$">
SetHandler "proxy:unix:/run/php/php_PHP_V-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
8 changes: 8 additions & 0 deletions .github/misc/settings.local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/**
* @file
* Custom settings for test runs.
*/

// Never send telemetry data.
$settings['telemetry_enabled'] = FALSE;
6 changes: 6 additions & 0 deletions .github/phpstan/baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^$#"
count: 1
path: ../../xmlsitemap.module
20 changes: 20 additions & 0 deletions .github/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The baseline file is generated with phpstan and contains known errors that
# don't need to show up in every report.
# If a problem got fixed, the file should be re-generated.
# @see https://phpstan.org/user-guide/baseline
# includes:
# - baseline.neon
# @see https://phpstan.org/config-reference
parameters:
level: 0
scanDirectories:
- ../../../../core
- ../../
fileExtensions:
- module
- inc
- install
- test
excludePaths:
- *.tpl.php
- *.api.php
68 changes: 43 additions & 25 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
name: Coding Standards
on: [push, pull_request]
name: Code Checks
on: [pull_request]
jobs:
phpcs:
name: Run phpcs
runs-on: ubuntu-18.04
codechecks:
name: PHPStan and phpcs
runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- name: Setup env
run: |
echo "REPO_NAME=${PWD##*/}" >> $GITHUB_ENV
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
php-version: 8.1
# No composer nor xdebug, but we need our commandline tools.
tools: none, phpstan, phpcs
coverage: none

- uses: actions/checkout@v2
# The checkout action refuses to put it outside, so we have to do it in
# two steps.
- name: Checkout coding standard
uses: actions/checkout@v4
with:
repository: backdrop-ops/phpcs
ref: 1.0.0
path: phpcs
- name: Move standard outside current dir
run: mv phpcs ..

- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer directory
uses: actions/cache@v2
# Core code is necessary for phpstan.
- name: Checkout Backdrop core
uses: actions/checkout@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('./composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Composer install coder_sniffer
run: composer install --ansi --prefer-dist --no-interaction --no-progress
repository: backdrop/backdrop

- name: Backdrop coding standards
run: >
vendor/bin/phpcs -n
--standard=vendor/backdrop/coder/coder_sniffer/Backdrop
--ignore="vendor/*,xmlsitemap.xmlsitemap.inc"
--extensions=install,module,php,inc .
- name: Checkout module
uses: actions/checkout@v4
with:
path: modules/${{ env.REPO_NAME }}

- name: Run PHPStan
run: |
cd modules/${{ env.REPO_NAME }}
phpstan analyze -c .github/phpstan/phpstan.neon --error-format=github --no-progress .
# We run phpcs even if phpstan fails.
- name: Run CodeSniffer
if: ${{ always() }}
run: |
cd modules/${{ env.REPO_NAME }}
phpcs --standard=../../../phpcs/Backdrop --report=.github/misc/Github.php -n --basepath=. *
34 changes: 24 additions & 10 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,58 @@ on: [pull_request]
jobs:
simpletest:
name: Run Simpletest
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Setup env
run: |
echo "REPO_NAME=${PWD##*/}" >> $GITHUB_ENV
echo 'USE_PHP_V=7.4' >> $GITHUB_ENV
- name: Start MySQL and create database
echo 'USE_PHP_V=8.2' >> $GITHUB_ENV
- name: Install MariaDB
uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: 'mariadb-10.5'
root-password: 'root'
auto-start: true

- name: Verify setup and create database
run: |
sudo systemctl start mysql.service
mysql -u root -proot -e 'CREATE DATABASE backdrop;'
echo -e '[client]\nuser = root\npassword = root\nhost = 127.0.0.1' > ~/.my.cnf
mysql -e 'SELECT version()\G'
mysql -e 'CREATE DATABASE backdrop;'
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.USE_PHP_V }}
coverage: none
tools: none

- name: Checkout Backdrop core
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: backdrop/backdrop

- name: Checkout module
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: modules/${{ env.REPO_NAME }}

- name: Setup Apache
run: |
sudo cp -f modules/${{ env.REPO_NAME }}/.github/workflows/apache/default.conf /etc/apache2/sites-available/000-default.conf
sudo cp -f modules/${{ env.REPO_NAME }}/.github/misc/default.conf /etc/apache2/sites-available/000-default.conf
sudo sed -i -e "s?_PWD?$PWD?g" -e "s/_PHP_V/${{ env.USE_PHP_V }}/g" /etc/apache2/sites-available/000-default.conf
sudo apt-get install libapache2-mod-fcgid
sudo a2enmod rewrite proxy fcgid proxy_fcgi
sudo systemctl start apache2.service
sudo sed -i -e 's/user = www-data/user = runner/' /etc/php/${{ env.USE_PHP_V }}/fpm/pool.d/www.conf
sudo sed -i -e 's/listen.owner = www-data/listen.owner = runner/' /etc/php/${{ env.USE_PHP_V }}/fpm/pool.d/www.conf
sudo systemctl restart php${{ env.USE_PHP_V }}-fpm.service
- name: Install Backdrop
run: core/scripts/install.sh --db-url=mysql://root:root@localhost/backdrop
run: |
cp modules/${{ env.REPO_NAME }}/.github/misc/settings.local.php .
core/scripts/install.sh --db-url=mysql://root:root@127.0.0.1/backdrop
- name: Run functional tests
run: core/scripts/run-tests.sh --force --directory=modules/${{ env.REPO_NAME }} --verbose --color --concurrency=2
run: core/scripts/run-tests.sh --force --directory=modules/${{ env.REPO_NAME }} --verbose --color --concurrency=3 --cache 2>&1
4 changes: 2 additions & 2 deletions xmlsitemap_custom/xmlsitemap_custom.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function xmlsitemap_custom_list_links() {
$row['priority'] = number_format($link->priority, 1);
$row['changefreq'] = $link->changefreq ? backdrop_ucfirst(xmlsitemap_get_changefreq($link->changefreq)) : t('None');
if (isset($header['language'])) {
$row['language'] = module_invoke('locale', 'language_name', $link->language);
$row['language'] = language_name($link->language);
}
$operations = array();
$operations['edit'] = xmlsitemap_get_operation_link('admin/config/search/xmlsitemap/custom/edit/' . $link->id, array('title' => t('Edit'), 'modal' => TRUE));
Expand Down Expand Up @@ -110,7 +110,7 @@ function xmlsitemap_custom_edit_link_form($form, &$form_state, $link = array())
'#default_value' => $link['changefreq'],
'#description' => t('How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.'),
);
$languages = module_exists('locale') ? locale_language_list() : array();
$languages = module_exists('locale') ? language_list(TRUE, TRUE, TRUE) : array();
$form['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
Expand Down
7 changes: 6 additions & 1 deletion xmlsitemap_i18n/tests/xmlsitemap_i18n.test
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {

// Add predefined language and reset the locale cache.
require_once BACKDROP_ROOT . '/includes/locale.inc';
locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
$french = (object) array(
'langcode' => 'fr',
'name' => 'French',
'direction' => LANGUAGE_LTR,
);
language_save($french);
backdrop_language_initialize();
config_set('xmlsitemap.settings', 'language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);

Expand Down
6 changes: 3 additions & 3 deletions xmlsitemap_i18n/xmlsitemap_i18n.module
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function xmlsitemap_i18n_autoload_info() {
function xmlsitemap_i18n_xmlsitemap_context_info() {
$context['language'] = array(
'label' => t('Language'),
'summary callback' => 'locale_language_name',
'summary callback' => 'language_name',
'default' => language_default('language'),
);
return $context;
Expand All @@ -37,7 +37,7 @@ function xmlsitemap_i18n_xmlsitemap_context_info() {
* Implements hook_xmlsitemap_context().
*/
function xmlsitemap_i18n_xmlsitemap_context() {
$context['language'] = $GLOBALS['language']->language;
$context['language'] = $GLOBALS['language']->langcode;
return $context;
}

Expand All @@ -59,7 +59,7 @@ function xmlsitemap_i18n_form_xmlsitemap_sitemap_edit_form_alter(&$form, $form_s
$form['context']['language'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#options' => locale_language_list(),
'#options' => language_list(TRUE, TRUE, TRUE),
'#default_value' => isset($form['#sitemap']->context['language']) ? $form['#sitemap']->context['language'] : LANGUAGE_NONE,
);
}
Expand Down

0 comments on commit cc3c8bc

Please sign in to comment.