PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.10
Post Views Counter v1.3.10
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / class-update.php
post-views-counter / includes Last commit date
class-admin.php 4 years ago class-columns.php 4 years ago class-counter.php 4 years ago class-crawler-detect.php 4 years ago class-cron.php 4 years ago class-dashboard.php 4 years ago class-frontend.php 4 years ago class-functions.php 4 years ago class-query.php 4 years ago class-settings-api.php 4 years ago class-settings.php 4 years ago class-update.php 4 years ago class-widgets.php 4 years ago functions.php 4 years ago
class-update.php
128 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Post_Views_Counter_Update class.
8 *
9 * @class Post_Views_Counter_Update
10 */
11 class Post_Views_Counter_Update {
12
13 /**
14 * Class constructor.
15 *
16 * @return void
17 */
18 public function __construct() {
19 // actions
20 add_action( 'init', array( $this, 'check_update' ) );
21 }
22
23 /**
24 * Check if there's a database update required.
25 *
26 * @return void
27 */
28 public function check_update() {
29 if ( ! current_user_can( 'manage_options' ) )
30 return;
31
32 // get current database version
33 $current_db_version = get_option( 'post_views_counter_version', '1.0.0' );
34
35 // update 1.2.4+
36 if ( version_compare( $current_db_version, '1.2.4', '<=' ) ) {
37 $general = Post_Views_Counter()->options['general'];
38
39 if ( $general['reset_counts']['number'] > 0 ) {
40 // unsupported data reset in minutes/hours
41 if ( in_array( $general['reset_counts']['type'], array( 'minutes', 'hours' ), true ) ) {
42 // set type to date
43 $general['reset_counts']['type'] = 'days';
44
45 // new number of days
46 if ( $general['reset_counts']['type'] === 'minutes' )
47 $general['reset_counts']['number'] = $general['reset_counts']['number'] * 60;
48 else
49 $general['reset_counts']['number'] = $general['reset_counts']['number'] * 3600;
50
51 // how many days?
52 $general['reset_counts']['number'] = (int) round( ceil( $general['reset_counts']['number'] / 86400 ) );
53
54 // force cron to update
55 $general['cron_run'] = true;
56 $general['cron_update'] = true;
57
58 // update settings
59 update_option( 'post_views_counter_settings_general', $general );
60
61 // update general options
62 Post_Views_Counter()->options['general'] = $general;
63 }
64
65 // update cron job for all users
66 Post_Views_Counter()->cron->check_cron();
67 }
68 }
69
70 if ( isset( $_POST['post_view_counter_update'], $_POST['post_view_counter_number'] ) ) {
71 if ( $_POST['post_view_counter_number'] === 'update_1' ) {
72 $this->update_1();
73
74 // update plugin version
75 update_option( 'post_views_counter_version', Post_Views_Counter()->defaults['version'], false );
76 }
77 }
78
79 $update_1_html = '
80 <form action="" method="post">
81 <input type="hidden" name="post_view_counter_number" value="update_1"/>
82 <p>' . __( '<strong>Post Views Counter</strong> - this version requires a database update. Make sure to back up your database first.', 'post-views-counter' ) . '</p>
83 <p><input type="submit" class="button button-primary" name="post_view_counter_update" value="' . __( 'Run the Update', 'post-views-counter' ) . '"/></p>
84 </form>';
85
86 // get current database version
87 $current_db_version = get_option( 'post_views_counter_version', '1.0.0' );
88
89 // new version?
90 if ( version_compare( $current_db_version, Post_Views_Counter()->defaults['version'], '<' ) ) {
91 // is update 1 required?
92 if ( version_compare( $current_db_version, '1.2.4', '<=' ) )
93 Post_Views_Counter()->add_notice( $update_1_html, 'notice notice-info' );
94 else
95 // update plugin version
96 update_option( 'post_views_counter_version', Post_Views_Counter()->defaults['version'], false );
97 }
98 }
99
100 /**
101 * Database update for 1.2.4 and below.
102 *
103 * @return void
104 */
105 public function update_1() {
106 global $wpdb;
107
108 // get index
109 $old_index = $wpdb->query( "SHOW INDEX FROM `" . $wpdb->prefix . "post_views` WHERE Key_name = 'id_period'" );
110
111 // check whether index already exists
112 if ( $old_index > 0 ) {
113 // drop unwanted index which prevented saving views with indentical weeks and months
114 $wpdb->query( "ALTER TABLE `" . $wpdb->prefix . "post_views` DROP INDEX id_period" );
115 }
116
117 // get index
118 $new_index = $wpdb->query( "SHOW INDEX FROM `" . $wpdb->prefix . "post_views` WHERE Key_name = 'id_type_period_count'" );
119
120 // check whether index already exists
121 if ( $new_index === 0 ) {
122 // create new index for better performance of SQL queries
123 $wpdb->query( 'ALTER TABLE `' . $wpdb->prefix . 'post_views` ADD UNIQUE INDEX `id_type_period_count` (`id`, `type`, `period`, `count`) USING BTREE' );
124 }
125
126 Post_Views_Counter()->add_notice( __( 'Thank you! Datebase was succesfully updated.', 'post-views-counter' ), 'updated', true );
127 }
128 }