wearerequired / traduttore

🗼 A WordPress plugin to improve the I18N workflow for your own projects based on @GlotPress.
https://wearerequired.github.io/traduttore/
72 stars 15 forks source link

Generate zip file names with the version number in them #143

Closed swissspidy closed 5 years ago

swissspidy commented 5 years ago

Description See #140.

How has this been tested? Added more unit tests.

Types of changes New feature (non-breaking change which adds functionality) Kind of a breaking change as file names change.

Checklist:

codecov-io commented 5 years ago

Codecov Report

Merging #143 into master will decrease coverage by 0.16%. The diff coverage is 67.34%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #143      +/-   ##
============================================
- Coverage     79.79%   79.63%   -0.17%     
- Complexity      379      397      +18     
============================================
  Files            24       24              
  Lines           896      928      +32     
============================================
+ Hits            715      739      +24     
- Misses          181      189       +8
Impacted Files Coverage Δ Complexity Δ
inc/Project.php 100% <ø> (ø) 53 <0> (ø) :arrow_down:
inc/ZipProvider.php 98.82% <100%> (+0.12%) 25 <0> (+1) :arrow_up:
inc/Plugin.php 41.76% <55.55%> (+4.09%) 71 <7> (+17) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ba2340f...7de4181. Read the comment docs.

grappler commented 5 years ago

Once the next version of Glotpress is released the code could be changed to

diff --git a/inc/Plugin.php b/inc/Plugin.php
index 3c6af31..1fcd9d8 100644
--- a/inc/Plugin.php
+++ b/inc/Plugin.php
@@ -53,7 +53,12 @@ class Plugin {

                add_action(
                        'gp_translation_saved',
-                       function ( GP_Translation $translation ) {
+                       function ( GP_Translation $translation, GP_Translation $translation_before ) {
+                               // Only run if translation is added or removed from current.
+                               if ( 'current' !== $translation->status && 'current' !== $translation_before->status ) {
+                                       return;
+                               }
+
                                /* @var GP_Translation_Set $translation_set */
                                $translation_set = GP::$translation_set->get( $translation->translation_set_id );

@@ -62,18 +67,11 @@ class Plugin {
                                        return;
                                }

-                               $last_modified = $translation_set->last_modified();
-                               if ( $last_modified ) {
-                                       $last_modified = new DateTime( $last_modified, new DateTimeZone( 'UTC' ) );
-                               } else {
-                                       $last_modified = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
-                               }
-
                                $zip_provider = new ZipProvider( $translation_set );
-                               if ( $last_modified > $zip_provider->get_last_build_time() ) {
-                                       $zip_provider->schedule_generation();
-                               }
-                       }
+                               $zip_provider->schedule_generation();
+                       },
+                       10,
+                       2
                );