PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
← All changes | includes/base/counter.php +6 -0 1.3.12 → 1.4.2 View file →
@@ -29,8 +29,10 @@
29 29 */
30 30 public static function add( $property = 'uploaded', $source_type = 'media_library' ){
31 31 $settings_key = Schema::getConstant('COUNTER_KEY');
32 32 $data = Utils::get_option( $source_type, [], $settings_key );
33 + // Self-heal a legacy/corrupted non-array row instead of crashing on it.
34 + $data = is_array($data) ? $data : [];
33 35 $data[$property] = isset($data[$property]) ? (int)$data[$property] + 1 : 1;
34 36 return Utils::update_option( $source_type, $data, $settings_key );
35 37 }
36 38
@@ -42,8 +44,10 @@
42 44 */
43 45 public static function remove( $property = 'uploaded', $source_type = 'media_library' ){
44 46 $settings_key = Schema::getConstant('COUNTER_KEY');
45 47 $data = Utils::get_option( $source_type, [], $settings_key );
48 + // Self-heal a legacy/corrupted non-array row instead of crashing on it.
49 + $data = is_array($data) ? $data : [];
46 50 $data[$property] = isset($data[$property]) ? (int)$data[$property] - 1 : -1;
47 51
48 52 return Utils::update_option( $source_type, $data, $settings_key );
49 53 }
@@ -65,8 +69,10 @@
65 69 public static function update( $property, $value, $source_type = 'media_library' ) {
66 70 $key = Schema::getConstant('COUNTER_KEY');
67 71 // Update the count by source type
68 72 $data = Utils::get_option( $source_type, [], $key );
73 + // Self-heal a legacy/corrupted non-array row instead of crashing on it.
74 + $data = is_array($data) ? $data : [];
69 75 $data[$property] = $value;
70 76 return Utils::update_option( $source_type, $data, $key );
71 77 }
72 78