Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/upgrade.tar
Назад
upgrades.php 0000644 00000102330 14720516071 0007071 0 ustar 00 <?php namespace ElementorPro\Core\Upgrade; use Elementor\Core\Base\Document; use Elementor\Core\Upgrade\Updater; use Elementor\Icons_Manager; use Elementor\Core\Upgrade\Upgrades as Core_Upgrades; use ElementorPro\License\API; use ElementorPro\Plugin; use Elementor\Modules\History\Revisions_Manager; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Upgrades { public static $typography_control_names = [ 'typography', // The popover toggle ('starter_name'). 'font_family', 'font_size', 'font_weight', 'text_transform', 'font_style', 'text_decoration', 'line_height', 'letter_spacing', ]; public static function _on_each_version( $updater ) { self::_remove_remote_info_api_data(); } public static function _v_1_3_0() { global $wpdb; // Fix Button widget to new sizes options $post_ids = $wpdb->get_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"form"%\';' ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $document = Plugin::elementor()->documents->get( $post_id ); if ( $document ) { $data = $document->get_elements_data(); } if ( empty( $data ) ) { continue; } $data = Plugin::elementor()->db->iterate_data( $data, function( $element ) { if ( empty( $element['widgetType'] ) || 'form' !== $element['widgetType'] ) { return $element; } if ( ! isset( $element['settings']['submit_actions'] ) ) { $element['settings']['submit_actions'] = [ 'email' ]; } if ( ! empty( $element['settings']['redirect_to'] ) ) { if ( ! in_array( 'redirect', $element['settings']['submit_actions'] ) ) { $element['settings']['submit_actions'][] = 'redirect'; } } if ( ! empty( $element['settings']['webhooks'] ) ) { if ( ! in_array( 'webhook', $element['settings']['submit_actions'] ) ) { $element['settings']['submit_actions'][] = 'webhook'; } } return $element; } ); self::save_editor( $post_id, $data ); } } public static function _v_1_4_0() { global $wpdb; // Move all posts columns to classic skin (Just add prefix) $post_ids = $wpdb->get_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"posts"%\';' ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $document = Plugin::elementor()->documents->get( $post_id ); if ( $document ) { $data = $document->get_elements_data(); } if ( empty( $data ) ) { continue; } $data = Plugin::elementor()->db->iterate_data( $data, function( $element ) { if ( empty( $element['widgetType'] ) || 'posts' !== $element['widgetType'] ) { return $element; } $fields_to_change = [ 'columns', 'columns_mobile', 'columns_tablet', ]; foreach ( $fields_to_change as $field ) { // TODO: Remove old value later $new_field_key = 'classic_' . $field; if ( isset( $element['settings'][ $field ] ) && ! isset( $element['settings'][ $new_field_key ] ) ) { $element['settings'][ $new_field_key ] = $element['settings'][ $field ]; } } return $element; } ); $document = Plugin::elementor()->documents->get( $post_id ); $document->save( [ 'elements' => $data, ] ); } } public static function _v_1_12_0() { global $wpdb; // Set `mailchimp_api_key_source` to `custom`. $post_ids = $wpdb->get_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"form"%\';' ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $do_update = false; $document = Plugin::elementor()->documents->get( $post_id ); if ( $document ) { $data = $document->get_elements_data(); } if ( empty( $data ) ) { continue; } $data = Plugin::elementor()->db->iterate_data( $data, function( $element ) use ( &$do_update ) { if ( empty( $element['widgetType'] ) || 'form' !== $element['widgetType'] ) { return $element; } if ( ! empty( $element['settings']['mailchimp_api_key'] ) && ! isset( $element['settings']['mailchimp_api_key_source'] ) ) { $element['settings']['mailchimp_api_key_source'] = 'custom'; $do_update = true; } return $element; } ); // Only update if form has mailchimp if ( ! $do_update ) { continue; } // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` $json_value = wp_slash( wp_json_encode( $data ) ); update_metadata( 'post', $post_id, '_elementor_data', $json_value ); } } /** * Replace 'sticky' => 'yes' with 'sticky' => 'top' in sections. */ public static function _v_2_0_3() { global $wpdb; $post_ids = $wpdb->get_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"sticky":"yes"%\';' ); if ( empty( $post_ids ) ) { return; } foreach ( $post_ids as $post_id ) { $do_update = false; $document = Plugin::elementor()->documents->get( $post_id ); if ( ! $document ) { continue; } $data = $document->get_elements_data(); if ( empty( $data ) ) { continue; } $data = Plugin::elementor()->db->iterate_data( $data, function( $element ) use ( &$do_update ) { if ( empty( $element['elType'] ) || 'section' !== $element['elType'] ) { return $element; } if ( ! empty( $element['settings']['sticky'] ) && 'yes' === $element['settings']['sticky'] ) { $element['settings']['sticky'] = 'top'; $do_update = true; } return $element; } ); if ( ! $do_update ) { continue; } // We need the `wp_slash` in order to avoid the unslashing during the `update_metadata` $json_value = wp_slash( wp_json_encode( $data ) ); update_metadata( 'post', $post_id, '_elementor_data', $json_value ); } // End foreach(). } private static function save_editor( $post_id, $posted ) { // Change the global post to current library post, so widgets can use `get_the_ID` and other post data if ( isset( $GLOBALS['post'] ) ) { $global_post = $GLOBALS['post']; } $GLOBALS['post'] = get_post( $post_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $editor_data = self::get_editor_data( $posted ); // We need the `wp_slash` in order to avoid the unslashing during the `update_post_meta` $json_value = wp_slash( wp_json_encode( $editor_data ) ); $is_meta_updated = update_metadata( 'post', $post_id, '_elementor_data', $json_value ); if ( $is_meta_updated ) { Revisions_Manager::handle_revision(); } // Restore global post if ( isset( $global_post ) ) { $GLOBALS['post'] = $global_post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited } else { unset( $GLOBALS['post'] ); } /** * After editor saves data. * * Fires after Elementor editor data was saved. * * @since 1.0.0 * * @param int $post_id The ID of the post. * @param array $editor_data The editor data. */ do_action( 'elementor/editor/after_save', $post_id, $editor_data ); } private static function get_editor_data( $data, $with_html_content = false ) { $editor_data = []; foreach ( $data as $element_data ) { $element = Plugin::elementor()->elements_manager->create_element_instance( $element_data ); if ( ! $element ) { continue; } $editor_data[] = $element->get_raw_data( $with_html_content ); } // End Section return $editor_data; } public static function _v_2_5_0_form( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_repeater_settings' ], 'control_ids' => [ 'form_fields' => [ '_id' => 'custom_id', ], ], ], ]; return self::_update_widget_settings( 'form', $updater, $changes ); } public static function _v_2_5_0_woocommerce_menu_cart( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings' ], 'control_ids' => [ 'checkout_button_border_color' => 'checkout_border_color', 'view_cart_button_border_color' => 'view_cart_border_color', ], ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_slider_to_border_settings' ], 'control_ids' => [ 'checkout_button_border_width' => [ 'new' => 'checkout_border_width', 'add' => 'checkout_border_border', ], 'view_cart_button_border_width' => [ 'new' => 'view_cart_border_width', 'add' => 'view_cart_border_border', ], ], ], ]; return self::_update_widget_settings( 'woocommerce-menu-cart', $updater, $changes ); } public static function _v_3_7_2_woocommerce_rename_related_to_related_products( $updater ) { $changes = self::get_woocommerce_rename_related_to_related_products_changes(); return self::_update_widget_settings( 'woocommerce-products', $updater, $changes ); } public static function _slider_to_border_settings( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } foreach ( $changes as $old => $new ) { if ( ! empty( $element['settings'][ $old ] ) && ! isset( $element['settings'][ $new['new'] ] ) ) { $new_border_width = [ 'unit' => $element['settings'][ $old ]['unit'], 'top' => $element['settings'][ $old ]['size'], 'bottom' => $element['settings'][ $old ]['size'], 'left' => $element['settings'][ $old ]['size'], 'right' => $element['settings'][ $old ]['size'], 'isLinked' => true, ]; $element['settings'][ $new ['new'] ] = $new_border_width; $element['settings'][ $new ['add'] ] = 'solid'; $args['do_update'] = true; } } return $element; } /** * @param $element * @param $args * * @return mixed */ public static function _rename_repeater_settings( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } foreach ( $changes as $change_key => $change ) { foreach ( $change as $old => $new ) { foreach ( $element['settings'][ $change_key ] as &$repeater ) { if ( ! empty( $repeater[ $old ] ) && ! isset( $repeater[ $new ] ) ) { $repeater[ $new ] = $repeater[ $old ]; $args['do_update'] = true; } } } } return $element; } private static function taxonomies_mapping( $prefix, $map_to ) { $taxonomy_filter_args = [ 'show_in_nav_menus' => true, ]; $taxonomies = get_taxonomies( $taxonomy_filter_args ); $mapping = []; foreach ( $taxonomies as $taxonomy ) { $mapping[ $prefix . $taxonomy . '_ids' ] = $map_to; } return $mapping; } public static function _v_2_5_0_posts( $updater ) { $add_taxonomies = self::taxonomies_mapping( 'posts_', [ 'posts_include' => 'terms' ] ); $merge_taxonomies = self::taxonomies_mapping( 'posts_', 'posts_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings' ], 'control_ids' => [ 'orderby' => 'posts_orderby', 'order' => 'posts_order', 'offset' => 'posts_offset', 'exclude' => 'posts_exclude', 'exclude_ids' => 'posts_exclude_ids', 'posts_query_id' => 'posts_posts_query_id', 'avoid_duplicates' => 'posts_avoid_duplicates', 'posts_authors' => 'posts_include_authors', ], ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_add_widget_settings_to_array' ], 'control_ids' => array_merge( $add_taxonomies, [ 'posts_authors' => [ 'posts_include' => 'authors' ], ] ), ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_merge_widget_settings' ], 'control_ids' => $merge_taxonomies, ], ]; return self::_update_widget_settings( 'posts', $updater, $changes ); } public static function _v_2_5_0_portfolio( $updater ) { $add_taxonomies = self::taxonomies_mapping( 'posts_', [ 'posts_include' => 'terms' ] ); $merge_taxonomies = self::taxonomies_mapping( 'posts_', 'posts_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings' ], 'control_ids' => [ 'orderby' => 'posts_orderby', 'order' => 'posts_order', 'offset' => 'posts_offset', 'exclude' => 'posts_exclude', 'exclude_ids' => 'posts_exclude_ids', 'posts_query_id' => 'posts_posts_query_id', 'avoid_duplicates' => 'posts_avoid_duplicates', 'posts_authors' => 'posts_include_authors', ], ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_add_widget_settings_to_array' ], 'control_ids' => array_merge( $add_taxonomies, [ 'posts_authors' => [ 'posts_include' => 'authors' ], ] ), ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_merge_widget_settings' ], 'control_ids' => $merge_taxonomies, ], ]; return self::_update_widget_settings( 'portfolio', $updater, $changes ); } public static function _v_2_5_0_products( $updater ) { $add_taxonomies = self::taxonomies_mapping( 'query_', [ 'query_include' => 'terms' ] ); $merge_taxonomies = self::taxonomies_mapping( 'query_', 'query_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings' ], 'control_ids' => [ 'orderby' => 'query_orderby', 'order' => 'query_order', 'exclude' => 'query_exclude', 'exclude_ids' => 'query_exclude_ids', 'query_authors' => 'query_include_authors', 'query_product_tag_ids' => 'query_include_term_ids', 'query_product_cat_ids' => 'query_include_term_ids', ], ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_add_widget_settings_to_array' ], 'control_ids' => array_merge( $add_taxonomies, [ 'query_authors' => [ 'query_include' => 'authors' ], ] ), ], [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_merge_widget_settings' ], 'control_ids' => $merge_taxonomies, ], ]; return self::_update_widget_settings( 'woocommerce-products', $updater, $changes ); } /** * @param $updater * * @return bool Should run again. */ public static function _v_2_5_0_sitemap( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings' ], 'control_ids' => [ 'exclude' => 'sitemap_exclude', 'exclude_ids' => 'sitemap_exclude_ids', ], ], ]; return self::_update_widget_settings( 'sitemap', $updater, $changes ); } /** * @param Updater $updater * * @return bool */ public static function _v_2_5_0_popup_border_radius( $updater ) { global $wpdb; $post_ids = $updater->query_col( "SELECT pm1.post_id FROM {$wpdb->postmeta} AS pm1 LEFT JOIN {$wpdb->postmeta} AS pm2 ON (pm1.post_id = pm2.post_id) WHERE pm1.meta_key = '_elementor_template_type' AND pm1.meta_value = 'popup' AND pm2.`meta_key` = '" . Document::PAGE_META_KEY . "' AND pm2.`meta_value` LIKE '%border_radius%';" ); if ( empty( $post_ids ) ) { return false; } foreach ( $post_ids as $post_id ) { // Clear WP cache for next step. $document = Plugin::elementor()->documents->get( $post_id ); if ( ! $document ) { continue; } $page_settings = $document->get_settings(); // Check if there isn't 'border_radius' setting or if it has already been upgraded if ( empty( $page_settings['border_radius']['size'] ) ) { continue; } $border_radius = $page_settings['border_radius']; $new_border_radius = [ 'unit' => $border_radius['unit'], 'top' => $border_radius['size'], 'bottom' => $border_radius['size'], 'left' => $border_radius['size'], 'right' => $border_radius['size'], 'isLinked' => true, ]; $page_settings['border_radius'] = $new_border_radius; // TODO: `$document->update_settings`. $document->update_meta( Document::PAGE_META_KEY, $page_settings ); wp_cache_flush(); } // End foreach(). return $updater->should_run_again( $post_ids ); } public static function _v_2_5_4_posts( $updater ) { $merge_taxonomies = self::taxonomies_mapping( 'posts_', 'posts_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_term_id_to_term_taxonomy_id' ], 'control_ids' => $merge_taxonomies, 'prefix' => 'posts_', 'new_id' => 'include_term_ids', ], ]; return self::_update_widget_settings( 'posts', $updater, $changes ); } public static function _v_2_5_4_portfolio( $updater ) { $merge_taxonomies = self::taxonomies_mapping( 'posts_', 'posts_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_term_id_to_term_taxonomy_id' ], 'control_ids' => $merge_taxonomies, 'prefix' => 'posts_', 'new_id' => 'include_term_ids', ], ]; return self::_update_widget_settings( 'portfolio', $updater, $changes ); } public static function _v_2_5_4_products( $updater ) { $merge_taxonomies = self::taxonomies_mapping( 'query_', 'query_include_term_ids' ); $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_term_id_to_term_taxonomy_id' ], 'control_ids' => $merge_taxonomies, 'prefix' => 'query_', 'new_id' => 'include_term_ids', ], ]; return self::_update_widget_settings( 'woocommerce-products', $updater, $changes ); } public static function _v_2_5_4_form( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_missing_form_custom_id_settings' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'form', $updater, $changes ); } public static function _v_3_1_0_media_carousel( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_progress_to_progressbar' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'media-carousel', $updater, $changes ); } public static function _v_3_1_0_reviews( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_progress_to_progressbar' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'reviews', $updater, $changes ); } public static function _v_3_1_0_testimonial_carousel( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_convert_progress_to_progressbar' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'testimonial-carousel', $updater, $changes ); } public static function _v_3_1_0_slides( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_migrate_slides_button_color_settings' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'slides', $updater, $changes ); } public static function _v_3_3_0_nav_menu_icon( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_migrate_indicator_control_to_submenu_icon' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'nav-menu', $updater, $changes ); } public static function _v_3_3_0_recalc_usage_data( $updater ) { return Core_Upgrades::recalc_usage_data( $updater ); } public static function _v_3_5_0_price_list( $updater ) { $changes = [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_copy_title_styles_to_new_price_controls' ], 'control_ids' => [], ], ]; return self::_update_widget_settings( 'price-list', $updater, $changes ); } /** * $changes is an array of arrays in the following format: * [ * 'control_ids' => array of control ids * 'callback' => user callback to manipulate the control_ids * ] * * @param $widget_id * @param $updater * @param array $changes * * @return bool */ public static function _update_widget_settings( $widget_id, $updater, $changes ) { global $wpdb; $post_ids = $updater->query_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"' . $widget_id . '"%\';' ); if ( empty( $post_ids ) ) { return false; } foreach ( $post_ids as $post_id ) { $do_update = false; $document = Plugin::elementor()->documents->get( $post_id ); if ( ! $document ) { continue; } $data = $document->get_elements_data(); if ( empty( $data ) ) { continue; } // loop through callbacks & array foreach ( $changes as $change ) { $args = [ 'do_update' => &$do_update, 'widget_id' => $widget_id, 'control_ids' => $change['control_ids'], ]; if ( isset( $change['prefix'] ) ) { $args['prefix'] = $change['prefix']; $args['new_id'] = $change['new_id']; } $data = Plugin::elementor()->db->iterate_data( $data, $change['callback'], $args ); if ( ! $do_update ) { continue; } // We need the `wp_slash` in order to avoid the unslashing during the `update_metadata` $json_value = wp_slash( wp_json_encode( $data ) ); update_metadata( 'post', $post_id, '_elementor_data', $json_value ); } } // End foreach(). return $updater->should_run_again( $post_ids ); } /** * @param $element * @param $args * * @return mixed */ public static function _rename_widget_settings( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } foreach ( $changes as $old => $new ) { if ( ! empty( $element['settings'][ $old ] ) && ! isset( $element['settings'][ $new ] ) ) { $element['settings'][ $new ] = $element['settings'][ $old ]; $args['do_update'] = true; } } return $element; } /** * @param $element * @param $args * * @return mixed */ public static function _rename_widget_settings_value( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( self::is_widget_matched( $element, $widget_id ) ) { $element = self::apply_rename( $changes, $element, $args ); } return $element; } /** * @param $element * @param $args * * @return mixed */ public static function _add_widget_settings_to_array( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } foreach ( $changes as $old_key => $added_key ) { if ( ! empty( $element['settings'][ $old_key ] ) ) { foreach ( $added_key as $control_id => $val ) { if ( ! in_array( $val, $element['settings'][ $control_id ], true ) ) { $element['settings'][ $control_id ][] = $val; $args['do_update'] = true; } } } } return $element; } /** * @param $element * @param $args * * @return mixed */ public static function _merge_widget_settings( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } foreach ( $changes as $old => $new ) { if ( ! empty( $element['settings'][ $old ] ) ) { if ( ! isset( $element['settings'][ $new ] ) ) { $element['settings'][ $new ] = $element['settings'][ $old ]; } else { $element['settings'][ $new ] = array_unique( array_merge( $element['settings'][ $old ], $element['settings'][ $new ] ) ); } $args['do_update'] = true; } } return $element; } /** * Possible scenarios: * 1) custom_id is not empty --> do nothing * 2) Existing _id: Empty or Missing custom_id --> create custom_id and set the value to the value of _id * 3) Missing _id: Empty or Missing custom_id --> generate a unique key and set it as custom_id value * @param $element * @param $args * * @return mixed */ public static function _missing_form_custom_id_settings( $element, $args ) { $widget_id = $args['widget_id']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } $random_id = (int) substr( time(), -5 ); //form_fields loop: foreach ( $element['settings']['form_fields'] as &$repeater_item ) { if ( ! empty( $repeater_item['custom_id'] ) ) { // Scenario 1 continue; } if ( ! empty( $repeater_item['_id'] ) ) { // Scenario 2 $repeater_item['custom_id'] = $repeater_item['_id']; } else { // Scenario 3 $repeater_item['custom_id'] = 'field_' . $random_id; $random_id++; } $args['do_update'] = true; } return $element; } /** * Migrates the value saved for the 'indicator' SELECT control in the Nav Menu Widget to the new replacement * 'submenu_icon' ICONS control. * * @param $element * @param $args * * @return mixed; */ public static function _migrate_indicator_control_to_submenu_icon( $element, $args ) { $widget_id = $args['widget_id']; // If the current element is not a Nav Menu widget, go to the next one. if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } // If this Nav Menu widget's 'indicator' control value is the default one (there is no value in the DB), // there is nothing to migrate, since the default icon is identical in the new control. Go to the next element. if ( ! isset( $element['settings']['indicator'] ) ) { return $element; } $new_value = ''; $new_library = 'fa-solid'; switch ( $element['settings']['indicator'] ) { case 'none': $new_library = ''; break; case 'classic': $new_value = 'fa-caret-down'; break; case 'chevron': $new_value = 'fa-chevron-down'; break; case 'angle': $new_value = 'fa-angle-down'; break; case 'plus': $new_value = 'e-plus-icon'; $new_library = ''; break; } // This is done in order to make sure that the menu will not look any different for users who upgrade. // The 'None' option should be completely empty. if ( $new_value ) { if ( Icons_Manager::is_migration_allowed() ) { // If the site has been migrated to FA5, add the new FA Solid class. $new_value = 'fas ' . $new_value; } else { // If the site has not been migrated, add the old generic 'fa' class. $new_value = 'fa ' . $new_value; } } // Set the migrated value for the new control. $element['settings']['submenu_icon'] = [ 'value' => $new_value, 'library' => $new_library, ]; $args['do_update'] = true; return $element; } /** * @param $element * @param $args * * @return mixed */ public static function _convert_term_id_to_term_taxonomy_id( $element, $args ) { $widget_id = $args['widget_id']; $changes = $args['control_ids']; $prefix = $args['prefix']; $new_id = $prefix . $args['new_id']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } // Exit if new is empty (should not happen) if ( empty( $element['settings'][ $new_id ] ) ) { return $element; } // 1) Convert each term-id to the equivalent term_taxonomy_id $term_taxonomy_ids = []; $old_term_ids = []; foreach ( $changes as $old => $new ) { if ( ! empty( $element['settings'][ $old ] ) ) { $start = strlen( $prefix ); $end = -strlen( '_ids' ); $taxonomy = substr( $old, $start, $end ); foreach ( $element['settings'][ $old ] as $term_id ) { $old_term_ids[] = $term_id; $term_obj = get_term( $term_id, $taxonomy, OBJECT ); if ( $term_obj && ! is_wp_error( $term_obj ) ) { $term_taxonomy_ids[] = $term_obj->term_taxonomy_id; } } } } // 2) Check if the widget's settings were changed after the u/g to 2.5.0 $diff = array_diff( $element['settings'][ $new_id ], array_unique( $old_term_ids ) ); if ( empty( $diff ) ) { // Nothing was changed $element['settings'][ $new_id . '_backup' ] = $element['settings'][ $new_id ]; $element['settings'][ $new_id ] = $term_taxonomy_ids; $args['do_update'] = true; } return $element; } /** * Convert 'progress' to 'progressbar' * * Before Elementor 2.2.0, the progress bar option key was 'progress'. In Elementor 2.2.0, * it was changed to 'progressbar'. This upgrade script migrated the DB data for old websites using 'progress'. * * @param $element * @param $args * @return mixed */ public static function _convert_progress_to_progressbar( $element, $args ) { $widget_id = $args['widget_id']; if ( empty( $element['widgetType'] ) || $widget_id !== $element['widgetType'] ) { return $element; } if ( 'progress' === $element['settings']['pagination'] ) { $element['settings']['pagination'] = 'progressbar'; $args['do_update'] = true; } return $element; } /** * Migrate Slides Button Color Settings * * Move Slides Widget's 'button_color' settings to 'button_text_color' and 'button_border_color' as necessary, * to allow for removing the redundant control. * * @param $element * @param $args * @return mixed */ public static function _migrate_slides_button_color_settings( $element, $args ) { if ( empty( $element['widgetType'] ) || $args['widget_id'] !== $element['widgetType'] ) { return $element; } // If the element doesn't use the 'button_color' control, no need to do anything. if ( ! isset( $element['settings']['button_color'] ) ) { return $element; } // Check if button_text_color is set. If it is not set, transfer the value from button_color to button_text_color. if ( ! isset( $element['settings']['button_text_color'] ) ) { $element['settings']['button_text_color'] = $element['settings']['button_color']; $args['do_update'] = true; } // Check if button_border_color is set. If it is not set, transfer the value from button_color to button_border_color. if ( ! isset( $element['settings']['button_border_color'] ) ) { $element['settings']['button_border_color'] = $element['settings']['button_color']; $args['do_update'] = true; } return $element; } /** * Copy Title Styles to New Price Controls * * Copy the values from the Price List widget's Title Style controls to new Price Style controls. * * @param $element * @param $args * @return mixed * @since 3.4.0 * */ public static function _copy_title_styles_to_new_price_controls( $element, $args ) { if ( empty( $element['widgetType'] ) || $args['widget_id'] !== $element['widgetType'] ) { return $element; } if ( ! empty( $element['settings']['heading_color'] ) ) { $element['settings']['price_color'] = $element['settings']['heading_color']; $args['do_update'] = true; } $old_control_prefix = 'heading_typography_'; $new_control_prefix = 'price_typography_'; foreach ( self::$typography_control_names as $control_name ) { if ( ! empty( $element['settings'][ $old_control_prefix . $control_name ] ) ) { $element['settings'][ $new_control_prefix . $control_name ] = $element['settings'][ $old_control_prefix . $control_name ]; $args['do_update'] = true; } } return $element; } public static function _remove_remote_info_api_data() { global $wpdb; $key = API::TRANSIENT_KEY_PREFIX; return $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '{$key}%';"); // phpcs:ignore } /** * @param $element * @param $to * @param $control_id * @param $args * @return array */ protected static function set_new_value( $element, $to, $control_id, $args ) { $element['settings'][ $control_id ] = $to; $args['do_update'] = true; return $element; } /** * * @param $change * @param array $element * @param $args * @return array */ protected static function replace_value_if_found( $change, array $element, $args ) { $control_id = key( $args['control_ids'] ); $from = $change['from']; $to = $change['to']; if ( self::is_control_exist_in_settings( $element, $control_id ) && self::is_need_to_replace_value( $element, $control_id, $from ) ) { $element = self::set_new_value( $element, $to, $control_id, $args ); } return $element; } /** * @param $element * @param $widget_id * @return bool */ protected static function is_widget_matched( $element, $widget_id ) { return ! empty( $element['widgetType'] ) && $widget_id === $element['widgetType']; } /** * @param $changes * @param $element * @param $args * @return array|mixed */ protected static function apply_rename( $changes, $element, $args ) { foreach ( $changes as $change ) { $element = self::replace_value_if_found( $change, $element, $args ); } return $element; } /** * @param $element * @param $control_id * @return bool */ protected static function is_control_exist_in_settings( $element, $control_id ) { return ! empty( $element['settings'][ $control_id ] ); } /** * @param $element * @param $new * @return bool */ protected static function is_need_to_replace_value( $element, $control_id, $value_to_replace ) { return $element['settings'][ $control_id ] === $value_to_replace; } /** * @return array[] */ public static function get_woocommerce_rename_related_to_related_products_changes() { return [ [ 'callback' => [ 'ElementorPro\Core\Upgrade\Upgrades', '_rename_widget_settings_value' ], 'control_ids' => [ 'query_post_type' => [ 'from' => 'related', 'to' => 'related_products', ], ], ], ]; } } manager.php 0000644 00000001616 14720516071 0006676 0 ustar 00 <?php namespace ElementorPro\Core\Upgrade; use Elementor\Core\Upgrade\Manager as Upgrades_Manager; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Manager extends Upgrades_Manager { public function get_action() { return 'elementor_pro_updater'; } public function get_plugin_name() { return 'elementor-pro'; } public function get_plugin_label() { return esc_html__( 'Elementor Pro', 'elementor-pro' ); } public function get_updater_label() { return esc_html__( 'Elementor Pro Data Updater', 'elementor-pro' ); } public function get_new_version() { return ELEMENTOR_PRO_VERSION; } public function get_version_option_name() { return 'elementor_pro_version'; } public function get_upgrades_class() { return 'ElementorPro\Core\Upgrade\Upgrades'; } public static function get_install_history_meta() { return 'elementor_pro_install_history'; } } class-wpml-media-2-3-0-migration.php 0000644 00000015133 14721520266 0013047 0 ustar 00 <?php class WPML_Media_2_3_0_Migration { const FLAG = 'wpml_media_2_3_migration'; const BATCH_SIZE = 200; const MAX_BATCH_REQUEST_TIME = 5; /** * @var wpdb */ private $wpdb; /** * @var SitePress */ private $sitepress; /** * WPML_Media_2_3_0_Migration constructor. * * @param wpdb $wpdb * @param SitePress $sitepress */ public function __construct( wpdb $wpdb, SitePress $sitepress ) { $this->wpdb = $wpdb; $this->sitepress = $sitepress; } public static function migration_complete() { return WPML_Media::get_setting( self::FLAG ); } private function mark_migration_complete() { return WPML_Media::update_setting( self::FLAG, 1 ); } public function is_required() { if ( $this->wpdb->get_var( "SELECT COUNT(ID) FROM {$this->wpdb->posts} WHERE post_type='attachment'" ) ) { return true; } self::mark_migration_complete(); return false; } public function add_hooks() { add_filter( 'wpml_media_menu_overrides', array( $this, 'override_default_menu' ) ); add_action( 'wp_ajax_wpml_media_2_3_0_upgrade', array( $this, 'run_upgrade' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_js' ) ); } public function override_default_menu( $menu_elements ) { $menu_elements[] = array( $this, 'render_menu' ); return $menu_elements; } public function maybe_show_admin_notice() { if ( is_admin() && ! $this->is_wpml_media_screen() ) { add_action( 'admin_notices', array( $this, 'render_menu' ) ); } } private function is_wpml_media_screen() { return isset( $_GET['page'] ) && $_GET['page'] === 'wpml-media'; } public function enqueue_js() { $wpml_media_url = $this->sitepress->get_wp_api()->constant( 'WPML_MEDIA_URL' ); wp_enqueue_script( 'wpml-media-2-3-0-upgrade', $wpml_media_url . '/res/js/upgrade/upgrade-2-3-0.js', array( 'jquery' ), false, true ); } public function render_menu() { if ( $this->is_wpml_media_screen() ) : ?> <div class="wrap wrap-wpml-media-upgrade"> <h2><?php esc_html_e( 'Upgrade required', 'wpml-media' ); ?></h2> <?php endif; ?> <div class="notice notice-warning" id="wpml-media-2-3-0-update" style="padding-bottom:8px"> <p> <?php printf( esc_html__( 'The %1$sWPML Media%2$s database needs updating. Please run the updater and leave the tab open until it completes.', 'wpml-media' ), '<strong>', '</strong>' ); ?> </p> <input type="button" class="button-primary alignright" value="<?php echo esc_attr_x( 'Update', 'Update button label', 'wpml-media' ); ?>" /> <input type="hidden" name="nonce" value="<?php echo wp_create_nonce( 'wpml-media-2-3-0-update' ); ?>" /> <span class="spinner"></span> <p class="alignleft status description"></p><br clear="all" /> </div> <?php if ( $this->is_wpml_media_screen() ) : ?> </div> <?php endif; } private function reset_new_content_settings() { $wpml_media_settings = get_option( '_wpml_media' ); // reset (will not remove since it's used by WCML) $wpml_media_settings['new_content_settings']['always_translate_media'] = 0; $wpml_media_settings['new_content_settings']['duplicate_media'] = 0; $wpml_media_settings['new_content_settings']['duplicate_featured'] = 0; update_option( '_wpml_media', $wpml_media_settings ); } public function run_upgrade() { if ( isset( $_POST['nonce'] ) && ( $_POST['nonce'] === wp_create_nonce( 'wpml-media-2-3-0-update' ) ) ) { $step = isset( $_POST['step'] ) ? $_POST['step'] : ''; if ( 'reset-new-content-settings' === $step ) { $this->reset_new_content_settings(); wp_send_json_success( array( 'status' => esc_html__( 'Reset new content duplication settings', 'wpml-media' ) ) ); } elseif ( 'migrate-attachments' === $step ) { $offset = isset( $_POST['offset'] ) ? (int) $_POST['offset'] : 0; $batch_size = $this->get_dynamic_batch_size( $_POST ); $left = $this->migrate_attachments( $offset, $batch_size ); if ( $left ) { $status = sprintf( esc_html__( 'Updating attachments translation status: %d remaining.', 'wpml-media' ), $left ); $continue = 1; $offset += $batch_size; } else { $this->mark_migration_complete(); $status = esc_html__( 'Update complete!', 'wpml-media' ); $continue = 0; $offset = 0; } wp_send_json_success( array( 'status' => $status, 'goon' => $continue, 'offset' => $offset, 'timestamp' => microtime( true ), ) ); } else { wp_send_json_error( array( 'error' => 'Invalid step' ) ); } } else { wp_send_json_error( array( 'error' => 'Invalid nonce' ) ); } } private function migrate_attachments( $offset = 0, $batch_size = self::BATCH_SIZE ) { $sql = "SELECT SQL_CALC_FOUND_ROWS p.ID FROM {$this->wpdb->posts} p JOIN {$this->wpdb->prefix}icl_translations t ON t.element_id = p.ID AND p.post_type='attachment' WHERE t.source_language_code IS NULL LIMIT %d, %d"; $sql_prepared = $this->wpdb->prepare( $sql, $offset, $batch_size ); $original_attachments = $this->wpdb->get_results( $sql_prepared ); $total_attachments = $this->wpdb->get_var( 'SELECT FOUND_ROWS() ' ); if ( $original_attachments ) { foreach ( $original_attachments as $attachment ) { $post_element = new WPML_Post_Element( $attachment->ID, $this->sitepress ); $translations = $post_element->get_translations(); $media_file = get_post_meta( $attachment->ID, '_wp_attached_file', true ); foreach ( $translations as $translation ) { if ( (int) $attachment->ID !== $translation->get_id() ) { $media_translation_status = WPML_Media_Translation_Status::NOT_TRANSLATED; $media_file_translation = get_post_meta( $translation->get_id(), '_wp_attached_file', true ); if ( $media_file_translation !== $media_file ) { $media_translation_status = WPML_Media_Translation_Status::TRANSLATED; } update_post_meta( $attachment->ID, WPML_Media_Translation_Status::STATUS_PREFIX . $translation->get_language_code(), $media_translation_status ); } } } } $left = max( 0, $total_attachments - $offset ); return $left; } private function get_dynamic_batch_size( $request ) { $batch_size_factor = isset( $request['batch_size_factor'] ) ? (int) $request['batch_size_factor'] : 1; if ( ! empty( $request['timestamp'] ) ) { $elapsed_time = microtime( true ) - (float) $request['timestamp']; if ( $elapsed_time < self::MAX_BATCH_REQUEST_TIME ) { $batch_size_factor ++; } else { $batch_size_factor = max( 1, $batch_size_factor - 1 ); } } return self::BATCH_SIZE * $batch_size_factor; } } custom-tasks-manager.php 0000644 00000004663 14721544053 0011340 0 ustar 00 <?php namespace Elementor\Core\Upgrade; use Elementor\Core\Base\Background_Task_Manager; use Elementor\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Custom_Tasks_Manager extends Background_Task_Manager { const TASKS_OPTION_KEY = 'elementor_custom_tasks'; const QUERY_LIMIT = 100; public function get_name() { return 'custom-task-manager'; } public function get_action() { return 'custom_task_manger'; } public function get_plugin_name() { return 'elementor'; } public function get_plugin_label() { return esc_html__( 'Elementor', 'elementor' ); } public function get_task_runner_class() { return Task::class; } public function get_query_limit() { return self::QUERY_LIMIT; } protected function start_run() { $custom_tasks_callbacks = $this->get_custom_tasks(); if ( empty( $custom_tasks_callbacks ) ) { return; } $task_runner = $this->get_task_runner(); foreach ( $custom_tasks_callbacks as $callback ) { $task_runner->push_to_queue( [ 'callback' => $callback, ] ); } $this->clear_tasks_requested_to_run(); Plugin::$instance->logger->get_logger()->info( 'Elementor custom task(s) process has been queued.', [ 'meta' => [ $custom_tasks_callbacks ], ] ); $task_runner->save()->dispatch(); } public function get_tasks_class() { return Custom_Tasks::class; } public function get_tasks_requested_to_run() { return get_option( self::TASKS_OPTION_KEY, [] ); } public function clear_tasks_requested_to_run() { return update_option( self::TASKS_OPTION_KEY, [], false ); } public function add_tasks_requested_to_run( $tasks = [] ) { $current_tasks = $this->get_tasks_requested_to_run(); $current_tasks = array_merge( $current_tasks, $tasks ); update_option( self::TASKS_OPTION_KEY, $current_tasks, false ); } private function get_custom_tasks() { $tasks_requested_to_run = $this->get_tasks_requested_to_run(); $tasks_class = $this->get_tasks_class(); $tasks_reflection = new \ReflectionClass( $tasks_class ); $callbacks = []; foreach ( $tasks_reflection->getMethods() as $method ) { $method_name = $method->getName(); if ( in_array( $method_name, $tasks_requested_to_run, true ) ) { $callbacks[] = [ $tasks_class, $method_name ]; } } return $callbacks; } public function __construct() { $task_runner = $this->get_task_runner(); if ( $task_runner->is_running() ) { return; } $this->start_run(); } } task.php 0000644 00000001015 14721544053 0006221 0 ustar 00 <?php namespace Elementor\Core\Upgrade; use Elementor\Core\Base\Background_Task; use Elementor\Core\Base\DB_Upgrades_Manager; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Task extends Background_Task { /** * @var DB_Upgrades_Manager */ protected $manager; protected function format_callback_log( $item ) { return $this->manager->get_plugin_label() . '/Tasks - ' . $item['callback'][1]; } public function set_limit( $limit ) { $this->manager->set_query_limit( $limit ); } } custom-tasks.php 0000644 00000000564 14721544053 0007724 0 ustar 00 <?php namespace Elementor\Core\Upgrade; use Elementor\Tracker; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Custom_Tasks { public static function opt_in_recalculate_usage( $updater ) { return Upgrades::recalc_usage_data( $updater ); } public static function opt_in_send_tracking_data() { Tracker::send_tracking_data( true ); } } upgrade-utils.php 0000644 00000003446 14721544053 0010056 0 ustar 00 <?php namespace Elementor\Core\Upgrade; use Elementor\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Upgrade_Utils { /** * _update_widget_settings * * @param string $widget_id widget type id * @param Updater $updater updater instance * @param array $changes array containing updating control_ids, callback and other data needed by the callback * * @return bool */ public static function _update_widget_settings( $widget_id, $updater, $changes ) { global $wpdb; $post_ids = $updater->query_col( 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` WHERE `meta_key` = "_elementor_data" AND `meta_value` LIKE \'%"widgetType":"' . $widget_id . '"%\';' ); if ( empty( $post_ids ) ) { return false; } foreach ( $post_ids as $post_id ) { $do_update = false; $document = Plugin::instance()->documents->get( $post_id ); if ( ! $document ) { continue; } $data = $document->get_elements_data(); if ( empty( $data ) ) { continue; } // loop thru callbacks & array foreach ( $changes as $change ) { $args = [ 'do_update' => &$do_update, 'widget_id' => $widget_id, 'control_ids' => $change['control_ids'], ]; if ( isset( $change['prefix'] ) ) { $args['prefix'] = $change['prefix']; $args['new_id'] = $change['new_id']; } $data = Plugin::instance()->db->iterate_data( $data, $change['callback'], $args ); if ( ! $do_update ) { continue; } // We need the `wp_slash` in order to avoid the unslashing during the `update_metadata` $json_value = wp_slash( wp_json_encode( $data ) ); update_metadata( 'post', $post_id, '_elementor_data', $json_value ); } } // End foreach(). return $updater->should_run_again( $post_ids ); } } updater.php 0000644 00000000753 14721544053 0006733 0 ustar 00 <?php namespace Elementor\Core\Upgrade; use Elementor\Core\Base\Background_Task; use Elementor\Core\Base\DB_Upgrades_Manager; defined( 'ABSPATH' ) || exit; class Updater extends Background_Task { /** * @var DB_Upgrades_Manager */ protected $manager; protected function format_callback_log( $item ) { return $this->manager->get_plugin_label() . '/Upgrades - ' . $item['callback'][1]; } public function set_limit( $limit ) { $this->manager->set_query_limit( $limit ); } } class-wpml-st-upgrade-migrate-originals.php 0000644 00000012235 14721577153 0015042 0 ustar 00 <?php class WPML_ST_Upgrade_Migrate_Originals implements IWPML_St_Upgrade_Command { /** @var wpdb $wpdb */ private $wpdb; /** @var SitePress sitepress */ private $sitepress; private $translations = array(); private $not_translated = array(); private $active_languages; public function __construct( wpdb $wpdb, SitePress $sitepress ) { $this->wpdb = $wpdb; $this->sitepress = $sitepress; $active_languages = $this->sitepress->get_active_languages(); foreach ( $active_languages as $lang ) { $this->active_languages[] = $lang['code']; } } public static function get_command_id() { return __CLASS__; } public function run() { if ( $this->is_migration_required() ) { if ( current_user_can( 'manage_options' ) ) { $this->sitepress->get_wp_api()->add_action( 'admin_notices', array( $this, 'update_message' ) ); } return false; } else { return true; } } function update_message() { ?> <div id="wpml-st-upgrade-migrate-originals" class="update-nag notice notice-info" style="display:block"> <p> <?php esc_html_e( "WPML needs to update the database. This update will help improve WPML's performance when fetching translated strings.", 'wpml-string-translation' ); ?> <br /><br /> <button class="wpml-st-upgrade-migrate-originals"><?php esc_html_e( 'Update Now', 'wpml-string-translation' ); ?></button> <span class="spinner" style="float: none"></span> </p> <?php wp_nonce_field( 'wpml-st-upgrade-migrate-originals-nonce', 'wpml-st-upgrade-migrate-originals-nonce' ); ?> </div> <div id="wpml-st-upgrade-migrate-originals-complete" class="update-nag notice notice-info" style="display:none"> <p> <?php esc_html_e( 'The database has been updated.', 'wpml-string-translation' ); ?> <br /><br /> <button class="wpml-st-upgrade-migrate-originals-close"><?php esc_html_e( 'Close', 'wpml-string-translation' ); ?></button> </p> <?php wp_nonce_field( 'wpml-st-upgrade-migrate-originals-nonce', 'wpml-st-upgrade-migrate-originals-nonce' ); ?> </div> <script type="text/javascript"> jQuery( function( $ ) { jQuery( '.wpml-st-upgrade-migrate-originals' ).click( function() { jQuery( this ).prop( 'disabled', true ); jQuery( this ).parent().find( '.spinner' ).css( 'visibility', 'visible' ); jQuery.ajax({ url: ajaxurl, type: "POST", data: { action: 'wpml-st-upgrade-migrate-originals', nonce: jQuery( '#wpml-st-upgrade-migrate-originals-nonce' ).val() }, success: function ( response ) { jQuery( '#wpml-st-upgrade-migrate-originals' ).hide(); jQuery( '#wpml-st-upgrade-migrate-originals-complete' ).css( 'display', 'block' ); } }); }); jQuery( '.wpml-st-upgrade-migrate-originals-close' ).click( function() { jQuery( '#wpml-st-upgrade-migrate-originals-complete' ).hide(); }); }); </script> <?php } public function run_ajax() { if ( $this->is_migration_required() ) { $this->get_strings_without_translations(); $this->get_originals_with_translations(); $this->migrate_translations(); } return true; } public function run_frontend() {} private function is_migration_required() { $query = " SELECT id FROM {$this->wpdb->prefix}icl_strings WHERE context LIKE 'plugin %' OR context LIKE 'theme %' LIMIT 1"; $found = $this->wpdb->get_var( $query ); return $found > 0; } private function get_strings_without_translations() { foreach ( $this->active_languages as $lang ) { $res_args = array( $lang, $lang ); $res_query = " SELECT s.value, s.id FROM {$this->wpdb->prefix}icl_strings s WHERE s.id NOT IN ( SELECT st.string_id FROM {$this->wpdb->prefix}icl_string_translations st WHERE st.language=%s ) AND s.language!=%s "; $res_prepare = $this->wpdb->prepare( $res_query, $res_args ); $this->not_translated[ $lang ] = $this->wpdb->get_results( $res_prepare, ARRAY_A ); } } private function get_originals_with_translations() { foreach ( $this->active_languages as $lang ) { $res_args = array( ICL_TM_COMPLETE, $lang ); $res_query = " SELECT st.value AS tra, s.value AS org FROM {$this->wpdb->prefix}icl_strings s LEFT JOIN {$this->wpdb->prefix}icl_string_translations st ON s.id=st.string_id WHERE st.status=%d AND st.language=%s "; $res_prepare = $this->wpdb->prepare( $res_query, $res_args ); $result = $this->wpdb->get_results( $res_prepare, ARRAY_A ); $strings = array(); foreach ( $result as $string ) { $strings[ $string['org'] ] = $string['tra']; } $this->translations[ $lang ] = $strings; } } private function migrate_translations() { foreach ( $this->active_languages as $lang ) { foreach ( $this->not_translated[ $lang ] as $not_translated ) { if ( isset( $this->translations[ $lang ][ $not_translated['value'] ] ) ) { icl_add_string_translation( $not_translated['id'], $lang, $this->translations[ $lang ][ $not_translated['value'] ], ICL_TM_COMPLETE ); break; } } } } } class-wpml-st-upgrade-command-not-found-exception.php 0000644 00000000653 14721577153 0016747 0 ustar 00 <?php class WPML_ST_Upgrade_Command_Not_Found_Exception extends InvalidArgumentException { /** * @param string $class_name * @param int $code * @param Exception $previous */ public function __construct( $class_name, $code = 0, Exception $previous = null ) { $msg = sprintf( 'Class %s is not valid String Translation upgrade strategy', $class_name ); parent::__construct( $msg, $code, $previous ); } } class-wpml-st-upgrade-db-longtext-string-value.php 0000644 00000003163 14721577153 0016272 0 ustar 00 <?php /** * WPML_ST_Upgrade_DB_Longtext_String_Value class file. * * @package wpml-string-translation */ /** * Class WPML_ST_Upgrade_DB_Longtext_String_Value */ class WPML_ST_Upgrade_DB_Longtext_String_Value implements IWPML_St_Upgrade_Command { /** * WP db instance. * * @var wpdb */ private $wpdb; /** * WPML_ST_Upgrade_DB_Longtext_String_Value constructor. * * @param wpdb $wpdb WP db instance. */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } /** * Run upgrade. * * @return bool */ public function run() { $result = true; $table_name = $this->wpdb->prefix . 'icl_strings'; if ( count( (array) $this->wpdb->get_results( "SHOW TABLES LIKE '{$table_name}'" ) ) ) { $sql = " ALTER TABLE {$table_name} MODIFY COLUMN `value` LONGTEXT NOT NULL; "; $result = false !== $this->wpdb->query( $sql ); } $table_name = $this->wpdb->prefix . 'icl_string_translations'; if ( count( (array) $this->wpdb->get_results( "SHOW TABLES LIKE '{$table_name}'" ) ) ) { $sql = " ALTER TABLE {$table_name} MODIFY COLUMN `value` LONGTEXT NULL DEFAULT NULL, MODIFY COLUMN `mo_string` LONGTEXT NULL DEFAULT NULL; "; $result = ( false !== $this->wpdb->query( $sql ) ) && $result; } return $result; } /** * Run upgrade in ajax. * * @return bool */ public function run_ajax() { return $this->run(); } /** * Run upgrade on frontend. * * @return bool */ public function run_frontend() { return $this->run(); } /** * Get command id. * * @return string */ public static function get_command_id() { return __CLASS__; } } class-wpml-st-upgrade.php 0000644 00000012660 14721577153 0011431 0 ustar 00 <?php /** * WPML_ST_Upgrade class file. * * @package wpml-string-translation */ /** * Class WPML_ST_Upgrade */ class WPML_ST_Upgrade { const TRANSIENT_UPGRADE_IN_PROGRESS = 'wpml_st_upgrade_in_progress'; /** * SitePress instance. * * @var SitePress $sitepress */ private $sitepress; /** * Upgrade Command Factory instance. * * @var WPML_ST_Upgrade_Command_Factory */ private $command_factory; /** * Upgrade in progress flag. * * @var bool $upgrade_in_progress */ private $upgrade_in_progress; /** * WPML_ST_Upgrade constructor. * * @param SitePress $sitepress SitePress instance. * @param WPML_ST_Upgrade_Command_Factory|null $command_factory Upgrade Command Factory instance. */ public function __construct( SitePress $sitepress, WPML_ST_Upgrade_Command_Factory $command_factory = null ) { $this->sitepress = $sitepress; $this->command_factory = $command_factory; } /** * Run upgrade. */ public function run() { if ( get_transient( self::TRANSIENT_UPGRADE_IN_PROGRESS ) ) { return; } if ( $this->sitepress->get_wp_api()->is_admin() ) { if ( $this->sitepress->get_wp_api()->constant( 'DOING_AJAX' ) ) { $this->run_ajax(); } else { $this->run_admin(); } } else { $this->run_front_end(); } $this->set_upgrade_completed(); } /** * Run admin. */ private function run_admin() { $this->maybe_run( 'WPML_ST_Upgrade_Migrate_Originals' ); $this->maybe_run( 'WPML_ST_Upgrade_Display_Strings_Scan_Notices' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_String_Packages' ); $this->maybe_run( 'WPML_ST_Upgrade_MO_Scanning' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_String_Name_Index' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_Longtext_String_Value' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_Strings_Add_Translation_Priority_Field' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_String_Packages_Word_Count' ); $this->maybe_run( '\WPML\ST\Upgrade\Command\RegenerateMoFilesWithStringNames' ); $this->maybe_run( \WPML\ST\Upgrade\Command\MigrateMultilingualWidgets::class ); } /** * Run ajax. */ private function run_ajax() { $this->maybe_run_ajax( 'WPML_ST_Upgrade_Migrate_Originals' ); // It has to be maybe_run. $this->maybe_run( 'WPML_ST_Upgrade_MO_Scanning' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_String_Packages_Word_Count' ); } /** * Run on frontend. */ private function run_front_end() { $this->maybe_run( 'WPML_ST_Upgrade_MO_Scanning' ); $this->maybe_run( 'WPML_ST_Upgrade_DB_String_Packages_Word_Count' ); } /** * Maybe run command. * * @param string $class Command class name. */ private function maybe_run( $class ) { if ( ! $this->has_command_been_executed( $class ) ) { $this->set_upgrade_in_progress(); $upgrade = $this->command_factory->create( $class ); if ( $upgrade->run() ) { $this->mark_command_as_executed( $class ); } } } /** * Maybe run command in ajax. * * @param string $class Command class name. */ private function maybe_run_ajax( $class ) { if ( ! $this->has_command_been_executed( $class ) ) { $this->run_ajax_command( $class ); } } /** * Run command in ajax. * * @param string $class Command class name. */ private function run_ajax_command( $class ) { if ( $this->nonce_ok( $class ) ) { $upgrade = $this->command_factory->create( $class ); if ( $upgrade->run_ajax() ) { $this->mark_command_as_executed( $class ); $this->sitepress->get_wp_api()->wp_send_json_success( '' ); } } } /** * Check nonce. * * @param string $class Command class name. * * @return bool */ private function nonce_ok( $class ) { $ok = false; $class = strtolower( $class ); $class = str_replace( '_', '-', $class ); if ( isset( $_POST['action'] ) && $_POST['action'] === $class ) { $nonce = $this->filter_nonce_parameter(); if ( $this->sitepress->get_wp_api()->wp_verify_nonce( $nonce, $class . '-nonce' ) ) { $ok = true; } } return $ok; } /** * Check if command was executed. * * @param string $class Command class name. * * @return bool */ public function has_command_been_executed( $class ) { /** @phpstan-ignore-next-line */ $id = call_user_func( [ $class, 'get_command_id' ] ); $settings = $this->sitepress->get_setting( 'st', [] ); return isset( $settings[ $id . '_has_run' ] ); } /** * Mark command as executed. * * @param string $class Command class name. */ public function mark_command_as_executed( $class ) { /** @phpstan-ignore-next-line */ $id = call_user_func( [ $class, 'get_command_id' ] ); $settings = $this->sitepress->get_setting( 'st', [] ); $settings[ $id . '_has_run' ] = true; $this->sitepress->set_setting( 'st', $settings, true ); wp_cache_flush(); } /** * Filter nonce. * * @return mixed */ protected function filter_nonce_parameter() { return filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); } /** * Set flag that upgrade is in process. */ private function set_upgrade_in_progress() { if ( ! $this->upgrade_in_progress ) { $this->upgrade_in_progress = true; set_transient( self::TRANSIENT_UPGRADE_IN_PROGRESS, true, MINUTE_IN_SECONDS ); } } /** * Mark upgrade as completed. */ private function set_upgrade_completed() { if ( $this->upgrade_in_progress ) { $this->upgrade_in_progress = false; delete_transient( self::TRANSIENT_UPGRADE_IN_PROGRESS ); } } } repair-schema/wpml-st-repair-strings-schema.php 0000644 00000005221 14721577153 0015621 0 ustar 00 <?php class WPML_ST_Repair_Strings_Schema { const OPTION_HAS_RUN = 'wpml_st_repair_string_schema_has_run'; /** @var IWPML_St_Upgrade_Command $upgrade_command */ private $upgrade_command; /** @var WPML_Notices $notices */ private $notices; /** @var array $args */ private $args; /** @var string $db_error */ private $db_error; /** @var array $has_run */ private $has_run = array(); public function __construct( WPML_Notices $notices, array $args, $db_error ) { $this->notices = $notices; $this->args = $args; $this->db_error = $db_error; } public function set_command( IWPML_St_Upgrade_Command $upgrade_command ) { $this->upgrade_command = $upgrade_command; } /** @return bool */ public function run() { $this->has_run = get_option( self::OPTION_HAS_RUN, array() ); if ( ! $this->upgrade_command || array_key_exists( $this->get_command_id(), $this->has_run ) ) { $this->add_notice(); return false; } if ( $this->run_upgrade_command() ) { return true; } $this->add_notice(); return false; } /** @return bool */ private function run_upgrade_command() { if ( ! $this->acquire_lock() ) { return false; } $success = $this->upgrade_command->run(); $this->has_run[ $this->get_command_id() ] = true; update_option( self::OPTION_HAS_RUN, $this->has_run, false ); $this->release_lock(); return (bool) $success; } private function get_command_id() { return get_class( $this->upgrade_command ); } /** @return bool */ private function acquire_lock() { if ( get_transient( WPML_ST_Upgrade::TRANSIENT_UPGRADE_IN_PROGRESS ) ) { return false; } set_transient( WPML_ST_Upgrade::TRANSIENT_UPGRADE_IN_PROGRESS, true, MINUTE_IN_SECONDS ); return true; } private function release_lock() { delete_transient( WPML_ST_Upgrade::TRANSIENT_UPGRADE_IN_PROGRESS ); } private function add_notice() { $text = '<p>' . sprintf( esc_html__( 'We have detected a problem with some tables in the database. Please contact %1$sWPML support%2$s to get this fixed.', 'wpml-string-translation' ), '<a href="https://wpml.org/forums/forum/english-support/" class="otgs-external-link" rel="noopener" target="_blank">', '</a>' ) . '</p>'; $text .= '<pre>' . $this->db_error . '</pre>'; if ( $this->upgrade_command ) { $notice_id = $this->get_command_id(); } else { $notice_id = 'default'; $text .= '<pre>' . print_r( $this->args, true ) . '</pre>'; } $notice = $this->notices->create_notice( $notice_id, $text, __CLASS__ ); $notice->set_hideable( true ); $notice->set_css_class_types( array( 'notice-error' ) ); $this->notices->add_notice( $notice ); } } class-wpml-st-upgrade-db-string-name-index.php 0000644 00000002047 14721577153 0015341 0 ustar 00 <?php class WPML_ST_Upgrade_DB_String_Name_Index implements IWPML_St_Upgrade_Command { /** @var wpdb */ private $wpdb; /** * @param wpdb $wpdb */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } public function run() { $result = true; $table_name = $this->wpdb->prefix . 'icl_strings'; /** @var array<int, object> $results */ $results = $this->wpdb->get_results( "SHOW TABLES LIKE '{$table_name}'" ); if ( 0 !== count( $results ) ) { $sql = "SHOW KEYS FROM {$table_name} WHERE Key_name='icl_strings_name'"; /** @var array<int, object> $results */ $results = $this->wpdb->get_results( $sql ); if ( 0 === count( $results ) ) { $sql = " ALTER TABLE {$this->wpdb->prefix}icl_strings ADD INDEX `icl_strings_name` (`name` ASC); "; $result = false !== $this->wpdb->query( $sql ); } } return $result; } public function run_ajax() { $this->run(); } public function run_frontend() { $this->run(); } public static function get_command_id() { return __CLASS__ . '_2'; } } class-wpml-st-upgrade-string-index.php 0000644 00000001354 14721577153 0014040 0 ustar 00 <?php class WPML_ST_Upgrade_String_Index { /** @var wpdb */ private $wpdb; const OPTION_NAME = 'wpml_string_table_ok_for_mo_import'; /** * @param wpdb $wpdb */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } public function is_uc_domain_name_context_index_unique() { $key_exists = get_option( self::OPTION_NAME ); if ( ! $key_exists ) { $sql = "SHOW KEYS FROM {$this->wpdb->prefix}icl_strings WHERE Key_name='uc_domain_name_context_md5' AND Non_unique = 0"; /** @var array<int, object> $results */ $results = $this->wpdb->get_results( $sql ); $key_exists = 0 < count( $results ) ? 'yes' : 'no'; update_option( self::OPTION_NAME, $key_exists, true ); } return 'yes' === $key_exists; } } class-wpml-st-upgrade-command-factory.php 0000644 00000005475 14721577153 0014520 0 ustar 00 <?php /** * WPML_ST_Upgrade_Command_Factory class file. * * @package wpml-string-translation */ use function WPML\Container\make; use WPML\ST\Upgrade\Command\RegenerateMoFilesWithStringNames; use WPML\ST\Upgrade\Command\MigrateMultilingualWidgets; /** * Class WPML_ST_Upgrade_Command_Factory */ class WPML_ST_Upgrade_Command_Factory { /** * WP db instance. * * @var wpdb wpdb */ private $wpdb; /** * SitePress instance. * * @var SitePress */ private $sitepress; /** * WPML_ST_Upgrade_Command_Factory constructor. * * @param wpdb $wpdb WP db instance. * @param SitePress $sitepress SitePress instance. */ public function __construct( wpdb $wpdb, SitePress $sitepress ) { $this->wpdb = $wpdb; $this->sitepress = $sitepress; } /** * Create upgrade commands. * * @param string $class_name Name of upgrade command class. * * @throws WPML_ST_Upgrade_Command_Not_Found_Exception Exception when command not found. * @return IWPML_St_Upgrade_Command */ public function create( $class_name ) { switch ( $class_name ) { case 'WPML_ST_Upgrade_Migrate_Originals': $result = new WPML_ST_Upgrade_Migrate_Originals( $this->wpdb, $this->sitepress ); break; case 'WPML_ST_Upgrade_Display_Strings_Scan_Notices': $themes_and_plugins_settings = new WPML_ST_Themes_And_Plugins_Settings(); $result = new WPML_ST_Upgrade_Display_Strings_Scan_Notices( $themes_and_plugins_settings ); break; case 'WPML_ST_Upgrade_DB_String_Packages': $result = new WPML_ST_Upgrade_DB_String_Packages( $this->wpdb ); break; case 'WPML_ST_Upgrade_MO_Scanning': $result = new WPML_ST_Upgrade_MO_Scanning( $this->wpdb ); break; case 'WPML_ST_Upgrade_DB_String_Name_Index': $result = new WPML_ST_Upgrade_DB_String_Name_Index( $this->wpdb ); break; case 'WPML_ST_Upgrade_DB_Longtext_String_Value': $result = new WPML_ST_Upgrade_DB_Longtext_String_Value( $this->wpdb ); break; case 'WPML_ST_Upgrade_DB_Strings_Add_Translation_Priority_Field': $result = new WPML_ST_Upgrade_DB_Strings_Add_Translation_Priority_Field( $this->wpdb ); break; case 'WPML_ST_Upgrade_DB_String_Packages_Word_Count': $result = new WPML_ST_Upgrade_DB_String_Packages_Word_Count( wpml_get_upgrade_schema() ); break; case '\WPML\ST\Upgrade\Command\RegenerateMoFilesWithStringNames': $isBackground = true; $result = new RegenerateMoFilesWithStringNames( \WPML\ST\MO\Generate\Process\ProcessFactory::createStatus( $isBackground ), \WPML\ST\MO\Generate\Process\ProcessFactory::createSingle( $isBackground ) ); break; case MigrateMultilingualWidgets::class: $result = new MigrateMultilingualWidgets(); break; default: throw new WPML_ST_Upgrade_Command_Not_Found_Exception( $class_name ); } return $result; } } interface-iwpml_st_upgrade_command.php 0000644 00000000262 14721577153 0014272 0 ustar 00 <?php interface IWPML_St_Upgrade_Command { public function run(); public function run_ajax(); public function run_frontend(); public static function get_command_id(); } class-wpml-st-upgrade-db-strings-add-translation-priority-field.php 0000644 00000003124 14721577153 0021520 0 ustar 00 <?php class WPML_ST_Upgrade_DB_Strings_Add_Translation_Priority_Field implements IWPML_St_Upgrade_Command { /** @var wpdb */ private $wpdb; /** * @param wpdb $wpdb */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } public function run() { $result = null; $table_name = $this->wpdb->prefix . 'icl_strings'; /** @var array<int, object> $results */ $results = $this->wpdb->get_results( "SHOW TABLES LIKE '{$table_name}'" ); if ( 0 !== count( $results ) ) { $sql = "SHOW FIELDS FROM {$table_name} WHERE FIELD = 'translation_priority'"; /** @var array<int, object> $s_results */ $s_results = $this->wpdb->get_results( $sql ); if ( 0 === count( $s_results ) ) { $sql = "ALTER TABLE {$this->wpdb->prefix}icl_strings ADD COLUMN `translation_priority` varchar(160) NOT NULL"; $result = false !== $this->wpdb->query( $sql ); } if ( false !== $result ) { $sql = "SHOW KEYS FROM {$table_name} WHERE Key_name='icl_strings_translation_priority'"; /** @var array<int, object> $results */ $results = $this->wpdb->get_results( $sql ); if ( 0 === count( $results ) ) { $sql = " ALTER TABLE {$this->wpdb->prefix}icl_strings ADD INDEX `icl_strings_translation_priority` ( `translation_priority` ASC ) "; $result = false !== $this->wpdb->query( $sql ); } else { $result = true; } } } return (bool) $result; } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } public static function get_command_id() { return __CLASS__; } } class-wpml-st-upgrade-db-string-packages-word-count.php 0000644 00000001554 14721577153 0017173 0 ustar 00 <?php class WPML_ST_Upgrade_DB_String_Packages_Word_Count implements IWPML_St_Upgrade_Command { /** @var WPML_Upgrade_Schema $upgrade_schema */ private $upgrade_schema; public function __construct( WPML_Upgrade_Schema $upgrade_schema ) { $this->upgrade_schema = $upgrade_schema; } public function run() { $table = 'icl_string_packages'; $column = 'word_count'; if ( ! $this->upgrade_schema->does_table_exist( $table ) ) { return false; } if ( ! $this->upgrade_schema->does_column_exist( $table, $column ) ) { return (bool) $this->upgrade_schema->add_column( $table, $column, 'VARCHAR(2000) DEFAULT NULL' ); } return true; } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** * @return string */ public static function get_command_id() { return __CLASS__; } } Command/MigrateMultilingualWidgets.php 0000644 00000005250 14721577153 0014157 0 ustar 00 <?php namespace WPML\ST\Upgrade\Command; use WPML\Element\API\Languages; use WPML\FP\Cast; use WPML\FP\Fns; use WPML\FP\Logic; use WPML\FP\Lst; use WPML\FP\Obj; use WPML\FP\Relation; use WPML\FP\Str; use WPML\LIB\WP\Option; use WPML\ST\MO\File\ManagerFactory; use function WPML\FP\partial; use function WPML\FP\pipe; class MigrateMultilingualWidgets implements \IWPML_St_Upgrade_Command { public function run() { $multiLingualWidgets = Option::getOr( 'widget_text_icl', [] ); $multiLingualWidgets = array_filter( $multiLingualWidgets, Logic::complement( 'is_scalar' ) ); if ( ! $multiLingualWidgets ) { return true; } $textWidgets = Option::getOr( 'widget_text', [] ); if ( $textWidgets ) { /** @var array $textWidgetsKeys */ $textWidgetsKeys = Obj::keys( $textWidgets ); $theHighestTextWidgetId = max( $textWidgetsKeys ); } else { $theHighestTextWidgetId = 0; $textWidgets['_multiwidget'] = 1; } $transformWidget = pipe( Obj::renameProp( 'icl_language', 'wpml_language' ), Obj::over( Obj::lensProp( 'wpml_language' ), Logic::ifElse( Relation::equals( 'multilingual' ), Fns::always( 'all' ), Fns::identity() ) ) ); $oldToNewIdMap = []; foreach ( $multiLingualWidgets as $id => $widget ) { $newId = ++ $theHighestTextWidgetId; $oldToNewIdMap[ $id ] = $newId; $textWidgets = Obj::assoc( $newId, $transformWidget( $widget ), $textWidgets ); } Option::update( 'widget_text', $textWidgets ); Option::delete( 'widget_text_icl' ); $sidebars = wp_get_sidebars_widgets(); $sidebars = $this->convertSidebarsConfig( $sidebars, $oldToNewIdMap ); wp_set_sidebars_widgets( $sidebars ); $this->convertWidgetsContentStrings(); return true; } private function convertSidebarsConfig( $sidebars, array $oldToNewIdMap ) { $isMultilingualWidget = Str::startsWith( 'text_icl' ); $extractIdNumber = pipe( Str::split( '-' ), Lst::last(), Cast::toInt() ); $mapWidgetId = Logic::ifElse( $isMultilingualWidget, pipe( $extractIdNumber, Obj::prop( Fns::__, $oldToNewIdMap ), Str::concat( 'text-' ) ), Fns::identity() ); return Fns::map( Fns::map( $mapWidgetId ), $sidebars ); } private function convertWidgetsContentStrings() { global $wpdb; $wpdb->query(" UPDATE {$wpdb->prefix}icl_strings SET `name` = CONCAT( 'widget body - ', MD5(`value`)) WHERE `name` LIKE 'widget body - text_icl%' "); $locales = Fns::map( Languages::getWPLocale(), Languages::getSecondaries() ); Fns::map( partial( [ ManagerFactory::create(), 'add' ], 'Widgets' ), $locales ); } public function run_ajax() { } public function run_frontend() { } public static function get_command_id() { return __CLASS__; } } Command/RegenerateMoFilesWithStringNames.php 0000644 00000003373 14721577153 0015224 0 ustar 00 <?php namespace WPML\ST\Upgrade\Command; use WPML\ST\MO\File\Manager; use WPML\ST\MO\Generate\Process\SingleSiteProcess; use WPML\ST\MO\Generate\Process\Status; use WPML\ST\MO\Notice\RegenerationInProgressNotice; use WPML_Installation; use function WPML\Container\make; class RegenerateMoFilesWithStringNames implements \IWPML_St_Upgrade_Command { const WPML_VERSION_FOR_THIS_COMMAND = '4.3.4'; /** @var Status $status */ private $status; /** @var SingleSiteProcess $singleProcess */ private $singleProcess; /** * @param Status $status * @param SingleSiteProcess $singleProcess We use run the single site process because * the migration command runs once per site. */ public function __construct( Status $status, SingleSiteProcess $singleProcess ) { $this->status = $status; $this->singleProcess = $singleProcess; } public function run() { if ( ! ( $this->hasWpmlStartedBeforeThisCommand() && Manager::hasFiles() ) ) { $this->status->markComplete(); return true; } $this->singleProcess->runPage(); if ( $this->singleProcess->isCompleted() ) { \wpml_get_admin_notices()->remove_notice( RegenerationInProgressNotice::GROUP, RegenerationInProgressNotice::ID ); return true; } \wpml_get_admin_notices()->add_notice( make( RegenerationInProgressNotice::class ) ); return false; } /** * @return bool */ private function hasWpmlStartedBeforeThisCommand() { return (bool) version_compare( get_option( WPML_Installation::WPML_START_VERSION_KEY, '0.0.0' ), self::WPML_VERSION_FOR_THIS_COMMAND, '<' ); } public function run_ajax() { } public function run_frontend() { } public static function get_command_id() { return __CLASS__; } } class-wpml-st-upgrade-mo-scanning.php 0000644 00000004370 14721577153 0013637 0 ustar 00 <?php class WPML_ST_Upgrade_MO_Scanning implements IWPML_St_Upgrade_Command { /** @var wpdb $wpdb */ private $wpdb; /** * @param wpdb $wpdb */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } public function run() { return $this->create_table() && $this->add_mo_value_field_if_does_not_exist(); } private function create_table() { $table_name = $this->wpdb->prefix . 'icl_mo_files_domains'; $this->wpdb->query( "DROP TABLE IF EXISTS `{$table_name}`" ); //@todo needs proper testing /** @var string $sql */ $sql = $this->wpdb->prepare( " CREATE TABLE `{$this->wpdb->prefix}icl_mo_files_domains` ( `id` int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT, `file_path` varchar(250) NOT NULL, `file_path_md5` varchar(32) NOT NULL, `domain` varchar(160) NOT NULL, `status` varchar(20) NOT NULL DEFAULT %s, `num_of_strings` int(11) NOT NULL DEFAULT '0', `last_modified` int(11) NOT NULL, `component_type` enum('plugin','theme','other') NOT NULL DEFAULT 'other', `component_id` varchar(100) DEFAULT NULL, UNIQUE KEY `file_path_md5_UNIQUE` (`file_path_md5`) ) ", array( WPML_ST_Translations_File_Entry::NOT_IMPORTED ) ); $sql .= $this->get_charset_collate(); return false !== $this->wpdb->query( $sql ); } private function add_mo_value_field_if_does_not_exist() { $result = true; $table_name = $this->wpdb->prefix . 'icl_string_translations'; /** @var array $results */ $results = $this->wpdb->get_results( "SHOW COLUMNS FROM `{$table_name}` LIKE 'mo_string'" ); if ( 0 === count( $results ) ) { $sql = " ALTER TABLE {$table_name} ADD COLUMN `mo_string` TEXT NULL DEFAULT NULL AFTER `value`; "; $result = false !== $this->wpdb->query( $sql ); } return $result; } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } public static function get_command_id() { return __CLASS__ . '_4' ; } /** * @return string */ private function get_charset_collate() { $charset_collate = ''; if ( method_exists( $this->wpdb, 'has_cap' ) && $this->wpdb->has_cap( 'collation' ) ) { $charset_collate = $this->wpdb->get_charset_collate(); } return $charset_collate; } } class-wpml-st-upgrade-display-strings-scan-notices.php 0000644 00000001577 14721577153 0017154 0 ustar 00 <?php class WPML_ST_Upgrade_Display_Strings_Scan_Notices implements IWPML_St_Upgrade_Command { /** @var WPML_ST_Themes_And_Plugins_Settings */ private $settings; /** * WPML_ST_Upgrade_Display_Strings_Scan_Notices constructor. * * @param WPML_ST_Themes_And_Plugins_Settings $settings */ public function __construct( WPML_ST_Themes_And_Plugins_Settings $settings ) { $this->settings = $settings; } public static function get_command_id() { return __CLASS__; } public function run() { $this->maybe_add_missing_setting(); return ! $this->settings->display_notices_setting_is_missing(); } public function run_ajax() { return false; } public function run_frontend() { return false; } private function maybe_add_missing_setting() { if ( $this->settings->display_notices_setting_is_missing() ) { $this->settings->create_display_notices_setting(); } } } class-wpml-st-upgrade-db-string-packages.php 0000644 00000002451 14721577153 0015071 0 ustar 00 <?php /** * Class WPML_ST_Upgrade_DB_String_Packages */ class WPML_ST_Upgrade_DB_String_Packages implements IWPML_St_Upgrade_Command { private $wpdb; /** * WPML_ST_Upgrade_DB_String_Packages constructor. * * @param wpdb $wpdb */ public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } public function run() { $sql_get_st_package_table_name = "SHOW TABLES LIKE '{$this->wpdb->prefix}icl_string_packages'"; $st_packages_table_exist = $this->wpdb->get_var( $sql_get_st_package_table_name ) === "{$this->wpdb->prefix}icl_string_packages"; if ( ! $st_packages_table_exist ) { return false; } $sql_get_post_id_column_from_st_package = "SHOW COLUMNS FROM {$this->wpdb->prefix}icl_string_packages LIKE 'post_id'"; $post_id_column_exists = $st_packages_table_exist ? $this->wpdb->get_var( $sql_get_post_id_column_from_st_package ) === 'post_id' : false; if ( ! $post_id_column_exists ) { $sql = "ALTER TABLE {$this->wpdb->prefix}icl_string_packages ADD COLUMN `post_id` INTEGER"; return (bool) $this->wpdb->query( $sql ); } return true; } public function run_ajax() { return $this->run(); } public function run_frontend() { } /** * @return string */ public static function get_command_id() { return __CLASS__ . '_2.4.2'; } } class-wpml-upgrade-command-definition.php 0000644 00000003706 14721661642 0014545 0 ustar 00 <?php /** * @author OnTheGo Systems */ class WPML_Upgrade_Command_Definition { private $class_name; private $dependencies = array(); /** @var array Can be 'admin', 'ajax' or 'front-end' */ private $scopes = array(); private $method; /** @var callable|null */ private $factory_method; /** * WPML_Upgrade_Command_Definition constructor. * * @param string $class_name A class implementing \IWPML_Upgrade_Command. * @param array $dependencies An array of dependencies passed to the `$class_name`'s constructor. * @param array $scopes An array of scope values. Accepted values are: `\WPML_Upgrade::SCOPE_ADMIN`, `\WPML_Upgrade::SCOPE_AJAX`, and `\WPML_Upgrade::SCOPE_FRONT_END`. * @param string|null $method The method to call to run the upgrade (otherwise, it calls the "run" method), * @param callable $factory_method */ public function __construct( $class_name, array $dependencies, array $scopes, $method = null, callable $factory_method = null ) { $this->class_name = $class_name; $this->dependencies = $dependencies; $this->scopes = $scopes; $this->method = $method; $this->factory_method = $factory_method; } /** * @return array */ public function get_dependencies() { return $this->dependencies; } /** * @return string */ public function get_class_name() { return $this->class_name; } /** * @return string */ public function get_method() { return $this->method; } /** * @return array */ public function get_scopes() { return $this->scopes; } /** * @return callable|null */ public function get_factory_method() { return $this->factory_method; } /** * @return IWPML_Upgrade_Command */ public function create() { if ( $this->get_factory_method() ) { $factory_method = $this->get_factory_method(); return $factory_method(); } $class_name = $this->get_class_name(); return new $class_name( $this->get_dependencies() ); } } class-wpml-upgrade-loader-factory.php 0000644 00000000501 14721661642 0013702 0 ustar 00 <?php class WPML_Upgrade_Loader_Factory implements IWPML_Backend_Action_Loader { public function create() { global $sitepress; return new WPML_Upgrade_Loader( $sitepress, wpml_get_upgrade_schema(), wpml_load_settings_helper(), wpml_get_admin_notices(), wpml_get_upgrade_command_factory() ); } } class-wpml-upgrade-command-factory.php 0000644 00000001055 14721661642 0014057 0 ustar 00 <?php class WPML_Upgrade_Command_Factory { /** * @param string $class_name * @param array $dependencies * @param array $scopes * @param string|null $method * @param callable|null $factory_method * * @return WPML_Upgrade_Command_Definition */ public function create_command_definition( $class_name, array $dependencies, array $scopes, $method = null, callable $factory_method = null ) { return new WPML_Upgrade_Command_Definition( $class_name, $dependencies, $scopes, $method, $factory_method ); } } class-wpml-upgrade-run-all.php 0000644 00000000655 14721661642 0012353 0 ustar 00 <?php abstract class WPML_Upgrade_Run_All implements IWPML_Upgrade_Command { /** @var bool $result */ protected $result = true; abstract protected function run(); public function run_admin() { return $this->run(); } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** @return bool */ public function get_results() { return $this->result; } } class-wpml-upgrade-loader.php 0000644 00000020414 14721661642 0012242 0 ustar 00 <?php /** * WPML_Upgrade_Loader class file. * * @package WPML */ use WPML\Upgrade\Commands\AddContextIndexToStrings; use WPML\Upgrade\Commands\AddStatusIndexToStringTranslations; use WPML\Upgrade\Commands\AddStringPackageIdIndexToStrings; use WPML\Upgrade\Command\DisableOptionsAutoloading; use WPML\Upgrade\Commands\AddTranslationManagerCapToAdmin; use WPML\Upgrade\Commands\RemoveRestDisabledNotice; use WPML\Upgrade\Commands\DropCodeLocaleIndexFromLocaleMap; use WPML\Upgrade\Commands\AddPrimaryKeyToLocaleMap; use WPML\Upgrade\Commands\AddCountryColumnToLanguages; use WPML\Upgrade\Commands\AddAutomaticColumnToIclTranslateJob; use WPML\Upgrade\Commands\RemoveEndpointsOption; use WPML\TM\Upgrade\Commands\AddReviewStatusColumnToTranslationStatus; use WPML\TM\Upgrade\Commands\AddAteCommunicationRetryColumnToTranslationStatus; use WPML\TM\Upgrade\Commands\AddAteSyncCountToTranslationJob; use WPML\TM\Upgrade\Commands\ResetTranslatorOfAutomaticJobs; use WPML\Upgrade\Commands\CreateBackgroundTaskTable; use WPML\Upgrade\Commands\RemoveTmWcmlPromotionNotice; /** * Class WPML_Upgrade_Loader */ class WPML_Upgrade_Loader implements IWPML_Action { const TRANSIENT_UPGRADE_IN_PROGRESS = 'wpml_core_update_in_progress'; /** * SitePress instance. * * @var SitePress */ private $sitepress; /** * Upgrade Schema instance. * * @var WPML_Upgrade_Schema */ private $upgrade_schema; /** * Settings Helper instance. * * @var WPML_Settings_Helper */ private $settings; /** * Upgrade Command Factory instance. * * @var WPML_Upgrade_Command_Factory */ private $factory; /** * Notices instance. * * @var WPML_Notices */ private $notices; /** * WPML_Upgrade_Loader constructor. * * @param SitePress $sitepress SitePress instance. * @param WPML_Upgrade_Schema $upgrade_schema Upgrade schema instance. * @param WPML_Settings_Helper $settings Settings Helper instance. * @param WPML_Notices $wpml_notices Notices instance. * @param WPML_Upgrade_Command_Factory $factory Upgrade Command Factory instance. */ public function __construct( SitePress $sitepress, WPML_Upgrade_Schema $upgrade_schema, WPML_Settings_Helper $settings, WPML_Notices $wpml_notices, WPML_Upgrade_Command_Factory $factory ) { $this->sitepress = $sitepress; $this->upgrade_schema = $upgrade_schema; $this->settings = $settings; $this->notices = $wpml_notices; $this->factory = $factory; } /** * Add hooks. */ public function add_hooks() { add_action( 'wpml_loaded', array( $this, 'wpml_upgrade' ) ); register_activation_hook( WPML_PLUGIN_PATH . '/' . WPML_PLUGIN_FILE, array( $this, 'wpml_upgrade' ) ); } /** * Upgrade WPML plugin. */ public function wpml_upgrade() { if ( get_transient( self::TRANSIENT_UPGRADE_IN_PROGRESS ) ) { return; } $commands = [ $this->factory->create_command_definition( 'WPML_Upgrade_Localization_Files', [ $this->sitepress ], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Fix_Non_Admin_With_Admin_Cap', [], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Table_Translate_Job_For_3_9_0', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Remove_Translation_Services_Transient', [], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Display_Mode_For_Posts', [ $this->sitepress, $this->settings, $this->notices ], [ 'admin', 'ajax' ] ), $this->factory->create_command_definition( 'WPML_Add_UUID_Column_To_Translation_Status', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Element_Type_Length_And_Collation', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Add_Word_Count_Column_To_Strings', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Media_Without_Language', [ $this->upgrade_schema->get_wpdb(), $this->sitepress->get_default_language() ], [ 'admin', 'ajax' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Media_Duplication_In_Core', [ $this->sitepress, $this->upgrade_schema, $this->notices ], [ 'admin', 'ajax' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Chinese_Flags', [ 'wpdb' => $this->sitepress->wpdb() ], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Add_Editor_Column_To_Icl_Translate_Job', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_WPML_Site_ID', [], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_WPML_Site_ID_Remaining', [], [ 'admin' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Add_Location_Column_To_Strings', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Add_Wrap_Column_To_Translate', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( 'WPML_Upgrade_Add_Wrap_Column_To_Strings', [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddContextIndexToStrings::class, array( $this->upgrade_schema ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( AddStatusIndexToStringTranslations::class, array( $this->upgrade_schema ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( AddStringPackageIdIndexToStrings::class, array( $this->upgrade_schema ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( CreateBackgroundTaskTable::class, array( $this->upgrade_schema ), array( 'admin' ) ), $this->factory->create_command_definition( DisableOptionsAutoloading::class, [], [ 'admin' ] ), $this->factory->create_command_definition( RemoveRestDisabledNotice::class, [], [ 'admin' ] ), $this->factory->create_command_definition( ResetTranslatorOfAutomaticJobs::class, [], [ 'admin' ] ), $this->factory->create_command_definition( DropCodeLocaleIndexFromLocaleMap::class, array( $this->upgrade_schema ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( AddPrimaryKeyToLocaleMap::class, array( $this->upgrade_schema ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( AddCountryColumnToLanguages::class, [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddAutomaticColumnToIclTranslateJob::class, [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddTMAllowedOption::class, [], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddTranslationManagerCapToAdmin::class, [], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddReviewStatusColumnToTranslationStatus::class, [ $this->upgrade_schema ], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( AddAteCommunicationRetryColumnToTranslationStatus::class, [ $this->upgrade_schema ], [ 'admin', 'ajax' ] ), $this->factory->create_command_definition( AddAteSyncCountToTranslationJob::class, [ $this->upgrade_schema ], [ 'admin', 'ajax' ] ), $this->factory->create_command_definition( 'WPML_TM_Add_TP_ID_Column_To_Translation_Status', [ $this->upgrade_schema ], array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( 'WPML_TM_Add_TP_Revision_And_TS_Status_Columns_To_Translation_Status', [ $this->upgrade_schema ], array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( 'WPML_TM_Add_TP_Revision_And_TS_Status_Columns_To_Core_Status', [ $this->upgrade_schema ], array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( RemoveEndpointsOption::class, [], [ 'admin', 'ajax', 'front-end' ] ), $this->factory->create_command_definition( RemoveTmWcmlPromotionNotice::class, [], [ 'admin' ] ), ]; $upgrade = new WPML_Upgrade( $commands, $this->sitepress, $this->factory ); $upgrade->run(); } } class-wpml-upgrade-localizations-files.php 0000644 00000001745 14721661642 0014755 0 ustar 00 <?php /** * @author OnTheGo Systems */ class WPML_Upgrade_Localization_Files implements IWPML_Upgrade_Command { private $download_localization; private $results = null; /** @var SitePress */ private $sitepress; /** * WPML_Upgrade_Localization_Files constructor. * * @param array $args */ public function __construct( array $args ) { $this->sitepress = $args[0]; $this->download_localization = new WPML_Download_Localization( $this->sitepress->get_active_languages(), $this->sitepress->get_default_language() ); } public function run_admin() { if ( ! $this->sitepress->get_wp_api()->is_back_end() ) { return false; } $this->results = $this->download_localization->download_language_packs(); return true; } public function run_ajax() { return false; } public function run_frontend() { return false; } public function get_command_id() { return 'wpml-upgrade-localization-files'; } public function get_results() { return $this->results; } } interface-iwpml-upgrade-command.php 0000644 00000000253 14721661642 0013415 0 ustar 00 <?php interface IWPML_Upgrade_Command { public function run_admin(); public function run_ajax(); public function run_frontend(); public function get_results(); } class-wpml-upgrade-schema.php 0000644 00000012014 14721661642 0012231 0 ustar 00 <?php class WPML_Upgrade_Schema { /** @var wpdb $wpdb */ private $wpdb; public function __construct( wpdb $wpdb ) { $this->wpdb = $wpdb; } /** * @param string $table_name * * @return bool */ public function does_table_exist( $table_name ) { return $this->has_results( $this->wpdb->get_results( "SHOW TABLES LIKE '{$this->wpdb->prefix}{$table_name}'" ) ); } /** * @param string $table_name * @param string $column_name * * @return bool */ public function does_column_exist( $table_name, $column_name ) { return $this->has_results( $this->wpdb->get_results( "SHOW COLUMNS FROM {$this->wpdb->prefix}{$table_name} LIKE '{$column_name}'" ) ); } /** * @param string $table_name * @param string $index_name * * @return bool */ public function does_index_exist( $table_name, $index_name ) { return $this->has_results( $this->wpdb->get_results( "SHOW INDEXES FROM {$this->wpdb->prefix}{$table_name} WHERE key_name = '{$index_name}'" ) ); } /** * @param string $table_name * @param string $key_name * * @return bool */ public function does_key_exist( $table_name, $key_name ) { return $this->has_results( $this->wpdb->get_results( "SHOW KEYS FROM {$this->wpdb->prefix}{$table_name} WHERE key_name = '{$key_name}'" ) ); } private function has_results( $results ) { return is_array( $results ) && count( $results ); } /** * @param string $table_name * @param string $column_name * @param string $attribute_string * * @return false|int */ public function add_column( $table_name, $column_name, $attribute_string ) { return $this->wpdb->query( "ALTER TABLE {$this->wpdb->prefix}{$table_name} ADD `{$column_name}` {$attribute_string}" ); } /** * @param string $table_name * @param string $column_name * @param string $attribute_string * * @return false|int */ public function modify_column( $table_name, $column_name, $attribute_string ) { return $this->wpdb->query( "ALTER TABLE {$this->wpdb->prefix}{$table_name} MODIFY COLUMN `{$column_name}` {$attribute_string}" ); } /** * @param string $table_name * @param string $index_name * @param string $attribute_string * * @return false|int */ public function add_index( $table_name, $index_name, $attribute_string ) { return $this->wpdb->query( "ALTER TABLE {$this->wpdb->prefix}{$table_name} ADD INDEX `{$index_name}` {$attribute_string}" ); } /** * @param string $table_name * @param array $key_columns * * @return false|int */ public function add_primary_key( $table_name, $key_columns ) { return $this->wpdb->query( "ALTER TABLE {$this->wpdb->prefix}{$table_name} ADD PRIMARY KEY (`" . implode( '`, `', $key_columns ) . '`)' ); } /** * @param string $table_name * @param string $index_name * * @return false|int */ public function drop_index( $table_name, $index_name ) { return $this->wpdb->query( "ALTER TABLE {$this->wpdb->prefix}{$table_name} DROP INDEX `{$index_name}`" ); } /** * @param string $table_name * @param string $column_name * * @return null|string */ public function get_column_collation( $table_name, $column_name ) { return $this->wpdb->get_var( "SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{$this->wpdb->dbname}' AND TABLE_NAME = '{$this->wpdb->prefix}{$table_name}' AND COLUMN_NAME = '{$column_name}'" ); } /** * @param string $table_name * * @return string|null */ public function get_table_collation( $table_name ) { $table_data = $this->wpdb->get_row( $this->wpdb->prepare( 'SHOW TABLE status LIKE %s', $table_name ) ); if ( isset( $table_data->Collation ) ) { return $table_data->Collation; } return null; } /** * We try to get the collation from the posts table first. * * @return string|null */ public function get_default_collate() { $posts_table_collate = $this->get_table_collation( $this->wpdb->posts ); if ( $posts_table_collate ) { return $posts_table_collate; } elseif ( ! empty( $this->wpdb->collate ) ) { return $this->wpdb->collate; } return null; } /** * @param string $table_name * * @return string|null */ public function get_table_charset( $table_name ) { try { return $this->wpdb->get_var( $this->wpdb->prepare( 'SELECT CCSA.character_set_name FROM information_schema.`TABLES` T, information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation AND T.table_schema = "%s" AND T.table_name = "%s";', $this->wpdb->dbname, $table_name ) ); } catch ( Exception $e ) { return null; } } /** * We try to get the charset from the posts table first. * * @return string|null */ public function get_default_charset() { $post_table_charset = $this->get_table_charset( $this->wpdb->posts ); if ( $post_table_charset ) { return $post_table_charset; } elseif ( ! empty( $this->wpdb->charset ) ) { return $this->wpdb->charset; } return null; } /** * @return wpdb */ public function get_wpdb() { return $this->wpdb; } } commands/ResetTranslatorOfAutomaticJobs.php 0000644 00000003275 14721661642 0015204 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class ResetTranslatorOfAutomaticJobs implements \IWPML_Upgrade_Command { /** @var bool $result */ private $result = false; public function run_admin() { global $wpdb; $automatic_column_exists = $wpdb->get_var( "SHOW COLUMNS FROM `{$wpdb->prefix}icl_translate_job` LIKE 'automatic'" ); if ( ! $automatic_column_exists ) { // No need to reset translator of automatic jobs // as this site never used automatic translation. // Return true to mark this upgrade as done. return true; } $subquery = " SELECT job_id, rid FROM {$wpdb->prefix}icl_translate_job WHERE job_id IN ( SELECT MAX(job_id) FROM {$wpdb->prefix}icl_translate_job GROUP BY rid ) AND automatic = 1 "; $rowsToUpdate = $wpdb->get_results( $subquery ); if ( count( $rowsToUpdate ) ) { $rids = \wpml_prepare_in( array_column( $rowsToUpdate, 'rid' ), '%d' ); $sql = " UPDATE {$wpdb->prefix}icl_translation_status translation_status SET translation_status.translator_id = 0 WHERE translation_status.rid IN ( $rids ) "; $wpdb->query( $sql ); $jobIds = \wpml_prepare_in( array_column( $rowsToUpdate, 'job_id' ), '%d' ); $sql = " UPDATE {$wpdb->prefix}icl_translate_job SET translator_id = 0 WHERE job_id IN ( $jobIds ) "; $wpdb->query( $sql ); } $this->result = true; return $this->result; } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/RemoveTmWcmlPromotionNotice.php 0000644 00000000553 14721661642 0014524 0 ustar 00 <?php namespace WPML\Upgrade\Commands; use ICL_AdminNotifier; class RemoveTmWcmlPromotionNotice implements \IWPML_Upgrade_Command { public function run_admin() { ICL_AdminNotifier::remove_message( 'promote-wcml' ); return true; } public function run_ajax() {} public function run_frontend() {} public function get_results() { return true; } } commands/class-wpml-upgrade-table-translate-job-for-3-9-0.php 0000644 00000002110 14721661642 0017647 0 ustar 00 <?php class WPML_Upgrade_Table_Translate_Job_For_3_9_0 implements IWPML_Upgrade_Command { /** @var bool $result */ private $result = true; /** @var WPML_Upgrade_Schema */ private $upgrade_schema; public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** @return bool */ private function run() { $table = 'icl_translate_job'; $columns = array( 'title' => 'VARCHAR(160) NULL', 'deadline_date' => 'DATETIME NULL', 'completed_date' => 'DATETIME NULL', ); if ( $this->upgrade_schema->does_table_exist( $table ) ) { foreach ( $columns as $column => $attribute_string ) { if ( ! $this->upgrade_schema->does_column_exist( $table, $column ) ) { $this->upgrade_schema->add_column( $table, $column, $attribute_string ); } } } return $this->result; } public function run_admin() { return $this->run(); } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** @return bool */ public function get_results() { return $this->result; } } commands/class-wpml-upgrade-add-location-column-to-strings.php 0000644 00000001211 14721661642 0020527 0 ustar 00 <?php /** * Upgrade 'icl_strings' table by adding 'location' column. * * @package WPML */ /** * Class WPML_Upgrade_Add_Location_Column_To_Strings */ class WPML_Upgrade_Add_Location_Column_To_Strings extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_strings'; } /** * Get column name. * * @return string */ protected function get_column() { return 'location'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'BIGINT unsigned NULL AFTER `string_package_id`'; } } commands/RefreshTranslationServices.php 0000644 00000002371 14721661642 0014413 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; use WPML\TM\Menu\TranslationServices\Troubleshooting\RefreshServices; use WPML\TM\Menu\TranslationServices\Troubleshooting\RefreshServicesFactory; class RefreshTranslationServices implements \IWPML_Upgrade_Command { const WPML_VERSION_SINCE_PREVIEW_LOGOS_AVAILABLE = '4.4.0'; /** @var bool $result */ private $result = false; /** @var RefreshServicesFactory */ private $refreshServicesFactory; /** @var callable */ private $isHigherThanInstallationVersion; public function __construct( array $args ) { $this->refreshServicesFactory = $args[0]; $this->isHigherThanInstallationVersion = $args[1]; } /** * @return bool */ public function run_admin() { $this->result = true; if ( call_user_func( $this->isHigherThanInstallationVersion, self::WPML_VERSION_SINCE_PREVIEW_LOGOS_AVAILABLE ) ) { $this->result = $this->refreshServicesFactory->create_an_instance()->refresh_services(); } return $this->result; } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/CreateAteDownloadQueueTable.php 0000644 00000002455 14721661642 0014377 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; use SitePress_Setup; class CreateAteDownloadQueueTable implements \IWPML_Upgrade_Command { const TABLE_NAME = 'icl_translation_downloads'; /** @var \WPML_Upgrade_Schema $schema */ private $schema; /** @var bool $result */ private $result = false; public function __construct( array $args ) { $this->schema = $args[0]; } /** * @return bool */ public function run() { $wpdb = $this->schema->get_wpdb(); $tableName = $wpdb->prefix . self::TABLE_NAME; $charsetCollate = SitePress_Setup::get_charset_collate(); $query = " CREATE TABLE IF NOT EXISTS `{$tableName}` ( `editor_job_id` BIGINT(20) UNSIGNED NOT NULL, `download_url` VARCHAR(2000) NOT NULL, `lock_timestamp` INT(11) UNSIGNED NULL, PRIMARY KEY (`editor_job_id`) ) ENGINE=INNODB {$charsetCollate}; "; $this->result = $wpdb->query( $query ); return $this->result; } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/class-wpml-upgrade-display-mode-for-posts.php 0000644 00000010236 14721661642 0017117 0 ustar 00 <?php class WPML_Upgrade_Display_Mode_For_Posts implements IWPML_Upgrade_Command { const DISPLAY_MODE_SETTING = 'show_untranslated_blog_posts'; /** @var SitePress */ private $sitepress; /** @var WPML_Settings_Helper */ private $settings; /** @var WPML_Notices */ private $wpml_notices; public function __construct( array $args ) { $this->sitepress = $args[0]; $this->settings = $args[1]; $this->wpml_notices = $args[2]; } /** * @return bool */ public function run_admin() { if ( $this->sitepress->get_setting( self::DISPLAY_MODE_SETTING ) ) { add_action( 'init', [ $this, 'add_notice' ] ); return false; } else { return true; } } public function add_notice() { $notice = $this->wpml_notices->create_notice( __CLASS__, $this->get_notice_content() ); $notice->add_display_callback( array( 'WPML_Notice_Show_On_Dashboard_And_WPML_Pages', 'is_on_page' ) ); $notice->set_css_class_types( 'info' ); $this->wpml_notices->add_notice( $notice ); } /** * @return bool */ public function run_ajax() { if ( isset( $_POST['mode'] ) ) { if ( 'translate' === $_POST['mode'] ) { $this->settings->set_post_type_translatable( 'post' ); $this->sitepress->set_setting( self::DISPLAY_MODE_SETTING, false, true ); $this->wpml_notices->remove_notice( 'default', __CLASS__ ); return true; } if ( 'display-as-translated' === $_POST['mode'] ) { $this->settings->set_post_type_display_as_translated( 'post' ); $this->sitepress->set_setting( self::DISPLAY_MODE_SETTING, false, true ); $this->wpml_notices->remove_notice( 'default', __CLASS__ ); return true; } } return false; } /** * @return bool */ public function run_frontend() { return false; } /** * @return array */ public function get_results() { return array(); } private function get_notice_content() { ob_start(); $action = str_replace( '_', '-', strtolower( __CLASS__ ) ); $setup_url = WPML_Admin_URL::multilingual_setup( 7 ); ?> <div class="js-main-content"> <h2><?php esc_html_e( 'Display mode for blog posts has changed', 'sitepress' ); ?></h2> <p><?php esc_html_e( 'Until now, your site was set to display "all blog posts", even if they are not translated. That feature is now replaced with a better and more complete translation mode.', 'sitepress' ); ?></p> <p><?php esc_html_e( "Which blog posts do you want to display on your site's translations?", 'sitepress' ); ?></p> <p><label><input type="radio" name="mode" value="display-as-translated"/> <?php esc_html_e( "Blog posts from the site's default language, or translations when they exist", 'sitepress' ); ?> </label></p> <p><label><input type="radio" name="mode" value="translate"/> <?php esc_html_e( "Only translated blog posts (never display posts from the default language on translation languages)", 'sitepress' ); ?> </label></p> <input type="button" class="button-primary" name="save" value="<?php esc_attr_e( 'Save' ); ?>" disabled="disabled"/> <?php wp_nonce_field( $action . '-nonce', $action . '-nonce' ); ?> </div> <div class="js-thankyou-content" style="display: none"> <p><?php echo sprintf( esc_html__( 'Thank you for choosing. You can always change your selection in %sPost Types Translation setup%s.', 'sitepress' ), '<a href="' . $setup_url . '">', '</a>' ); ?></p> </div> <script> jQuery( document ).ready( function ( $ ) { $( '.js-main-content' ).find( 'input[name=mode]' ).on( 'change', function ( e ) { $( '.js-main-content' ).find( 'input[name=save]' ).prop( 'disabled', false ); } ); $( '.js-main-content' ).find( 'input[name=save]' ).on( 'click', function ( e ) { $( this ).prop( 'disabled', true ); $.ajax( { url: ajaxurl, type: "POST", data: { action: '<?php echo $action; ?>', nonce: $( '#<?php echo $action; ?>-nonce' ).val(), mode: $( 'input[name=mode]:checked', '.js-main-content' ).val() }, success: function ( response ) { $( '.js-main-content' ).hide(); $( '.js-thankyou-content' ).show(); } } ); } ); } ); </script> <?php return ob_get_clean(); } } commands/class-wpml-tm-upgrade-service-redirect-to-field.php 0000644 00000002221 14721661642 0020147 0 ustar 00 <?php use WPML\TM\Menu\TranslationServices\Troubleshooting\RefreshServices; use WPML\TM\Menu\TranslationServices\Troubleshooting\RefreshServicesFactory; class WPML_TM_Upgrade_Service_Redirect_To_Field implements IWPML_Upgrade_Command { /** @var bool $result */ private $result = true; /** @var RefreshServices */ private $service_refresh; public function __construct( $args ) { if ( isset( $args[0] ) && $args[0] instanceof RefreshServices ) { $this->service_refresh = $args[0]; } } /** * Add the default terms for Translation Priority taxonomy * * @return bool */ private function run() { $this->result = $this->get_service_refresh()->refresh_services(); return $this->result; } public function run_admin() { return $this->run(); } public function run_ajax() { } public function run_frontend() { } /** @return bool */ public function get_results() { return $this->result; } private function get_service_refresh() { if ( ! $this->service_refresh ) { $factory = new RefreshServicesFactory(); $this->service_refresh = $factory->create_an_instance(); } return $this->service_refresh; } } commands/class-wpml-add-uuid-column-to-translation-status.php 0000644 00000001167 14721661642 0020440 0 ustar 00 <?php /** * Upgrade 'icl_translation_status' table by adding 'uuid' column. * * @package WPML */ /** * Class WPML_Add_UUID_Column_To_Translation_Status */ class WPML_Add_UUID_Column_To_Translation_Status extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_translation_status'; } /** * Get column name. * * @return string */ protected function get_column() { return 'uuid'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'VARCHAR(36) NULL'; } } commands/AddTMAllowedOption.php 0000644 00000000340 14721661642 0012516 0 ustar 00 <?php use WPML\Plugins; class AddTMAllowedOption extends WPML_Upgrade_Run_All { /** * @return bool */ public function run() { add_action('init', [ Plugins::class, 'updateTMAllowedOption' ] ); return true; } } commands/DropCodeLocaleIndexFromLocaleMap.php 0000644 00000000347 14721661642 0015304 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class DropCodeLocaleIndexFromLocaleMap extends DropIndexFromTable { protected function get_table() { return 'icl_locale_map'; } protected function get_index() { return 'code'; } } commands/AddAteSyncCountToTranslationJob.php 0000644 00000000664 14721661642 0015242 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class AddAteSyncCountToTranslationJob extends \WPML_Upgrade_Add_Column_To_Table { /** * @return string */ protected function get_table() { return 'icl_translate_job'; } /** * @return string */ protected function get_column() { return 'ate_sync_count'; } /** * @return string */ protected function get_column_definition() { return "INT(6) UNSIGNED DEFAULT 0"; } } commands/RemoveRestDisabledNotice.php 0000644 00000000541 14721661642 0013754 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class RemoveRestDisabledNotice implements \IWPML_Upgrade_Command { public function run_admin() { wpml_get_admin_notices()->remove_notice( 'default', 'rest-disabled' ); return true; } public function run_ajax() {} public function run_frontend() {} public function get_results() { return true; } } commands/AddContextIndexToStrings.php 0000644 00000000447 14721661642 0013776 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddContextIndexToStrings extends AddIndexToTable { protected function get_table() { return 'icl_strings'; } protected function get_index() { return 'context'; } protected function get_index_definition() { return '( `context` )'; } } commands/wpml-tm-upgrade-cancel-orphan-jobs.php 0000644 00000002342 14721661642 0015555 0 ustar 00 <?php class WPML_TM_Upgrade_Cancel_Orphan_Jobs implements IWPML_Upgrade_Command { /** @var WPML_TP_Sync_Orphan_Jobs_Factory */ private $factory; /** @var WPML_TM_Jobs_Migration_State */ private $migration_state; /** * @param array $args */ public function __construct( array $args ) { if ( ! isset( $args[0] ) || ! $args[0] instanceof WPML_TP_Sync_Orphan_Jobs_Factory ) { throw new InvalidArgumentException( 'The factory class must be passed as the first argument in the constructor' ); } if ( ! isset( $args[1] ) || ! $args[1] instanceof WPML_TM_Jobs_Migration_State ) { throw new InvalidArgumentException( 'The WPML_TM_Jobs_Migration_State class must be passed as the second argument in the constructor' ); } $this->factory = $args[0]; $this->migration_state = $args[1]; } /** * @return bool */ public function run_admin() { if ( ! $this->migration_state->is_migrated() ) { return false; } $this->factory->create()->cancel_orphans(); return true; } /** * @return null */ public function run_ajax() { return null; } /** * @return null */ public function run_frontend() { return null; } /** * @return null */ public function get_results() { return null; } } commands/class-wpml-tm-upgrade-translation-priorities-for-posts.php 0000644 00000001636 14721661642 0021677 0 ustar 00 <?php class WPML_TM_Upgrade_Translation_Priorities_For_Posts implements IWPML_Upgrade_Command { /** @var bool $result */ private $result = true; const TRANSLATION_PRIORITY_TAXONOMY = 'translation_priority'; /** * Add the default terms for Translation Priority taxonomy * * @return bool */ private function run() { $translation_priorities_factory = new WPML_TM_Translation_Priorities_Factory(); $translation_priorities_actions = $translation_priorities_factory->create(); $translation_priorities_actions->register_translation_priority_taxonomy(); WPML_TM_Translation_Priorities::insert_missing_default_terms(); return $this->result; } public function run_admin() { return $this->run(); } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** @return bool */ public function get_results() { return $this->result; } } commands/class-wpml-upgrade-wpml-site-id.php 0000644 00000002323 14721661642 0015107 0 ustar 00 <?php /** * Upgrades the former option to the new one. */ class WPML_Upgrade_WPML_Site_ID implements IWPML_Upgrade_Command { /** * Runs the upgrade process. * * @return bool */ public function run() { if ( $this->old_option_exists() ) { $value_from_old_option = get_option( WPML_Site_ID::SITE_ID_KEY, null ); update_option( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_Site_ID::SITE_SCOPES_GLOBAL, $value_from_old_option, false ); return delete_option( WPML_Site_ID::SITE_ID_KEY ); } return true; } /** * Checks has the old option. * * @return bool */ protected function old_option_exists() { get_option( WPML_Site_ID::SITE_ID_KEY, null ); $notoptions = wp_cache_get( 'notoptions', 'options' ); return false === $notoptions || ! array_key_exists( WPML_Site_ID::SITE_ID_KEY, $notoptions ); } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * Unused. * * @return null */ public function get_results() { return null; } } commands/AddReviewStatusColumnToTranslationStatus.php 0000644 00000000723 14721661642 0017253 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class AddReviewStatusColumnToTranslationStatus extends \WPML_Upgrade_Add_Column_To_Table { /** * @return string */ protected function get_table() { return 'icl_translation_status'; } /** * @return string */ protected function get_column() { return 'review_status'; } /** * @return string */ protected function get_column_definition() { return "ENUM('NEEDS_REVIEW', 'EDITING', 'ACCEPTED')"; } } commands/AddTranslationManagerCapToAdmin.php 0000644 00000000610 14721661642 0015166 0 ustar 00 <?php namespace WPML\Upgrade\Commands; use WPML\LIB\WP\User; class AddTranslationManagerCapToAdmin extends \WPML_Upgrade_Run_All { protected function run() { get_role( 'administrator' )->add_cap( User::CAP_MANAGE_TRANSLATIONS ); do_action( 'wpml_tm_ate_synchronize_managers' ); wp_get_current_user()->get_role_caps(); // Refresh the current user capabilities. return true; } } commands/MigrateAteRepository.php 0000644 00000005173 14721661642 0013217 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class MigrateAteRepository implements \IWPML_Upgrade_Command { const TABLE_NAME = 'icl_translate_job'; const COLUMN_EDITOR_JOB_ID = 'editor_job_id'; const COLUMN_EDIT_TIMESTAMP = 'edit_timestamp'; const OPTION_NAME_REPO = 'WPML_TM_ATE_JOBS'; /** @var \WPML_Upgrade_Schema $schema */ private $schema; /** @var bool $result */ private $result = false; public function __construct( array $args ) { $this->schema = $args[0]; } /** * @return bool */ public function run() { $this->result = $this->addColumnsToJobsTable(); if ( $this->result ) { $this->migrateOldRepository(); } return $this->result; } private function addColumnsToJobsTable() { $result = true; if ( ! $this->schema->does_column_exist( self::TABLE_NAME, self::COLUMN_EDITOR_JOB_ID ) ) { $result = $this->schema->add_column( self::TABLE_NAME, self::COLUMN_EDITOR_JOB_ID, 'bigint(20) unsigned NULL' ); } return $result; } private function migrateOldRepository() { $records = get_option( self::OPTION_NAME_REPO ); if ( is_array( $records ) && $records ) { $wpdb = $this->schema->get_wpdb(); $recordPairs = wpml_collect( array_keys( $records ) )->zip( $records ); $ateJobIdCases = $recordPairs->reduce( $this->getCasesReducer(), '' ) . "ELSE 0\n"; $sql = " UPDATE {$wpdb->prefix}" . self::TABLE_NAME . " SET " . self::COLUMN_EDITOR_JOB_ID . " = ( CASE job_id " . $ateJobIdCases . " END ) WHERE " . self::COLUMN_EDITOR_JOB_ID . " IS NULL AND job_id IN(" . wpml_prepare_in( array_keys( $records ), '%d' ) . ") "; $wpdb->query( $sql ); } $this->disableAutoloadOnOldOption(); } /** * @param string $field * * @return \Closure */ private function getCasesReducer() { $wpdb = $this->schema->get_wpdb(); return function( $cases, $data ) use ( $wpdb ) { $cases .= isset( $data[1]['ate_job_id'] ) ? $wpdb->prepare( "WHEN %d THEN %d\n", $data[0], $data[1]['ate_job_id'] ) : ''; return $cases; }; } private function disableAutoloadOnOldOption() { $wpdb = $this->schema->get_wpdb(); $wpdb->update( $wpdb->options, [ 'autoload' => 'no' ], [ 'option_name' => self::OPTION_NAME_REPO ] ); } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/AddAteCommunicationRetryColumnToTranslationStatus.php 0000644 00000000722 14721661642 0021072 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class AddAteCommunicationRetryColumnToTranslationStatus extends \WPML_Upgrade_Add_Column_To_Table { /** * @return string */ protected function get_table() { return 'icl_translation_status'; } /** * @return string */ protected function get_column() { return 'ate_comm_retry_count'; } /** * @return string */ protected function get_column_definition() { return "INT(11) UNSIGNED DEFAULT 0"; } } commands/AddAutomaticColumnToIclTranslateJob.php 0000644 00000001013 14721661642 0016043 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddAutomaticColumnToIclTranslateJob extends \WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_translate_job'; } /** * Get column name. * * @return string */ protected function get_column() { return 'automatic'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'TINYINT UNSIGNED NOT NULL DEFAULT 0'; } } commands/class-wpml-upgrade-add-editor-column-to-icl-translate-job.php 0000644 00000001203 14721661642 0022027 0 ustar 00 <?php /** * Upgrade 'icl_translate_job' table by adding 'editor' column. * * @package WPML */ /** * Class WPML_Upgrade_Add_Editor_Column_To_Icl_Translate_Job */ class WPML_Upgrade_Add_Editor_Column_To_Icl_Translate_Job extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_translate_job'; } /** * Get column name. * * @return string */ protected function get_column() { return 'editor'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'VARCHAR(16) NULL'; } } commands/AddStatusIndexToStringTranslations.php 0000644 00000000473 14721661642 0016053 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddStatusIndexToStringTranslations extends AddIndexToTable { protected function get_table() { return 'icl_string_translations'; } protected function get_index() { return 'status'; } protected function get_index_definition() { return '( `status` )'; } } commands/class-wpml-upgrade-add-wrap-column-to-strings.php 0000644 00000001166 14721661642 0017701 0 ustar 00 <?php /** * Upgrade 'icl_strings' table by adding 'wrap' column. * * @package WPML */ /** * Class WPML_Upgrade_Add_Wrap_Column_To_Strings */ class WPML_Upgrade_Add_Wrap_Column_To_Strings extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_strings'; } /** * Get column name. * * @return string */ protected function get_column() { return 'wrap_tag'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'VARCHAR( 16 ) NOT NULL AFTER `location`'; } } commands/wpml-upgrade-chinese-flags.php 0000644 00000002416 14721661642 0014204 0 ustar 00 <?php class WPML_Upgrade_Chinese_Flags implements IWPML_Upgrade_Command { private $wpdb; /** * WPML_Upgrade_Chinese_Flags constructor. * * @param array $args { * 'wpdb' => @type wpdb * } */ public function __construct( array $args ) { $this->wpdb = $args['wpdb']; } public function run() { $codes = array( 'zh-hans', 'zh-hant' ); $flags_query = 'SELECT id, lang_code, flag FROM ' . $this->wpdb->prefix . 'icl_flags WHERE lang_code IN (' . wpml_prepare_in( $codes ) . ')'; $flags = $this->wpdb->get_results( $flags_query ); if ( $flags ) { foreach ( $flags as $flag ) { if ( $this->must_update( $flag ) ) { $this->wpdb->update( $this->wpdb->prefix . 'icl_flags', array( 'flag' => 'zh.png', ), array( 'id' => $flag->id ), array( '%s' ), array( '%d' ) ); } } } return true; } /** * @param \stdClass $flag * * @return bool */ protected function must_update( $flag ) { return $flag->flag === $flag->lang_code . '.png'; } public function run_admin() { return $this->run(); } public function run_ajax() { return null; } public function run_frontend() { return null; } public function get_results() { return null; } } commands/class-wpml-tm-upgrade-default-editor-for-old-jobs.php 0000644 00000001556 14721661642 0020424 0 ustar 00 <?php class WPML_TM_Upgrade_Default_Editor_For_Old_Jobs implements IWPML_Upgrade_Command { /** @var SitePress */ private $sitepress; public function __construct( $args ) { $this->sitepress = $args[0]; } /** * @return bool */ private function run() { $default = get_option( WPML_TM_Old_Jobs_Editor::OPTION_NAME ); if ( ! $default ) { $method = $this->sitepress->get_setting( 'doc_translation_method' ); $default = WPML_TM_Editors::ATE === strtolower( $method ) ? WPML_TM_Editors::ATE : WPML_TM_Editors::WPML; update_option( WPML_TM_Old_Jobs_Editor::OPTION_NAME, $default ); } return true; } public function run_admin() { return $this->run(); } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** @return bool */ public function get_results() { return true; } } commands/class-wpml-upgrade-add-wrap-column-to-translate.php 0000644 00000001220 14721661642 0020174 0 ustar 00 <?php /** * Upgrade 'icl_translate' table by adding 'field_wrap_tag' column. * * @package WPML */ /** * Class WPML_Upgrade_Add_Wrap_Column_To_Translate */ class WPML_Upgrade_Add_Wrap_Column_To_Translate extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_translate'; } /** * Get column name. * * @return string */ protected function get_column() { return 'field_wrap_tag'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'VARCHAR( 16 ) NOT NULL AFTER `field_type`'; } } commands/class-wpml-upgrade-element-type-length-and-collation.php 0000644 00000002326 14721661642 0021210 0 ustar 00 <?php class WPML_Upgrade_Element_Type_Length_And_Collation implements IWPML_Upgrade_Command { /** @var bool $result */ private $result = true; /** @var WPML_Upgrade_Schema */ private $upgrade_schema; public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** @return bool */ private function run() { $table = 'icl_translations'; $column = 'element_type'; $column_attr = "VARCHAR(60) NOT NULL DEFAULT 'post_post'"; if ( $this->upgrade_schema->does_table_exist( $table ) ) { $column_attr = $this->add_collation_from_post_type( $column_attr ); $this->upgrade_schema->modify_column( $table, $column, $column_attr ); } return $this->result; } private function add_collation_from_post_type( $element_type_attr ) { $collation = $this->upgrade_schema->get_column_collation( 'posts', 'post_type' ); if ( $collation ) { $element_type_attr .= ' COLLATE ' . $collation; } return $element_type_attr; } public function run_admin() { return $this->run(); } public function run_ajax() { return $this->run(); } public function run_frontend() { return $this->run(); } /** @return bool */ public function get_results() { return $this->result; } } commands/class-wpml-tm-add-tp-revision-and-ts-status-columns-to-translation-status.php 0000644 00000001433 14721661642 0025253 0 ustar 00 <?php class WPML_TM_Add_TP_Revision_And_TS_Status_Columns_To_Translation_Status extends WPML_Upgrade_Run_All { /** @var WPML_Upgrade_Schema */ private $upgrade_schema; public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** @return bool */ protected function run() { $table = 'icl_translation_status'; $columns = array( 'tp_revision' => 'INT NOT NULL DEFAULT 1', 'ts_status' => 'TEXT NULL DEFAULT NULL', ); if ( $this->upgrade_schema->does_table_exist( $table ) ) { foreach ( $columns as $column => $definition ) { if ( ! $this->upgrade_schema->does_column_exist( $table, $column ) ) { $this->upgrade_schema->add_column( $table, $column, $definition ); } } } $this->result = true; return $this->result; } } commands/class-wpml-upgrade-add-word-count-column-to-strings.php 0000644 00000001164 14721661642 0021027 0 ustar 00 <?php /** * Upgrade 'icl_strings' table by adding 'word_count' column. * * @package WPML */ /** * Class WPML_Upgrade_Add_Word_Count_Column_To_Strings */ class WPML_Upgrade_Add_Word_Count_Column_To_Strings extends WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_strings'; } /** * Get column name. * * @return string */ protected function get_column() { return 'word_count'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'int unsigned NULL'; } } commands/class-wpml-upgrade-remove-translation-services-transient.php 0000644 00000000735 14721661642 0022260 0 ustar 00 <?php class WPML_Upgrade_Remove_Translation_Services_Transient implements IWPML_Upgrade_Command { /** * @return bool|void */ public function run_admin() { delete_transient( 'wpml_translation_service_list' ); return true; } /** * @return bool */ public function run_ajax() { return false; } /** * @return bool */ public function run_frontend() { return false; } /** * @return null */ public function get_results() { return array(); } } commands/class-wpml-upgrade-media-duplication-in-core.php 0000644 00000024676 14721661642 0017535 0 ustar 00 <?php class WPML_Upgrade_Media_Duplication_In_Core implements IWPML_Upgrade_Command { const FEATURED_AS_TRANSLATED_META_KEY = '_wpml_featured_image_as_translated'; const TRANSIENT_DEFERRED_UPGRADE_IN_PROGRESS = 'wpml_upgrade_media_duplication_in_progress'; const MAX_TIME = 10; /** @var SitePress */ private $sitepress; /** @var WPML_Upgrade $wpml_upgrade */ private $wpml_upgrade; /** @var wpdb $wpdb */ private $wpdb; /** @var WPML_Notices $notices */ private $notices; /** @var WPML_Media_Attachments_Duplication $media_attachment_duplication */ private $media_attachment_duplication; /** @var array $post_thumbnail_map */ private $post_thumbnail_map; /** @var int $start_time */ private $start_time; public function __construct( array $args ) { $this->sitepress = $args[0]; $this->wpdb = $args[1]->get_wpdb(); $this->notices = $args[2]; } /** * @return bool */ public function run_admin() { if ( $this->has_notice() ) { $this->create_or_refresh_notice(); return false; } if ( $this->find_posts_altered_between_402_and_404() ) { /** * The rest of the upgrade needs to run when all the custom post types are registered */ add_action( 'init', array( $this, 'deferred_upgrade_admin' ), PHP_INT_MAX ); return false; } $this->remove_notice(); return true; } public function deferred_upgrade_admin() { list( $is_complete ) = $this->process_upgrade(); if ( ! $is_complete ) { // We could not complete the upgrade in the same request $this->create_or_refresh_notice(); } } /** * @return bool */ public function run_ajax() { /** * The rest of the upgrade needs to run when all the custom post types are registered */ add_action( 'init', array( $this, 'deferred_upgrade_ajax' ), PHP_INT_MAX ); return false; } public function deferred_upgrade_ajax() { list( $is_complete, $remaining ) = $this->process_upgrade(); if ( $is_complete ) { $data = array( 'response' => esc_html__( 'The upgrade is complete.', 'sitepress' ), 'complete' => true, ); } elseif ( $remaining ) { $data = array( 'response' => sprintf( esc_html__( '%d items remaining...', 'sitepress' ), $remaining ), 'complete' => false, ); } else { $data = array( 'concurrent_request' => true ); } wp_send_json_success( $data ); } /** * @return bool */ public function run_frontend() { return false; } /** * @return array */ public function get_results() { return array(); } private function process_upgrade() { $remaining = null; $is_complete = false; if ( ! $this->acquire_lock() ) { return $is_complete; } $this->start_timer(); $source_posts = $this->find_posts_altered_between_402_and_404(); $remaining = count( $source_posts ); $should_duplicate_media = $this->should_duplicate_media(); foreach ( $source_posts as $key => $source_post ) { if ( $should_duplicate_media ) { $this->duplicate_missing_attachments_for_post( $source_post ); } $this->duplicate_missing_featured_image_for_post( $source_post ); $remaining--; if ( $this->is_max_time_elapsed() ) { break; } } if ( ! $this->is_max_time_elapsed() ) { $this->cleanup_display_featured_as_translated_meta(); $this->remove_notice(); $is_complete = true; } $this->release_lock(); return array( $is_complete, $remaining ); } private function get_notice_content() { ob_start(); $action = str_replace( '_', '-', strtolower( __CLASS__ ) ); ?> <div class="js-main-content"> <h2><?php esc_html_e( "WPML needs to upgrade the post's media information.", 'sitepress' ); ?></h2> <p><?php esc_html_e( "We couldn't complete the whole process in one request. Please click on the \"Upgrade\" button to continue.", 'sitepress' ); ?></p> <input type="button" class="button-primary" name="upgrade" value="<?php esc_attr_e( 'Upgrade' ); ?>"/> <span class="js-wpml-upgrade-progress" style="display:none"><?php esc_html_e( 'Starting...', 'sitepress' ); ?></span> <?php wp_nonce_field( $action . '-nonce', $action . '-nonce' ); ?> </div> <script> jQuery( document ).ready( function ( $ ) { var upgradeProgress = $('.js-wpml-upgrade-progress'); var ajax_request = function () { $.ajax( { url: ajaxurl, type: "POST", data: { action: '<?php echo $action; ?>', nonce: $( '#<?php echo $action; ?>-nonce' ).val() }, success: function ( response ) { if ( response.data.concurrent_request ) { setTimeout(ajax_request, 3000); } else { upgradeProgress.text( response.data.response ); if ( ! response.data.complete ) { ajax_request(); } } }, error: function(jqXHR, textStatus, errorThrown) { var errorData = '<p>status code: '+jqXHR.status+'</p><p>errorThrown: ' + errorThrown + '</p><p>jqXHR.responseText:</p><div>'+jqXHR.responseText + '</div>'; upgradeProgress.html( '<?php echo esc_html__( 'The following exception has occurred while running the migration, please try again later or contact support if the problem persists.', 'sitepress' ); ?><hr>' + errorData ); console.log('jqXHR:'); console.log(jqXHR); console.log('textStatus:'); console.log(textStatus); console.log('errorThrown:'); console.log(errorThrown); } } ); }; $( '.js-main-content' ).find( 'input[name="upgrade"]' ).on( 'click', function ( e ) { $( this ).prop( 'disabled', true ); $('.js-wpml-upgrade-progress').show(); ajax_request(); } ); } ); </script> <?php return ob_get_clean(); } /** * Some posts could have been created between WPML 4.0.2 and WPML 4.0.4 * And they would have '_wpml_featured_image_as_translated' but not '_wpml_media_featured' */ private function find_posts_altered_between_402_and_404() { $source_posts_missing_duplicate_featured_meta = "SELECT pm.post_id AS ID, pm.meta_value AS duplicate_featured, t.trid, t.element_type FROM {$this->wpdb->postmeta} AS pm LEFT JOIN {$this->wpdb->prefix}icl_translations AS t ON t.element_id = pm.post_id AND t.element_type LIKE 'post_%' LEFT JOIN {$this->wpdb->postmeta} AS duplicate_featured ON duplicate_featured.post_id = pm.post_id AND duplicate_featured.meta_key = '" . \WPML\Media\Option::DUPLICATE_FEATURED_KEY . "' WHERE pm.meta_key = '" . self::FEATURED_AS_TRANSLATED_META_KEY . "' AND t.source_language_code IS NULL AND duplicate_featured.meta_value IS NULL "; return $this->wpdb->get_results( $source_posts_missing_duplicate_featured_meta ); } private function duplicate_missing_featured_image_for_post( $post ) { if ( $post->duplicate_featured == 1 && $this->has_thumbnail( $post->ID ) ) { $post->post_type = preg_replace( '/^post_/', '', $post->element_type ); $this->get_media_attachment_duplication()->duplicate_featured_image_in_post( $post, $this->get_post_thumbnail_map() ); } // Add the meta to the source post and its translations $translations = $this->sitepress->get_element_translations( $post->trid, $post->element_type ); $post_ids = wp_list_pluck( $translations, 'element_id' ); $this->wpdb->query( $this->wpdb->prepare( "INSERT INTO {$this->wpdb->prefix}postmeta ( post_id, meta_key, meta_value ) SELECT post_id, '" . \WPML\Media\Option::DUPLICATE_FEATURED_KEY . "', %d FROM {$this->wpdb->postmeta} WHERE post_id IN(" . wpml_prepare_in( $post_ids ) . ") AND meta_key = '" . self::FEATURED_AS_TRANSLATED_META_KEY . "'", $post->duplicate_featured ) ); } private function has_thumbnail( $post_id ) { return (bool) $this->wpdb->get_var( $this->wpdb->prepare( "SELECT meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = '_thumbnail_id' AND post_id = %d", $post_id ) ); } /** * @return array */ private function get_post_thumbnail_map() { if ( ! $this->post_thumbnail_map ) { list( $this->post_thumbnail_map ) = $this->get_media_attachment_duplication()->get_post_thumbnail_map(); } return $this->post_thumbnail_map; } private function duplicate_missing_attachments_for_post( $post ) { $attachment_ids = $this->wpdb->get_col( $this->wpdb->prepare( "SELECT ID FROM {$this->wpdb->posts} WHERE post_type = 'attachment' AND post_parent = %d", $post->ID ) ); foreach ( $attachment_ids as $attachment_id ) { foreach ( $this->sitepress->get_active_languages() as $language_code => $active_language ) { $this->get_media_attachment_duplication()->create_duplicate_attachment( (int) $attachment_id, (int) $post->ID, $language_code ); } } } private function should_duplicate_media() { return \WPML\FP\Obj::prop( 'duplicate_media', \WPML\Media\Option::getNewContentSettings() ); } private function cleanup_display_featured_as_translated_meta() { $this->wpdb->query( "DELETE FROM {$this->wpdb->postmeta} WHERE meta_key = '" . self::FEATURED_AS_TRANSLATED_META_KEY . "'" ); } private function mark_migration_completed() { $this->wpml_upgrade->mark_command_as_executed( $this ); } private function get_media_attachment_duplication() { global $wpml_language_resolution; if ( ! $this->media_attachment_duplication ) { $this->media_attachment_duplication = new WPML_Media_Attachments_Duplication( $this->sitepress, new WPML_Model_Attachments( $this->sitepress, wpml_get_post_status_helper() ), $this->wpdb, $wpml_language_resolution ); } return $this->media_attachment_duplication; } private function acquire_lock() { $lock = get_transient( self::TRANSIENT_DEFERRED_UPGRADE_IN_PROGRESS ); if ( $lock ) { return false; } set_transient( self::TRANSIENT_DEFERRED_UPGRADE_IN_PROGRESS, true, MINUTE_IN_SECONDS ); return true; } private function release_lock() { delete_transient( self::TRANSIENT_DEFERRED_UPGRADE_IN_PROGRESS ); } private function start_timer() { $this->start_time = time(); } private function is_max_time_elapsed() { return self::MAX_TIME <= ( time() - $this->start_time ); } private function remove_notice() { $this->notices->remove_notice( 'default', __CLASS__ ); } private function create_or_refresh_notice() { $notice = $this->notices->create_notice( __CLASS__, $this->get_notice_content() ); $notice->add_display_callback( array( 'WPML_Notice_Show_On_Dashboard_And_WPML_Pages', 'is_on_page' ) ); $notice->set_css_class_types( 'info' ); $this->notices->add_notice( $notice ); } private function has_notice() { return $this->notices->get_notice( __CLASS__, 'default' ); } } commands/class-wpml-tm-upgrade-wpml-site-id-ate.php 0000644 00000003005 14721661642 0016272 0 ustar 00 <?php /** * Upgrades the former option to the new one. */ class WPML_TM_Upgrade_WPML_Site_ID_ATE implements IWPML_Upgrade_Command { /** * Runs the upgrade process. * * @return bool */ public function run() { if ( $this->must_run() ) { $site_id = new WPML_Site_ID(); $old_value = $site_id->get_site_id( WPML_Site_ID::SITE_SCOPES_GLOBAL ); return update_option( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_TM_ATE::SITE_ID_SCOPE, $old_value, false ); } return true; } /** * True if all conditions are met. * * @return bool */ private function must_run() { return WPML_TM_ATE_Status::is_enabled_and_activated() && (bool) get_option( WPML_TM_Wizard_Options::WIZARD_COMPLETE_FOR_MANAGER, false ) && $this->site_id_ate_does_not_exist(); } /** * Checks has the old option. * * @return bool */ protected function site_id_ate_does_not_exist() { get_option( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_TM_ATE::SITE_ID_SCOPE, null ); $notoptions = wp_cache_get( 'notoptions', 'options' ); return ( array_key_exists( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_TM_ATE::SITE_ID_SCOPE, $notoptions ) ); } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * Unused. * * @return null */ public function get_results() { return null; } } commands/AddCountryColumnToLanguages.php 0000644 00000000771 14721661642 0014460 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddCountryColumnToLanguages extends \WPML_Upgrade_Add_Column_To_Table { /** * Get table name. * * @return string */ protected function get_table() { return 'icl_languages'; } /** * Get column name. * * @return string */ protected function get_column() { return 'country'; } /** * Get column definition. * * @return string */ protected function get_column_definition() { return 'VARCHAR(10) NULL DEFAULT NULL'; } } commands/ATEProxyUpdateRewriteRules.php 0000644 00000001305 14721661642 0014261 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands; class ATEProxyUpdateRewriteRules implements \IWPML_Upgrade_Command { /** @var bool $result */ private $result = false; /** * @return bool */ public function run_admin() { // By doing this, we ensure that the rewrite rules get updated for the `ate/widget/script` endpoint. update_option( 'plugin_permalinks_flushed', 0 ); $this->result = true; return $this->result; } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/AddPrimaryKeyToLocaleMap.php 0000644 00000000462 14721661642 0013657 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddPrimaryKeyToLocaleMap extends AddPrimaryKeyToTable { protected function get_table() { return 'icl_locale_map'; } protected function get_key_name() { return 'PRIMARY'; } protected function get_key_columns() { return [ 'code', 'locale' ]; } } commands/CreateBackgroundTaskTable.php 0000644 00000003151 14721661642 0014065 0 ustar 00 <?php namespace WPML\Upgrade\Commands; use WPML\Core\BackgroundTask\Model\BackgroundTask; use SitePress_Setup; class CreateBackgroundTaskTable implements \IWPML_Upgrade_Command { /** @var \WPML_Upgrade_Schema $schema */ private $schema; /** @var bool $result */ private $result = false; public function __construct( array $args ) { $this->schema = $args[0]; } /** * @return bool */ public function run() { $wpdb = $this->schema->get_wpdb(); $table_name = $wpdb->prefix . BackgroundTask::TABLE_NAME; $charset_collate = SitePress_Setup::get_charset_collate(); $query = " CREATE TABLE IF NOT EXISTS `{$table_name}` ( `task_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `task_type` VARCHAR(500) NOT NULL, `task_status` SMALLINT UNSIGNED NOT NULL DEFAULT 0, `starting_date` DATETIME NULL, `total_count` INT UNSIGNED NOT NULL DEFAULT 0, `completed_count` INT UNSIGNED NOT NULL DEFAULT 0, `completed_ids` TEXT NULL DEFAULT NULL, `payload` TEXT NULL DEFAULT NULL, `retry_count` SMALLINT UNSIGNED NOT NULL DEFAULT 0 ) {$charset_collate}; "; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $this->result = $wpdb->query( $query ); return $this->result; } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } } commands/SynchronizeSourceIdOfATEJobs/Repository.php 0000644 00000001252 14721661642 0016654 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands\SynchronizeSourceIdOfATEJobs; class Repository { /** @var \wpdb */ private $wpdb; /** * @param \wpdb $wpdb */ public function __construct( \wpdb $wpdb ) { $this->wpdb = $wpdb; } /** * @return \WPML\Collect\Support\Collection */ public function getPairs() { $sql = " SELECT MAX(editor_job_id) as editor_job_id, rid FROM {$this->wpdb->prefix}icl_translate_job WHERE editor = 'ate' AND editor_job_id IS NOT NULL GROUP BY rid "; $rowset = $this->wpdb->get_results( $sql, ARRAY_A ); $rowset = \wpml_collect( is_array( $rowset ) ? $rowset : [] ); return $rowset->pluck( 'rid', 'editor_job_id' ); } } commands/SynchronizeSourceIdOfATEJobs/Command.php 0000644 00000003372 14721661642 0016060 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands\SynchronizeSourceIdOfATEJobs; use WPML\Utils\Pager; use WPML\TM\Upgrade\Commands\MigrateAteRepository; use WPML\Collect\Support\Collection; use WPML\Upgrade\CommandsStatus; use function WPML\Container\make; class Command implements \IWPML_Upgrade_Command { const CHUNK_SIZE = 1000; /** @var Repository */ private $repository; /** @var \WPML_TM_ATE_API */ private $api; /** @var Pager */ private $pager; /** @var CommandsStatus */ private $commandStatus; /** @var bool $result */ private $result = false; /** * Command constructor. * * @param Repository $repository * @param \WPML_TM_ATE_API $api * @param Pager $pager * @param CommandsStatus $commandStatus */ public function __construct( Repository $repository, \WPML_TM_ATE_API $api, Pager $pager, CommandsStatus $commandStatus ) { $this->repository = $repository; $this->api = $api; $this->pager = $pager; $this->commandStatus = $commandStatus; } public function run_admin() { if ( ! $this->hasBeenMigrateATERepositoryUpgradeRun() ) { return false; } $chunks = $this->repository->getPairs()->chunk( self::CHUNK_SIZE ); $this->result = $this->pager->iterate( $chunks, function ( Collection $pairs ) { return $this->api->migrate_source_id( $pairs->toArray() ); } ) === 0; return $this->result; } public function run_ajax() { return null; } public function run_frontend() { return null; } /** * @return bool */ public function get_results() { return $this->result; } /** * @return mixed */ private function hasBeenMigrateATERepositoryUpgradeRun() { return $this->commandStatus->hasBeenExecuted( MigrateAteRepository::class ); } } commands/SynchronizeSourceIdOfATEJobs/CommandFactory.php 0000644 00000000560 14721661642 0017404 0 ustar 00 <?php namespace WPML\TM\Upgrade\Commands\SynchronizeSourceIdOfATEJobs; use WPML\Utils\Pager; use function WPML\Container\make; class CommandFactory { const PAGER_OPTION_NAME = 'sync-source-id-ate-jobs-pager'; /** * @return Command */ public function create() { return make( Command::class, [ ':pager' => new Pager( self::PAGER_OPTION_NAME, 1 ) ] ); } } commands/wpml-upgrade-admin-users-languages.php 0000644 00000002055 14721661642 0015666 0 ustar 00 <?php class WPML_Upgrade_Admin_Users_Languages { private $sitepress; const ICL_ADMIN_LANGUAGE_MIGRATED_TO_WP_47 = 'icl_admin_language_migrated_to_wp47'; public function __construct( SitePress $sitepress ) { $this->sitepress = $sitepress; $this->add_hooks(); } public function add_hooks() { add_action( 'admin_init', array( $this, 'run' ) ); } public function run() { $user_id = get_current_user_id(); $wpml_user_lang = get_user_meta( $user_id, 'icl_admin_language', true ); $wpml_user_lang_migrated = get_user_meta( $user_id, self::ICL_ADMIN_LANGUAGE_MIGRATED_TO_WP_47, false ); $wpml_user_locale = $this->sitepress->get_locale_from_language_code( $wpml_user_lang ); $wp_user_locale = get_user_meta( $user_id, 'locale', true ); if ( ! $wpml_user_lang_migrated ) { if ( $wpml_user_locale && $wpml_user_locale !== $wp_user_locale ) { update_user_meta( $user_id, 'locale', $wpml_user_locale ); } update_user_meta( $user_id, self::ICL_ADMIN_LANGUAGE_MIGRATED_TO_WP_47, true ); } } } commands/class-disable-options-autoloading.php 0000644 00000002302 14721661642 0015567 0 ustar 00 <?php namespace WPML\Upgrade\Command; class DisableOptionsAutoloading implements \IWPML_Upgrade_Command { /** @var bool */ private $results; public function run() { global $wpdb; $do_not_autoload_options = [ '_icl_cache', 'wp_installer_settings', 'wpml_translation_services', '_wpml_batch_report', ]; $where = 'WHERE option_name IN (' . wpml_prepare_in( $do_not_autoload_options ) . ") AND autoload = 'yes'"; // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $query_result = $wpdb->query( "UPDATE {$wpdb->prefix}options SET autoload = 'no' {$where}" ); // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery $this->results = false !== $query_result; return $this->results; } public function run_admin() { return $this->run(); } public function run_ajax() { return null; } public function run_frontend() { return null; } public function get_results() { return $this->results; } } commands/class-wpml-tm-add-tpid-column-to-translation-status.php 0000644 00000001165 14721661642 0021046 0 ustar 00 <?php class WPML_TM_Add_TP_ID_Column_To_Translation_Status extends WPML_Upgrade_Run_All { /** @var WPML_Upgrade_Schema */ private $upgrade_schema; public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** @return bool */ protected function run() { $table = 'icl_translation_status'; $column = 'tp_id'; if ( $this->upgrade_schema->does_table_exist( $table ) ) { if ( ! $this->upgrade_schema->does_column_exist( $table, $column ) ) { $this->upgrade_schema->add_column( $table, $column, 'INT NULL DEFAULT NULL' ); } } $this->result = true; return $this->result; } } commands/AddStringPackageIdtIndexToStrings.php 0000644 00000000503 14721661642 0015526 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class AddStringPackageIdIndexToStrings extends AddIndexToTable { protected function get_table() { return 'icl_strings'; } protected function get_index() { return 'string_package_id'; } protected function get_index_definition() { return '( `string_package_id` )'; } } commands/abstracts/DropIndexFromTable.php 0000644 00000001534 14721661642 0014550 0 ustar 00 <?php namespace WPML\Upgrade\Commands; abstract class DropIndexFromTable extends \WPML_Upgrade_Run_All { /** * @return string */ abstract protected function get_table(); /** * @return string */ abstract protected function get_index(); /** * @var \WPML_Upgrade_Schema */ private $upgrade_schema; /** * @param array $args */ public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** * @return bool */ protected function run() { $this->result = false; if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) { if ( $this->upgrade_schema->does_index_exist( $this->get_table(), $this->get_index() ) ) { $this->result = $this->upgrade_schema->drop_index( $this->get_table(), $this->get_index() ); } else { $this->result = true; } } return $this->result; } } commands/abstracts/class-add-index-to-table.php 0000644 00000002370 14721661642 0015524 0 ustar 00 <?php /** * Abstract class to upgrade a table by adding a column to it. * * @package WPML */ namespace WPML\Upgrade\Commands; /** * Class Add_Index_To_Table */ abstract class AddIndexToTable extends \WPML_Upgrade_Run_All { /** * Get table name. * * @return string */ abstract protected function get_table(); /** * Get index name. * * @return string */ abstract protected function get_index(); /** * Get index definition. * * @return string */ abstract protected function get_index_definition(); /** * Upgrade schema. * * @var \WPML_Upgrade_Schema */ private $upgrade_schema; /** * Add_Index_To_Table constructor. * * @param array $args */ public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** * Run the table upgrade. * * @return bool */ protected function run() { $this->result = false; if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) { if ( ! $this->upgrade_schema->does_index_exist( $this->get_table(), $this->get_index() ) ) { $this->result = $this->upgrade_schema->add_index( $this->get_table(), $this->get_index(), $this->get_index_definition() ); } else { $this->result = true; } } return $this->result; } } commands/abstracts/class-wpml-upgrade-add-column-to-table.php 0000644 00000003157 14721661642 0020320 0 ustar 00 <?php /** * Abstract class to upgrade a table by adding a column to it. * * @package WPML */ /** * Class WPML_Upgrade_Add_Column_To_Table */ abstract class WPML_Upgrade_Add_Column_To_Table implements IWPML_Upgrade_Command { /** * Get table name. * * @return string */ abstract protected function get_table(); /** * Get column name. * * @return string */ abstract protected function get_column(); /** * Get column definition. * * @return string */ abstract protected function get_column_definition(); /** * Upgrade schema. * * @var WPML_Upgrade_Schema */ private $upgrade_schema; /** * WPML_Upgrade_Add_Column_To_Table constructor. * * @param array $args Arguments. */ public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** * Run the table upgrade. * * @return bool */ private function run() { if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) { if ( ! $this->upgrade_schema->does_column_exist( $this->get_table(), $this->get_column() ) ) { $this->upgrade_schema->add_column( $this->get_table(), $this->get_column(), $this->get_column_definition() ); } } return true; } /** * Run in admin. * * @return bool */ public function run_admin() { return $this->run(); } /** * Run in ajax. * * @return bool */ public function run_ajax() { return $this->run(); } /** * Run in frontend. * * @return bool */ public function run_frontend() { return $this->run(); } /** * Get upgrade results. * * @return bool */ public function get_results() { return true; } } commands/abstracts/AddPrimaryKeyToTable.php 0000644 00000001674 14721661642 0015045 0 ustar 00 <?php namespace WPML\Upgrade\Commands; abstract class AddPrimaryKeyToTable extends \WPML_Upgrade_Run_All { /** * @return string */ abstract protected function get_table(); /** * @return string */ abstract protected function get_key_name(); /** * @return array */ abstract protected function get_key_columns(); /** * @var \WPML_Upgrade_Schema */ private $upgrade_schema; /** * @param array $args */ public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** * @return bool */ protected function run() { $this->result = false; if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) { if ( ! $this->upgrade_schema->does_key_exist( $this->get_table(), $this->get_key_name() ) ) { $this->result = $this->upgrade_schema->add_primary_key( $this->get_table(), $this->get_key_columns() ); } else { $this->result = true; } } return $this->result; } } commands/class-wpml-upgrade-fix-non-admin-cap.php 0000644 00000001302 14721661642 0015775 0 ustar 00 <?php class WPML_Upgrade_Fix_Non_Admin_With_Admin_Cap implements IWPML_Upgrade_Command { private $results = array(); /** * @return bool|void */ public function run_admin() { $user = new WP_User( 'admin' ); if ( $user->exists() && ! is_super_admin( $user->get( 'ID' ) ) ) { $wpml_capabilities = wpml_get_capability_keys(); foreach ( $wpml_capabilities as $capability ) { $user->remove_cap( $capability ); } } return true; } /** * @return bool */ public function run_ajax() { return false; } /** * @return bool */ public function run_frontend() { return false; } /** * @return null */ public function get_results() { return $this->results; } } commands/class-wpml-tm-add-tp-revision-and-ts-status-columns-to-core-status.php 0000644 00000001726 14721661642 0023652 0 ustar 00 <?php class WPML_TM_Add_TP_Revision_And_TS_Status_Columns_To_Core_Status implements IWPML_Upgrade_Command { /** @var WPML_Upgrade_Schema */ private $upgrade_schema; public function __construct( array $args ) { $this->upgrade_schema = $args[0]; } /** @return bool */ private function run() { $table = 'icl_core_status'; $columns = array( 'tp_revision' => 'INT NOT NULL DEFAULT 1', 'ts_status' => 'TEXT NULL DEFAULT NULL', ); if ( $this->upgrade_schema->does_table_exist( $table ) ) { foreach ( $columns as $column => $definition ) { if ( ! $this->upgrade_schema->does_column_exist( $table, $column ) ) { $this->upgrade_schema->add_column( $table, $column, $definition ); } } } return true; } public function run_admin() { return $this->run(); } public function run_ajax() { return null; } public function run_frontend() { return null; } /** @return bool */ public function get_results() { return null; } } commands/class-wpml-upgrade-media-without-language.php 0000644 00000000774 14721661642 0017145 0 ustar 00 <?php class WPML_Upgrade_Media_Without_Language extends WPML_Upgrade_Run_All { /** @var wpdb */ private $wpdb; /** @var string */ private $default_language; public function __construct( array $args ) { $this->wpdb = $args[0]; $this->default_language = $args[1]; } /** @return bool */ protected function run() { $initialize_post_type = new WPML_Initialize_Language_For_Post_Type( $this->wpdb ); return $initialize_post_type->run( 'attachment', $this->default_language ); } } commands/class-wpml-upgrade-wpml-site-id-remaining.php 0000644 00000004221 14721661642 0017055 0 ustar 00 <?php /** * Some sites were not properly upgraded in 4.2.0. * In that case the old option was not deleted * and new site IDs were wrongly created. */ class WPML_Upgrade_WPML_Site_ID_Remaining implements IWPML_Upgrade_Command { /** * @var string * * @see WPML_TM_ATE::SITE_ID_SCOPE */ const SCOPE_ATE = 'ate'; /** * @return bool */ public function run() { if ( $this->old_and_new_options_exist() ) { $value_from_old_option = get_option( WPML_Site_ID::SITE_ID_KEY, null ); $value_from_new_option = get_option( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_Site_ID::SITE_SCOPES_GLOBAL, null ); // 1. We update the global option with the old value. update_option( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_Site_ID::SITE_SCOPES_GLOBAL, $value_from_old_option, false ); // 2. If the ate option has the same value as the new global, we also update it. if ( $this->option_exists( WPML_Site_ID::SITE_ID_KEY . ':' . self::SCOPE_ATE ) ) { $ate_uuid = get_option( WPML_Site_ID::SITE_ID_KEY . ':' . self::SCOPE_ATE, null ); if ( $ate_uuid === $value_from_new_option ) { update_option( WPML_Site_ID::SITE_ID_KEY . ':' . self::SCOPE_ATE, $value_from_old_option, false ); } } return delete_option( WPML_Site_ID::SITE_ID_KEY ); } return true; } /** * @return bool */ protected function old_and_new_options_exist() { return $this->option_exists( WPML_Site_ID::SITE_ID_KEY ) && $this->option_exists( WPML_Site_ID::SITE_ID_KEY . ':' . WPML_Site_ID::SITE_SCOPES_GLOBAL ); } /** * @param string $key * * @return bool */ private function option_exists( $key ) { get_option( $key, null ); $notoptions = wp_cache_get( 'notoptions', 'options' ); return false === $notoptions || ! array_key_exists( $key, $notoptions ); } /** * Runs in admin pages. * * @return bool */ public function run_admin() { return $this->run(); } /** * Unused. * * @return null */ public function run_ajax() { return null; } /** * Unused. * * @return null */ public function run_frontend() { return null; } /** * Unused. * * @return null */ public function get_results() { return null; } } commands/RemoveEndpointsOption.php 0000644 00000000304 14721661642 0013376 0 ustar 00 <?php namespace WPML\Upgrade\Commands; class RemoveEndpointsOption extends \WPML_Upgrade_Run_All { public function run() { delete_option( 'wpml_registered_endpoints' ); return true; } } class-wpml-upgrade.php 0000644 00000014256 14721661642 0011005 0 ustar 00 <?php use WPML\Upgrade\CommandsStatus; class WPML_Upgrade { const SCOPE_ADMIN = 'admin'; const SCOPE_AJAX = 'ajax'; const SCOPE_FRONT_END = 'front-end'; /** @var array */ private $commands; const UPDATE_STATUSES_KEY = 'wpml_update_statuses'; /** @var SitePress */ private $sitepress; /** @var WPML_Upgrade_Command_Factory */ private $command_factory; /** @var CommandsStatus */ private $command_status; /** @var bool $upgrade_in_progress */ private $upgrade_in_progress; /** * WPML_Upgrade constructor. * * @param array $commands * @param SitePress $sitepress * @param WPML_Upgrade_Command_Factory $command_factory * @param CommandsStatus $command_status */ public function __construct( array $commands, SitePress $sitepress, WPML_Upgrade_Command_Factory $command_factory, CommandsStatus $command_status = null ) { $this->add_commands( $commands ); $this->sitepress = $sitepress; $this->command_factory = $command_factory; $this->command_status = $command_status ?: new CommandsStatus(); } /** * @param array $commands */ public function add_commands( array $commands ) { foreach ( $commands as $command ) { if ( $command instanceof WPML_Upgrade_Command_Definition ) { $this->commands[] = $command; } } } public function run() { $result = false; /** * Add commands to the upgrade logic. * * The filter must be added before the `wpml_loaded` action is fired (the action is fired on `plugins_loaded`). * * @param array $commands An empty array. * @return array Array of classes created with \wpml_create_upgrade_command_definition. * * @since 4.1.0 * @see \wpml_create_upgrade_command_definition */ $new_commands = apply_filters( 'wpml_upgrade_commands', array() ); if ( $new_commands && is_array( $new_commands ) ) { $this->add_commands( $new_commands ); } if ( $this->sitepress->get_wp_api()->is_admin() ) { if ( $this->sitepress->get_wp_api()->is_ajax() ) { $result = $this->run_ajax(); } else { $result = $this->run_admin(); } } elseif ( $this->sitepress->get_wp_api()->is_front_end() ) { $result = $this->run_front_end(); } $this->set_upgrade_completed(); return $result; } private function get_commands_by_scope( $scope ) { $results = array(); /** @var WPML_Upgrade_Command_Definition $command */ foreach ( $this->commands as $command ) { if ( in_array( $scope, $command->get_scopes(), true ) ) { $results[] = $command; } } return $results; } private function get_admin_commands() { return $this->get_commands_by_scope( self::SCOPE_ADMIN ); } private function get_ajax_commands() { return $this->get_commands_by_scope( self::SCOPE_AJAX ); } private function get_front_end_commands() { return $this->get_commands_by_scope( self::SCOPE_FRONT_END ); } private function run_admin() { return $this->run_commands( $this->get_admin_commands(), 'maybe_run_admin' ); } private function run_ajax() { return $this->run_commands( $this->get_ajax_commands(), 'maybe_run_ajax' ); } private function run_front_end() { return $this->run_commands( $this->get_front_end_commands(), 'maybe_run_front_end' ); } private function run_commands( $commands, $default ) { $results = array(); /** @var WPML_Upgrade_Command_Definition $command */ foreach ( $commands as $command ) { $results[] = $this->run_command( $command, $default ); } return $results; } private function run_command( WPML_Upgrade_Command_Definition $command_definition, $default ) { $method = $default; if ( $command_definition->get_method() ) { $method = $command_definition->get_method(); } if ( ! $this->command_status->hasBeenExecuted( $command_definition->get_class_name() ) ) { $this->set_upgrade_in_progress(); $upgrade = $command_definition->create(); return $this->$method( $upgrade ); } return null; } /** @noinspection PhpUnusedPrivateMethodInspection * @param IWPML_Upgrade_Command $upgrade * * @return null */ private function maybe_run_admin( IWPML_Upgrade_Command $upgrade ) { if ( $upgrade->run_admin() ) { $this->mark_command_as_executed( $upgrade ); } return $upgrade->get_results(); } /** @noinspection PhpUnusedPrivateMethodInspection * @param IWPML_Upgrade_Command $upgrade * * @return null */ private function maybe_run_front_end( IWPML_Upgrade_Command $upgrade ) { if ( $upgrade->run_frontend() ) { $this->mark_command_as_executed( $upgrade ); } return $upgrade->get_results(); } /** @noinspection PhpUnusedPrivateMethodInspection * @param IWPML_Upgrade_Command $upgrade * * @return null */ private function maybe_run_ajax( IWPML_Upgrade_Command $upgrade ) { if ( $this->nonce_ok( $upgrade ) && $upgrade->run_ajax() ) { $this->mark_command_as_executed( $upgrade ); $this->sitepress->get_wp_api()->wp_send_json_success( '' ); } return $upgrade->get_results(); } private function nonce_ok( $class ) { $class_name = get_class( $class ); if ( ! $class_name ) { return false; } $class_name = $this->get_command_id( $class_name ); if ( isset( $_POST['action'] ) && $_POST['action'] === $class_name ) { $nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( $this->sitepress->get_wp_api()->wp_verify_nonce( $nonce, $class_name . '-nonce' ) ) { return true; } } return false; } /** * @param IWPML_Upgrade_Command $class */ public function mark_command_as_executed( IWPML_Upgrade_Command $class ) { $this->command_status->markAsExecuted( get_class( $class ) ); } /** * @param string $class_name * * @return string */ private function get_command_id( $class_name ) { return str_replace( '_', '-', strtolower( $class_name ) ); } private function set_upgrade_in_progress() { if ( ! $this->upgrade_in_progress ) { $this->upgrade_in_progress = true; set_transient( WPML_Upgrade_Loader::TRANSIENT_UPGRADE_IN_PROGRESS, true, MINUTE_IN_SECONDS ); } } private function set_upgrade_completed() { if ( $this->upgrade_in_progress ) { $this->upgrade_in_progress = false; delete_transient( WPML_Upgrade_Loader::TRANSIENT_UPGRADE_IN_PROGRESS ); } } } class-wpml-tm-upgrade-loader.php 0000644 00000005473 14721661642 0012670 0 ustar 00 <?php use WPML\TM\Menu\TranslationServices\Troubleshooting\RefreshServicesFactory; use WPML\API\Version; class WPML_TM_Upgrade_Loader implements IWPML_Action { /** @var SitePress */ private $sitepress; /** @var WPML_Upgrade_Schema */ private $upgrade_schema; /** @var WPML_Settings_Helper */ private $settings; /** @var WPML_Upgrade_Command_Factory */ private $factory; /** @var WPML_Notices */ private $notices; public function __construct( SitePress $sitepress, WPML_Upgrade_Schema $upgrade_schema, WPML_Settings_Helper $settings, WPML_Notices $wpml_notices, WPML_Upgrade_Command_Factory $factory ) { $this->sitepress = $sitepress; $this->upgrade_schema = $upgrade_schema; $this->settings = $settings; $this->notices = $wpml_notices; $this->factory = $factory; } public function add_hooks() { add_action( 'init', array( $this, 'wpml_tm_upgrade' ) ); } public function wpml_tm_upgrade() { $commands = array( $this->factory->create_command_definition( 'WPML_TM_Upgrade_Translation_Priorities_For_Posts', array(), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( 'WPML_TM_Upgrade_Default_Editor_For_Old_Jobs', array( $this->sitepress ), array( 'admin', 'ajax', 'front-end' ) ), $this->factory->create_command_definition( 'WPML_TM_Upgrade_Service_Redirect_To_Field', array(), array( 'admin' ) ), $this->factory->create_command_definition( 'WPML_TM_Upgrade_WPML_Site_ID_ATE', array( $this->upgrade_schema ), array( 'admin' ) ), $this->factory->create_command_definition( 'WPML_TM_Upgrade_Cancel_Orphan_Jobs', array( new WPML_TP_Sync_Orphan_Jobs_Factory(), new WPML_TM_Jobs_Migration_State() ), array( 'admin' ) ), $this->factory->create_command_definition( WPML\TM\Upgrade\Commands\MigrateAteRepository::class, [ $this->upgrade_schema ], [ 'admin' ] ), $this->factory->create_command_definition( WPML\TM\Upgrade\Commands\SynchronizeSourceIdOfATEJobs\Command::class, [], [ 'admin' ], null, [ new WPML\TM\Upgrade\Commands\SynchronizeSourceIdOfATEJobs\CommandFactory(), 'create' ] ), $this->factory->create_command_definition( WPML\TM\Upgrade\Commands\CreateAteDownloadQueueTable::class, [ $this->upgrade_schema ], [ 'admin' ] ), $this->factory->create_command_definition( WPML\TM\Upgrade\Commands\RefreshTranslationServices::class, [ \WPML\Container\make( RefreshServicesFactory::class ), Version::isHigherThanInstallation() ], [ 'admin' ] ), $this->factory->create_command_definition( WPML\TM\Upgrade\Commands\ATEProxyUpdateRewriteRules::class, [], [ \WPML_Upgrade::SCOPE_ADMIN ] ), ); $upgrade = new WPML_Upgrade( $commands, $this->sitepress, $this->factory ); $upgrade->run(); } } CommandsStatus.php 0000644 00000002211 14721661642 0010227 0 ustar 00 <?php namespace WPML\Upgrade; class CommandsStatus { const OPTION_KEY = 'wpml_update_statuses'; /** * @param string $className * * @return bool */ public function hasBeenExecuted( $className ) { return (bool) $this->get_update_option_value( $this->get_command_id( $className ) ); } /** * @param string $className * @param bool $flag */ public function markAsExecuted( $className, $flag = true ) { $this->set_update_status( $this->get_command_id( $className ), $flag ); wp_cache_flush(); } /** * @param string $className * * @return string */ private function get_command_id( $className ) { return str_replace( '_', '-', strtolower( $className ) ); } private function set_update_status( $id, $value ) { $update_options = get_option( self::OPTION_KEY, array() ); $update_options[ $id ] = $value; update_option( self::OPTION_KEY, $update_options, true ); } private function get_update_option_value( $id ) { $update_options = get_option( self::OPTION_KEY, array() ); if ( $update_options && array_key_exists( $id, $update_options ) ) { return $update_options[ $id ]; } return null; } } class-wpml-tm-upgrade-loader-factory.php 0000644 00000000533 14721661642 0014325 0 ustar 00 <?php class WPML_TM_Upgrade_Loader_Factory implements IWPML_Backend_Action_Loader, IWPML_Frontend_Action_Loader { public function create() { global $sitepress, $wpdb; return new WPML_TM_Upgrade_Loader( $sitepress, wpml_get_upgrade_schema(), wpml_load_settings_helper(), wpml_get_admin_notices(), new WPML_Upgrade_Command_Factory() ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0.03 |
proxy
|
phpinfo
|
Настройка