Skip to content

Commit 69632af

Browse files
committed
Fixes
1 parent d4381a9 commit 69632af

13 files changed

Lines changed: 308 additions & 117 deletions
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Update Translation File
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- '*.php'
8+
- '**/*.php'
9+
- '*.js'
10+
- '**/*.js'
11+
- '.github/workflows/update-pot-file.yml'
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
issues: write
22+
23+
env:
24+
PLUGIN_SLUG: enginescript-site-exporter
25+
POT_FILE: languages/enginescript-site-exporter.pot
26+
27+
jobs:
28+
update-pot:
29+
name: Regenerate .pot File
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v6
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Setup PHP
39+
uses: shivammathur/setup-php@v2
40+
with:
41+
php-version: '8.2'
42+
coverage: none
43+
44+
- name: Install WP-CLI
45+
run: |
46+
curl -fsSL -o wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
47+
chmod +x wp-cli.phar
48+
sudo mv wp-cli.phar /usr/local/bin/wp
49+
wp --version
50+
wp help i18n make-pot >/dev/null
51+
52+
- name: Regenerate .pot file
53+
run: |
54+
mkdir -p "$(dirname "$POT_FILE")"
55+
56+
wp i18n make-pot . "$POT_FILE" \
57+
--slug="$PLUGIN_SLUG" \
58+
--domain="$PLUGIN_SLUG" \
59+
--skip-audit \
60+
--exclude=vendor,node_modules,tests,build,plugin-check-build,.git,.github
61+
62+
test -f "$POT_FILE"
63+
64+
- name: Check for changes
65+
id: changes
66+
run: |
67+
if git diff --quiet --ignore-matching-lines='^"POT-Creation-Date:' -- "$POT_FILE"; then
68+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
69+
echo "Translation file is up to date"
70+
git restore -- "$POT_FILE"
71+
else
72+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
73+
echo "Translation file updated"
74+
git diff --ignore-matching-lines='^"POT-Creation-Date:' -- "$POT_FILE" | head -80
75+
fi
76+
77+
- name: Create Pull Request
78+
if: steps.changes.outputs.has_changes == 'true'
79+
uses: peter-evans/create-pull-request@v8
80+
with:
81+
commit-message: 'chore(i18n): regenerate translation template'
82+
title: 'chore(i18n): Update translation template (.pot file)'
83+
body: |
84+
## Translation Template Update
85+
86+
This PR updates the translation template (`.pot` file) based on recent code changes.
87+
88+
### What Changed
89+
The following PHP and JavaScript source files had translatable strings added or modified.
90+
91+
See the diff in this PR for details.
92+
93+
### Next Steps
94+
1. Review the changes in the `.pot` file
95+
2. Approve and merge this PR
96+
3. Translators can then use the updated `.pot` file with their translation tools
97+
98+
---
99+
*This PR was automatically generated by the [Update Translation File](https://github.com/${{ github.repository }}/blob/main/.github/workflows/update-pot-file.yml) workflow.*
100+
add-paths: ${{ env.POT_FILE }}
101+
branch: chore/update-pot-file
102+
base: main
103+
delete-branch: true
104+
labels: 'automation,maintenance'

.github/workflows/wp-compatibility-test.yml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -406,34 +406,12 @@ jobs:
406406
dependency-versions: highest
407407
composer-options: "--prefer-dist --no-progress"
408408

409-
- name: Install Psalm
410-
run: composer require --dev vimeo/psalm:"^6.16" --with-all-dependencies --no-progress
411-
412-
- name: Create Psalm config
413-
run: |
414-
cat > psalm.xml << 'EOF'
415-
<?xml version="1.0"?>
416-
<psalm
417-
errorLevel="3"
418-
resolveFromConfigFile="true"
419-
>
420-
<projectFiles>
421-
<directory name="." />
422-
<ignoreFiles>
423-
<directory name="vendor" />
424-
</ignoreFiles>
425-
</projectFiles>
426-
</psalm>
427-
EOF
409+
- name: Verify Psalm installation
410+
run: vendor/bin/psalm --version
428411

429412
- name: Run Psalm
430413
run: |
431-
# Initialize Psalm configuration if needed
432-
if [ ! -f psalm.xml ]; then
433-
./vendor/bin/psalm --init
434-
fi
435-
436-
./vendor/bin/psalm --show-info=true
414+
vendor/bin/psalm --config=psalm.xml --show-info=true
437415
438416
- name: Create issue on Psalm failure
439417
if: ${{ failure() }}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"dealerdirect/phpcodesniffer-composer-installer": "^1.2",
2323
"friendsofphp/php-cs-fixer": "^3.95",
2424
"phpmd/phpmd": "^2.15",
25+
"vimeo/psalm": "^6.16",
2526
"php-stubs/wordpress-stubs": "^6.9",
2627
"szepeviktor/phpstan-wordpress": "^2.0",
2728
"phpstan/phpstan": "^2.1",
@@ -31,11 +32,13 @@
3132
"phpcs": "phpcs --standard=phpcs.xml",
3233
"phpcs:fix": "phpcbf --standard=phpcs.xml",
3334
"phpmd": "phpmd . text phpmd.xml --exclude vendor",
35+
"psalm": "psalm --config=psalm.xml --show-info=true",
3436
"phpstan": "phpstan analyze --memory-limit=1G",
3537
"test": "phpunit",
3638
"check-all": [
3739
"@phpcs",
3840
"@phpmd",
41+
"@psalm",
3942
"@phpstan"
4043
]
4144
},

includes/admin-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function sse_exporter_page_html(): void {
181181
}
182182

183183
$export_dir_path = sse_get_export_directory_path();
184-
if ( is_wp_error( $export_dir_path ) ) {
184+
if ( sse_is_wp_error( $export_dir_path ) ) {
185185
sse_wp_die( $export_dir_path->get_error_message() );
186186
}
187187
$display_path = wp_normalize_path( $export_dir_path );

includes/archive.php

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,29 @@ function sse_is_path_within_export_source( string $path, string $directory ): bo
5555
* Creates a site archive with database and files.
5656
*
5757
* @since 1.0.0
58-
* @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
59-
* @param array{filename: string, filepath: string} $database_file Database file information.
60-
* @param string $site_identifier Sanitized site identifier.
61-
* @param string $timestamp Export timestamp.
58+
* @param array $export_paths Export directory paths.
59+
* @param array $database_file Database file information.
60+
* @param string $site_identifier Sanitized site identifier.
61+
* @param string $timestamp Export timestamp.
62+
* @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
63+
* @psalm-param array{filename: string, filepath: string} $database_file
6264
* @return array{filename: string, filepath: string}|WP_Error Archive info on success, WP_Error on failure.
6365
*/
6466
function sse_create_site_archive( array $export_paths, array $database_file, string $site_identifier, string $timestamp ) {
6567
$requirements_result = sse_validate_archive_requirements();
66-
if ( is_wp_error( $requirements_result ) ) {
68+
if ( sse_is_wp_error( $requirements_result ) ) {
6769
return $requirements_result;
6870
}
6971

7072
$bundle_paths = sse_prepare_engine_script_bundle_paths( $export_paths, $site_identifier, $timestamp );
7173
$setup_result = sse_create_bundle_staging_directories( $bundle_paths );
72-
if ( is_wp_error( $setup_result ) ) {
74+
if ( sse_is_wp_error( $setup_result ) ) {
7375
return $setup_result;
7476
}
7577

7678
try {
7779
$archive_result = sse_build_engine_script_bundle( $export_paths, $database_file, $bundle_paths, $site_identifier );
78-
if ( is_wp_error( $archive_result ) ) {
80+
if ( sse_is_wp_error( $archive_result ) ) {
7981
return $archive_result;
8082
}
8183

@@ -115,30 +117,33 @@ function sse_validate_archive_requirements() {
115117
* Builds the staged EngineScript bundle payload.
116118
*
117119
* @since 2.0.0
118-
* @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
119-
* @param array{filename: string, filepath: string} $database_file Database file information.
120-
* @param array{database_path: string, files_archive_path: string, manifest_path: string, database_gz_filename: string, files_archive_filename: string, combined_zip_path: string, combined_zip_filename: string} $bundle_paths Bundle paths.
121-
* @param string $site_identifier Sanitized site identifier.
120+
* @param array $export_paths Export directory paths.
121+
* @param array $database_file Database file information.
122+
* @param array $bundle_paths Bundle paths.
123+
* @param string $site_identifier Sanitized site identifier.
124+
* @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
125+
* @psalm-param array{filename: string, filepath: string} $database_file
126+
* @psalm-param array{database_path: string, files_archive_path: string, manifest_path: string, database_gz_filename: string, files_archive_filename: string, combined_zip_path: string, combined_zip_filename: string, ...} $bundle_paths
122127
* @return true|WP_Error True on success, WP_Error on failure.
123128
*/
124129
function sse_build_engine_script_bundle( array $export_paths, array $database_file, array $bundle_paths, string $site_identifier ) {
125130
$database_result = sse_create_compressed_database_file( $database_file['filepath'], $bundle_paths['database_path'] );
126-
if ( is_wp_error( $database_result ) ) {
131+
if ( sse_is_wp_error( $database_result ) ) {
127132
return $database_result;
128133
}
129134

130135
$file_result = sse_create_wordpress_files_archive( $bundle_paths['files_archive_path'], $export_paths['export_dir'] );
131-
if ( is_wp_error( $file_result ) ) {
136+
if ( sse_is_wp_error( $file_result ) ) {
132137
return $file_result;
133138
}
134139

135140
$manifest_result = sse_write_engine_script_manifest( $bundle_paths, $site_identifier );
136-
if ( is_wp_error( $manifest_result ) ) {
141+
if ( sse_is_wp_error( $manifest_result ) ) {
137142
return $manifest_result;
138143
}
139144

140145
$zip_result = sse_create_combined_engine_script_zip( $bundle_paths );
141-
if ( is_wp_error( $zip_result ) ) {
146+
if ( sse_is_wp_error( $zip_result ) ) {
142147
return $zip_result;
143148
}
144149

@@ -149,16 +154,17 @@ function sse_build_engine_script_bundle( array $export_paths, array $database_fi
149154
* Prepares canonical EngineScript bundle paths and filenames.
150155
*
151156
* @since 2.0.0
152-
* @param array{export_dir: string, export_dir_name: string} $export_paths Export directory paths.
153-
* @param string $site_identifier Sanitized site identifier.
154-
* @param string $timestamp Export timestamp.
157+
* @param array $export_paths Export directory paths.
158+
* @param string $site_identifier Sanitized site identifier.
159+
* @param string $timestamp Export timestamp.
160+
* @psalm-param array{export_dir: string, export_dir_name: string} $export_paths
155161
* @return array{staging_dir: string, bundle_root_dir: string, database_dir: string, files_dir: string, manifest_path: string, database_filename: string, database_gz_filename: string, database_path: string, files_archive_filename: string, files_archive_path: string, combined_zip_filename: string, combined_zip_path: string}
156162
*/
157163
function sse_prepare_engine_script_bundle_paths( array $export_paths, string $site_identifier, string $timestamp ): array {
158-
$staging_dir = trailingslashit( $export_paths['export_dir'] ) . 'staging-' . $timestamp;
159-
$bundle_root_dir = trailingslashit( $staging_dir ) . 'bundle';
160-
$database_dir = trailingslashit( $bundle_root_dir ) . 'database';
161-
$files_dir = trailingslashit( $bundle_root_dir ) . 'files';
164+
$staging_dir = trailingslashit( $export_paths['export_dir'] ) . 'staging-' . $timestamp;
165+
$bundle_root_dir = trailingslashit( $staging_dir ) . 'bundle';
166+
$database_dir = trailingslashit( $bundle_root_dir ) . 'database';
167+
$files_dir = trailingslashit( $bundle_root_dir ) . 'files';
162168
$database_filename = "{$site_identifier}_db_{$timestamp}.sql";
163169
$database_gz_filename = $database_filename . '.gz';
164170
$files_archive_filename = "{$site_identifier}_files_{$timestamp}.tar.gz";
@@ -184,7 +190,8 @@ function sse_prepare_engine_script_bundle_paths( array $export_paths, string $si
184190
* Creates bundle staging directories.
185191
*
186192
* @since 2.0.0
187-
* @param array{database_dir: string, files_dir: string} $bundle_paths Bundle paths.
193+
* @param array $bundle_paths Bundle paths.
194+
* @psalm-param array{database_dir: string, files_dir: string, ...} $bundle_paths
188195
* @return true|WP_Error True on success, WP_Error on failure.
189196
*/
190197
function sse_create_bundle_staging_directories( array $bundle_paths ) {
@@ -258,7 +265,7 @@ function sse_create_wordpress_files_archive( string $files_archive_path, string
258265
$file_result = sse_add_wordpress_files_to_tar( $tar_archive, $export_dir );
259266
unset( $tar_archive );
260267

261-
if ( is_wp_error( $file_result ) ) {
268+
if ( sse_is_wp_error( $file_result ) ) {
262269
sse_cleanup_files( [ $tar_path, $files_archive_path ] );
263270
return $file_result;
264271
}
@@ -290,8 +297,9 @@ function sse_create_wordpress_files_archive( string $files_archive_path, string
290297
* Writes the EngineScript archive manifest.
291298
*
292299
* @since 2.0.0
293-
* @param array{manifest_path: string, database_gz_filename: string, files_archive_filename: string} $bundle_paths Bundle paths.
294-
* @param string $site_identifier Sanitized site identifier.
300+
* @param array $bundle_paths Bundle paths.
301+
* @param string $site_identifier Sanitized site identifier.
302+
* @psalm-param array{manifest_path: string, database_gz_filename: string, files_archive_filename: string, ...} $bundle_paths
295303
* @return true|WP_Error True on success, WP_Error on failure.
296304
*/
297305
function sse_write_engine_script_manifest( array $bundle_paths, string $site_identifier ) {
@@ -308,7 +316,7 @@ function sse_write_engine_script_manifest( array $bundle_paths, string $site_ide
308316
) . "\n";
309317

310318
$filesystem_init = sse_init_filesystem();
311-
if ( is_wp_error( $filesystem_init ) ) {
319+
if ( sse_is_wp_error( $filesystem_init ) ) {
312320
return $filesystem_init;
313321
}
314322

@@ -324,7 +332,8 @@ function sse_write_engine_script_manifest( array $bundle_paths, string $site_ide
324332
* Creates the outer EngineScript ZIP archive.
325333
*
326334
* @since 2.0.0
327-
* @param array{combined_zip_path: string, manifest_path: string, database_path: string, database_gz_filename: string, files_archive_path: string, files_archive_filename: string} $bundle_paths Bundle paths.
335+
* @param array $bundle_paths Bundle paths.
336+
* @psalm-param array{combined_zip_path: string, manifest_path: string, database_path: string, database_gz_filename: string, files_archive_path: string, files_archive_filename: string, ...} $bundle_paths
328337
* @return true|WP_Error True on success, WP_Error on failure.
329338
*/
330339
function sse_create_combined_engine_script_zip( array $bundle_paths ) {
@@ -344,7 +353,7 @@ function sse_create_combined_engine_script_zip( array $bundle_paths ) {
344353
$zip->addEmptyDir( 'files' );
345354

346355
$entries = [
347-
'manifest.txt' => $bundle_paths['manifest_path'],
356+
'manifest.txt' => $bundle_paths['manifest_path'],
348357
'database/' . $bundle_paths['database_gz_filename'] => $bundle_paths['database_path'],
349358
'files/' . $bundle_paths['files_archive_filename'] => $bundle_paths['files_archive_path'],
350359
];
@@ -381,12 +390,16 @@ function sse_create_combined_engine_script_zip( array $bundle_paths ) {
381390
* @return bool True if deleted or absent, false on failure.
382391
*/
383392
function sse_delete_directory_tree( string $directory ): bool {
384-
if ( is_wp_error( sse_init_filesystem() ) ) {
393+
if ( sse_is_wp_error( sse_init_filesystem() ) ) {
385394
return false;
386395
}
387396

388397
$export_dir = sse_get_export_directory_path();
389-
if ( is_wp_error( $export_dir ) || ! sse_is_path_within_directory( $directory, $export_dir ) ) {
398+
if ( sse_is_wp_error( $export_dir ) ) {
399+
return false;
400+
}
401+
402+
if ( ! sse_is_path_within_directory( $directory, $export_dir ) ) {
390403
return false;
391404
}
392405

@@ -408,7 +421,7 @@ function sse_delete_directory_tree( string $directory ): bool {
408421
*/
409422
function sse_add_wordpress_files_to_tar( PharData $tar, string $export_dir ) {
410423
$source_path = realpath( ABSPATH );
411-
if ( ! $source_path ) {
424+
if ( false === $source_path ) {
412425
sse_log( 'Could not resolve real path for ABSPATH. Using ABSPATH directly.', 'warning' );
413426
$source_path = ABSPATH;
414427
}
@@ -422,7 +435,7 @@ function sse_add_wordpress_files_to_tar( PharData $tar, string $export_dir ) {
422435

423436
foreach ( $files as $file_info ) {
424437
$file_result = sse_process_file_for_tar( $tar, $file_info, $source_path, $export_dir );
425-
if ( is_wp_error( $file_result ) ) {
438+
if ( sse_is_wp_error( $file_result ) ) {
426439
return $file_result;
427440
}
428441
}
@@ -570,10 +583,17 @@ function sse_should_exclude_file( string $pathname, string $relative_path, strin
570583
*
571584
* @param int $max_file_size Maximum file size in bytes. Default is user's selection or 0 (no limit).
572585
*/
573-
$cached_max_file_size ??= (int) apply_filters(
574-
SSE_FILTER_MAX_FILE_SIZE,
575-
get_transient( 'sse_export_max_file_size_' . get_current_user_id() ) ?: 0
576-
);
586+
if ( null === $cached_max_file_size ) {
587+
$selected_max_file_size = get_transient( 'sse_export_max_file_size_' . get_current_user_id() );
588+
if ( false === $selected_max_file_size || ! is_numeric( $selected_max_file_size ) ) {
589+
$selected_max_file_size = 0;
590+
}
591+
592+
$cached_max_file_size = (int) apply_filters(
593+
SSE_FILTER_MAX_FILE_SIZE,
594+
(int) $selected_max_file_size
595+
);
596+
}
577597

578598
if ( $cached_max_file_size > 0 && $file_info->getSize() > $cached_max_file_size ) {
579599
sse_log( 'Excluding large file: ' . $pathname . ' (Size: ' . size_format( $file_info->getSize() ) . ', Limit: ' . size_format( $cached_max_file_size ) . ')', 'info' );

0 commit comments

Comments
 (0)