PluginProbe
SweepPress: Website Cleanup and Optimization / 2.2
SweepPress: Website Cleanup and Optimization v2.2
trunk 1.1 1.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.8 2.0 2.1 2.1.1 2.2 2.3 2.3.1 2.4 2.4.1 2.4.2 2.5 2.6 3.0 3.1 3.1.1 3.2 All 39 releases
sweeppress / core / basic / Settings.php

Settings.php in SweepPress: Website Cleanup and Optimization 2.2, at core/basic/Settings.php

195 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dev4Press\Plugin\SweepPress\Basic;
4
5 use Dev4Press\v41\Core\Plugins\Settings as BaseSettings;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class Settings extends BaseSettings {
12 public $base = 'sweeppress';
13
14 public $settings = array(
15 'core' => array(
16 'activated' => 0
17 ),
18 'statistics' => array(
19 'months' => array(),
20 'total' => array()
21 ),
22 'settings' => array(
23 'expand_cli' => false,
24 'expand_rest' => false,
25 'hide_backup_notices' => false
26 ),
27 'sweepers' => array(
28 'keep_days_posts-auto-draft' => 14,
29 'keep_days_posts-spam' => 14,
30 'keep_days_posts-trash' => 14,
31 'keep_days_posts-revisions' => 14,
32 'keep_days_posts-draft-revisions' => 14,
33 'keep_days_comments-spam' => 14,
34 'keep_days_comments-trash' => 14,
35 'keep_days_comments-unapproved' => 60,
36 'keep_days_comments-pingback' => 14,
37 'keep_days_comments-trackback' => 14,
38 'keep_days_comments-ua' => 14,
39 'keep_days_comments-akismet' => 14,
40 'keep_days_signups-inactive' => 90,
41 'keep_days_actionscheduler-log' => 14,
42 'keep_days_actionscheduler-failed' => 14,
43 'keep_days_actionscheduler-complete' => 14,
44 'keep_days_actionscheduler-canceled' => 14,
45 'db_table_optimize_threshold' => 40,
46 'db_table_optimize_min_size' => 6,
47 'db_table_optimize_method' => 'optimize',
48 'last_used_timestamp' => array()
49 )
50 );
51
52 public function log_statistics( $input = array() ) {
53 $default = array(
54 'source' => '',
55 'records' => 0,
56 'size' => 0,
57 'time' => 0,
58 'jobs' => 0,
59 'tasks' => 0,
60 'sweepers' => array()
61 );
62
63 $input = wp_parse_args( $input, $default );
64
65 if ( in_array( $input['source'], array( 'quick', 'scheduler', 'panel', 'auto', 'cli', 'rest' ) ) ) {
66 $month = date( 'Y-m' );
67
68 if ( ! isset( $this->current['statistics']['months'][ $month ] ) ) {
69 $this->current['statistics']['months'][ $month ] = $this->_statistics_empty();
70 }
71
72 $this->current['statistics']['months'][ $month ][ $input['source'] ] ++;
73 $this->current['statistics']['months'][ $month ]['records'] += $input['records'] ?? 0;
74 $this->current['statistics']['months'][ $month ]['size'] += $input['size'] ?? 0;
75 $this->current['statistics']['months'][ $month ]['time'] += $input['time'] ?? 0;
76 $this->current['statistics']['months'][ $month ]['jobs'] += $input['jobs'] ?? 0;
77 $this->current['statistics']['months'][ $month ]['tasks'] += $input['tasks'] ?? 0;
78
79 foreach ( $input['sweepers'] as $sweep => $data ) {
80 if ( ! isset( $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ] ) ) {
81 $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ] = array(
82 'records' => 0,
83 'size' => 0,
84 'time' => 0,
85 'counts' => 0
86 );
87 }
88
89 $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ]['records'] += $data['records'] ?? 0;
90 $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ]['size'] += $data['size'] ?? 0;
91 $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ]['time'] += $data['time'] ?? 0;
92 $this->current['statistics']['months'][ $month ]['sweepers'][ $sweep ]['counts'] ++;
93
94 $this->current['sweepers']['last_used_timestamp'][ $sweep ] = time();
95 }
96
97 if ( empty( $this->current['statistics']['total'] ) ) {
98 $this->current['statistics']['total'] = $this->_statistics_empty();
99 }
100
101 $this->current['statistics']['total'][ $input['source'] ] ++;
102 $this->current['statistics']['total']['records'] += $input['records'] ?? 0;
103 $this->current['statistics']['total']['size'] += $input['size'] ?? 0;
104 $this->current['statistics']['total']['time'] += $input['time'] ?? 0;
105 $this->current['statistics']['total']['jobs'] += $input['jobs'] ?? 0;
106 $this->current['statistics']['total']['tasks'] += $input['tasks'] ?? 0;
107
108 foreach ( $input['sweepers'] as $sweep => $data ) {
109 if ( ! isset( $this->current['statistics']['total']['sweepers'][ $sweep ] ) ) {
110 $this->current['statistics']['total']['sweepers'][ $sweep ] = array(
111 'records' => 0,
112 'size' => 0,
113 'time' => 0,
114 'counts' => 0
115 );
116 }
117
118 $this->current['statistics']['total']['sweepers'][ $sweep ]['records'] += $data['records'] ?? 0;
119 $this->current['statistics']['total']['sweepers'][ $sweep ]['size'] += $data['size'] ?? 0;
120 $this->current['statistics']['total']['sweepers'][ $sweep ]['time'] += $data['time'] ?? 0;
121 $this->current['statistics']['total']['sweepers'][ $sweep ]['counts'] ++;
122 }
123
124 $this->save( 'statistics' );
125 $this->save( 'sweepers' );
126 }
127 }
128
129 public function get_statistics( string $month = '' ) : array {
130 if ( empty( $month ) || ! isset( $this->current['statistics']['months'][ $month ] ) ) {
131 $value = $this->current['statistics']['total'];
132 $value['label'] = isset( $value['started'] ) ? sprintf( __( "Since: %s", "sweeppress" ), $value['started'] ) : __( "All Time", "sweeppress" );
133 } else {
134 $value = $this->current['statistics']['months'][ $month ];
135 $value['label'] = sprintf( __( "For Month: %s", "sweeppress" ), date_create_from_format( 'Y-m', $month )->format( 'Y F' ) );
136 }
137
138 $value['size_total'] = $value['size'];
139
140 if ( isset( $value['sweepers']['optimize-tables']['size'] ) ) {
141 $value['size'] = $value['size'] - $value['sweepers']['optimize-tables']['size'];
142 }
143
144 return $value;
145 }
146
147 public function list_statistics() : array {
148 $list = array(
149 '' => __( "All Time Statistics", "sweeppress" )
150 );
151
152 foreach ( array_keys( $this->current['statistics']['months'] ) as $month ) {
153 $list[ $month ] = date_create_from_format( 'Y-m', $month )->format( 'Y F' );
154 }
155
156 return $list;
157 }
158
159 public function show_notice( string $name = 'backup' ) : bool {
160 switch ( $name ) {
161 default:
162 case 'backup':
163 return ! $this->get( 'hide_backup_notices' );
164 }
165 }
166
167 public function get_sweeper_last_used_timestamp( string $sweeper ) : int {
168 return isset( $this->current['sweepers']['last_used_timestamp'][ $sweeper ] ) ? intval( $this->current['sweepers']['last_used_timestamp'][ $sweeper ] ) : 0;
169 }
170
171 protected function constructor() {
172 $this->info = new Information();
173
174 add_action( 'sweeppress_load_settings', array( $this, 'init' ) );
175 }
176
177 protected function _statistics_empty() : array {
178 return array(
179 'started' => date( 'c' ),
180 'quick' => 0,
181 'scheduler' => 0,
182 'panel' => 0,
183 'auto' => 0,
184 'cli' => 0,
185 'rest' => 0,
186 'records' => 0,
187 'size' => 0,
188 'jobs' => 0,
189 'tasks' => 0,
190 'time' => 0,
191 'sweepers' => array()
192 );
193 }
194 }
195