010009.php
7 months ago
010300.php
7 months ago
010306.php
7 months ago
010309.php
7 months ago
010402.php
7 months ago
010501.php
3 months ago
010802.php
7 months ago
010803.php
3 months ago
index.php
3 years ago
010306.php
110 lines
| 1 | <?php #comp-page builds: premium |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Updates for altering the table used to store statistics data. |
| 10 | * Adds new columns and renames existing ones in order to add support for the new social buttons. |
| 11 | */ |
| 12 | class WIOUpdate010306 extends Wbcr_Factory600_Update { |
| 13 | |
| 14 | /** |
| 15 | * {inherit} |
| 16 | * |
| 17 | * @since 1.3.6 |
| 18 | */ |
| 19 | public function install() { |
| 20 | |
| 21 | $db_version = RIO_Process_Queue::get_db_version(); |
| 22 | $plugin_version_in_db = $this->get_plugin_version_in_db(); |
| 23 | $current_plugin_version = $this->plugin->getPluginVersion(); |
| 24 | |
| 25 | $init_log_message = "Start plugin migration < %s.\r\n"; |
| 26 | $init_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-DB Version: {$db_version}\r\n"; |
| 27 | $init_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-Plugin Version in DB: {$plugin_version_in_db}\r\n"; |
| 28 | $init_log_message .= "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t-Current Plugin Version: {$current_plugin_version}"; |
| 29 | |
| 30 | WRIO_Plugin::app()->logger->info( sprintf( $init_log_message, '1.3.6' ) ); |
| 31 | |
| 32 | $this->clear_webp_images(); |
| 33 | |
| 34 | WBCR\Factory_Templates_759\Helpers::flushPageCache(); |
| 35 | |
| 36 | WRIO_Plugin::app()->logger->info( 'Plugin migration was successfull!' ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get previous plugin version |
| 41 | * |
| 42 | * @since 1.3.8 |
| 43 | * @return number |
| 44 | */ |
| 45 | public function get_plugin_version_in_db() { |
| 46 | if ( WRIO_Plugin::app()->isNetworkActive() ) { |
| 47 | return get_site_option( WRIO_Plugin::app()->getOptionName( 'plugin_version' ), 0 ); |
| 48 | } |
| 49 | |
| 50 | return get_option( WRIO_Plugin::app()->getOptionName( 'plugin_version' ), 0 ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @since 1.3.6 |
| 55 | * @see RIO_Process_Queue::fix_table_collation |
| 56 | */ |
| 57 | public function fix_table_collation() { |
| 58 | RIO_Process_Queue::fix_table_collation(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * This removes webp queue items from in the database. For compatibility with the new |
| 63 | * version, it will be better to remove them, so that the user can start converting |
| 64 | * and have no compatibility problems. |
| 65 | * |
| 66 | * @since 1.3.6 |
| 67 | */ |
| 68 | public function clear_webp_queue_items() { |
| 69 | global $wpdb; |
| 70 | |
| 71 | $table_name = RIO_Process_Queue::table_name(); |
| 72 | $wpdb->query( "DELETE FROM {$table_name} WHERE item_type='webp'" ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * We are removing Webp dir, since the migration will be very difficult. The previous |
| 77 | * version of the plugin has serious problems in the design of webp image convertation. |
| 78 | * |
| 79 | * @since 1.3.6 |
| 80 | * @return bool |
| 81 | */ |
| 82 | public function clear_webp_images() { |
| 83 | |
| 84 | require_once( WRIO_PLUGIN_DIR . '/includes/functions.php' ); |
| 85 | |
| 86 | $upload_dirs = wp_upload_dir(); |
| 87 | |
| 88 | if ( isset( $upload_dirs['error'] ) && $upload_dirs['error'] !== false ) { |
| 89 | WRIO_Plugin::app()->logger->error( sprintf( 'Plugin migration error: %s', $upload_dirs['error'] ) ); |
| 90 | |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | $content_path = $upload_dirs['basedir']; |
| 95 | |
| 96 | $dir_path = wp_normalize_path( trailingslashit( $content_path ) . 'wrio-webp-uploads' ); |
| 97 | |
| 98 | if ( file_exists( $dir_path ) ) { |
| 99 | $this->clear_webp_queue_items(); |
| 100 | $this->plugin->updatePopulateOption( 'cleared_webp_images', 1 ); |
| 101 | |
| 102 | wrio_rmdir( $dir_path ); |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 |