| @@ -1,14 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); | |
| 3 | 2 | |
| 3 | +use Imagify\Traits\InstanceGetterTrait; | |
| 4 | + | |
| 4 | 5 | /** |
| 5 | 6 | * Class that scans the custom folders to keep files in sync in the database. |
| 6 | 7 | * |
| 7 | 8 | * @since 1.7 |
| 8 | - * @author Grégory Viguier | |
| 9 | 9 | */ |
| 10 | 10 | class Imagify_Cron_Sync_Files extends Imagify_Abstract_Cron { |
| 11 | + use InstanceGetterTrait; | |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Class version. |
| 14 | 15 | * |
| @@ -21,9 +22,8 @@ | ||
| 21 | 22 | * Cron name. |
| 22 | 23 | * |
| 23 | 24 | * @var string |
| 24 | 25 | * @since 1.7 |
| 25 | - * @access protected | |
| 26 | 26 | */ |
| 27 | 27 | protected $event_name = 'imagify_sync_files'; |
| 28 | 28 | |
| 29 | 29 | /** |
| @@ -30,9 +30,8 @@ | ||
| 30 | 30 | * Cron recurrence. |
| 31 | 31 | * |
| 32 | 32 | * @var string |
| 33 | 33 | * @since 1.7 |
| 34 | - * @access protected | |
| 35 | 34 | */ |
| 36 | 35 | protected $event_recurrence = 'daily'; |
| 37 | 36 | |
| 38 | 37 | /** |
| @@ -39,39 +38,12 @@ | ||
| 39 | 38 | * Cron time. |
| 40 | 39 | * |
| 41 | 40 | * @var string |
| 42 | 41 | * @since 1.7 |
| 43 | - * @access protected | |
| 44 | 42 | */ |
| 45 | 43 | protected $event_time = '02:00'; |
| 46 | 44 | |
| 47 | - /** | |
| 48 | - * The single instance of the class. | |
| 49 | - * | |
| 50 | - * @var object | |
| 51 | - * @since 1.7 | |
| 52 | - * @access protected | |
| 53 | - */ | |
| 54 | - protected static $_instance; | |
| 55 | 45 | |
| 56 | - /** | |
| 57 | - * Get the main Instance. | |
| 58 | - * | |
| 59 | - * @since 1.7 | |
| 60 | - * @access public | |
| 61 | - * @author Grégory Viguier | |
| 62 | - * | |
| 63 | - * @return object Main instance. | |
| 64 | - */ | |
| 65 | - public static function get_instance() { | |
| 66 | - if ( ! isset( self::$_instance ) ) { | |
| 67 | - self::$_instance = new self(); | |
| 68 | - } | |
| 69 | - | |
| 70 | - return self::$_instance; | |
| 71 | - } | |
| 72 | - | |
| 73 | - | |
| 74 | 46 | /** ----------------------------------------------------------------------------------------- */ |
| 75 | 47 | /** HOOKS =================================================================================== */ |
| 76 | 48 | /** ----------------------------------------------------------------------------------------- */ |
| 77 | 49 | |
| @@ -77,15 +49,11 @@ | ||
| 77 | 49 | |
| 78 | 50 | /** |
| 79 | 51 | * The event action. |
| 80 | 52 | * |
| 81 | - * @since 1.7 | |
| 82 | - * @access public | |
| 83 | - * @author Grégory Viguier | |
| 53 | + * @since 1.7 | |
| 84 | 54 | */ |
| 85 | 55 | public function do_event() { |
| 86 | - global $wpdb; | |
| 87 | - | |
| 88 | 56 | $folders_db = Imagify_Folders_DB::get_instance(); |
| 89 | 57 | $files_db = Imagify_Files_DB::get_instance(); |
| 90 | 58 | |
| 91 | 59 | if ( ! $folders_db->can_operate() || ! $files_db->can_operate() ) { |
| @@ -99,9 +67,9 @@ | ||
| 99 | 67 | if ( Imagify_Requirements::is_over_quota() ) { |
| 100 | 68 | return; |
| 101 | 69 | } |
| 102 | 70 | |
| 103 | - @set_time_limit( 0 ); | |
| 71 | + $this->set_no_time_limit(); | |
| 104 | 72 | |
| 105 | 73 | /** |
| 106 | 74 | * Get the folders from DB. |
| 107 | 75 | */ |
| @@ -111,6 +79,22 @@ | ||
| 111 | 79 | return; |
| 112 | 80 | } |
| 113 | 81 | |
| 114 | 82 | Imagify_Custom_Folders::synchronize_files_from_folders( $folders ); |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * Attempts to set no limit to the PHP timeout for time intensive processes. | |
| 87 | + * | |
| 88 | + * @return void | |
| 89 | + */ | |
| 90 | + protected function set_no_time_limit() { | |
| 91 | + if ( | |
| 92 | + function_exists( 'set_time_limit' ) | |
| 93 | + && | |
| 94 | + false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) | |
| 95 | + && ! ini_get( 'safe_mode' ) // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.safe_modeDeprecatedRemoved | |
| 96 | + ) { | |
| 97 | + @set_time_limit( 0 ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 98 | + } | |
| 115 | 99 | } |
| 116 | 100 | } |