1212
1313class Migrations
1414{
15+ protected $ prefix ;
1516 protected $ option_name ;
1617 protected $ version_from ;
1718 protected $ version_to ;
18- protected $ current_version ;
1919 protected $ migrations_dir ;
20- protected $ prefix ;
2120
2221 public function __construct (string $ prefix , string $ version_to , string $ migrations_dir )
2322 {
2423 $ this ->prefix = rtrim ($ prefix , '_ ' );
25- $ option_name = str_ends_with ($ this ->prefix , '_version ' ) ? $ this ->prefix : "{$ this ->prefix }_version " ;
26- $ this ->option_name = $ option_name ;
24+ $ this ->option_name = str_ends_with ($ this ->prefix , '_version ' ) ? $ this ->prefix : "{$ this ->prefix }_version " ;
2725 $ this ->version_from = isset ($ _GET ["{$ this ->prefix }_migrate_from_version " ]) && current_user_can ('manage_options ' ) ? $ _GET ["{$ this ->prefix }_migrate_from_version " ] : get_option ($ this ->option_name , '0.0.0 ' );
2826 $ this ->version_to = $ version_to ;
2927 $ this ->migrations_dir = $ migrations_dir ;
@@ -36,13 +34,16 @@ public function maybe_run(): void
3634 }
3735
3836 // check if migrations not already running
39- if (get_transient ("{$ this ->prefix }_migrations_running " )) {
37+ $ transient_key = "{$ this ->prefix }_migrations_running " ;
38+ $ transient_timeout = 10 ;
39+ $ previous_run_start = get_transient ($ transient_key );
40+ if ($ previous_run_start && $ previous_run_start > time () - $ transient_timeout ) {
4041 return ;
4142 }
4243
43- set_transient ("{ $ this -> prefix } _migrations_running " , true , 3 );
44+ set_transient ($ transient_key , time (), $ transient_timeout );
4445 $ this ->run ();
45- delete_transient ("{ $ this -> prefix } _migrations_running " );
46+ delete_transient ($ transient_key );
4647 }
4748
4849 /**
0 commit comments