PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.1
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.1
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / classes / class-imagify-cron-sync-files.php

class-imagify-cron-sync-files.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.1, at inc/classes/class-imagify-cron-sync-files.php

101 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Imagify\Traits\InstanceGetterTrait;
4
5 /**
6 * Class that scans the custom folders to keep files in sync in the database.
7 *
8 * @since 1.7
9 */
10 class Imagify_Cron_Sync_Files extends Imagify_Abstract_Cron {
11 use InstanceGetterTrait;
12
13 /**
14 * Class version.
15 *
16 * @var string
17 * @since 1.7
18 */
19 const VERSION = '1.0';
20
21 /**
22 * Cron name.
23 *
24 * @var string
25 * @since 1.7
26 */
27 protected $event_name = 'imagify_sync_files';
28
29 /**
30 * Cron recurrence.
31 *
32 * @var string
33 * @since 1.7
34 */
35 protected $event_recurrence = 'daily';
36
37 /**
38 * Cron time.
39 *
40 * @var string
41 * @since 1.7
42 */
43 protected $event_time = '02:00';
44
45
46 /** ----------------------------------------------------------------------------------------- */
47 /** HOOKS =================================================================================== */
48 /** ----------------------------------------------------------------------------------------- */
49
50 /**
51 * The event action.
52 *
53 * @since 1.7
54 */
55 public function do_event() {
56 $folders_db = Imagify_Folders_DB::get_instance();
57 $files_db = Imagify_Files_DB::get_instance();
58
59 if ( ! $folders_db->can_operate() || ! $files_db->can_operate() ) {
60 return;
61 }
62
63 if ( ! Imagify_Requirements::is_api_key_valid() ) {
64 return;
65 }
66
67 if ( Imagify_Requirements::is_over_quota() ) {
68 return;
69 }
70
71 $this->set_no_time_limit();
72
73 /**
74 * Get the folders from DB.
75 */
76 $folders = Imagify_Custom_Folders::get_folders();
77
78 if ( ! $folders ) {
79 return;
80 }
81
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 }
99 }
100 }
101