first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
jQuery(function () {
jQuery('#icl-migrate-start').one('click', function () {
iclStepper(jQuery(this).attr('href'), '&init=1', true);
return false;
});
});
function iclStepper(href, addUrl, init) {
init = typeof(init) != 'undefined' ? true : false;
jQuery.ajax({
type: "POST",
url: href+addUrl,
cache: false,
dataType: 'json',
success: function(data) {
if (data.stop == true) {
jQuery('#icl-migrate-progress .message').html('stopped');
} else if (data.error == false) {
if (init == true) {
jQuery('#icl-migrate-start').fadeOut(function(){
jQuery('#icl-migrate-progress').fadeIn().html(data.output).children('.message').html(data.message);
iclStepper(href, '&step='+data.step);
});
// jQuery('#icl-migrate-progress').html(data.output).children('.message').html(data.message);
} else {
jQuery('#icl-migrate-progress .message').html(data.message);
jQuery('#icl-migrate-progress .progress').animate({
width : data.barWidth+'%'
}, 100);
if (data.completed == true) {
jQuery('#icl-migrate').delay(3000).fadeOut();
} else {
iclStepper(href, '&step='+data.step);
}
}
} else {
alert('error');
jQuery('#icl-migrate-progress .message').html(data.error);
}
}
});
}

View File

@@ -0,0 +1,116 @@
<?php
class Icl_Stepper {
/**
* Added dummy element to match number of elements and to cover init action
*
* @var array
*/
protected $_steps = array( null );
/**
* Current step
*
* @var int
*/
protected $_step;
/**
* Next step can be forced with Icl_Stepper::setNextStep()
*
* @var int
*/
protected $_nextStep = null;
/**
* Provide current step here
*
* @param int $step
*/
function __construct( $step = 0 ) {
if ( empty( $step ) ) {
$step = 0;
}
$this->_step = intval( $step );
}
/**
* Register steps (function names)
*/
public function registerSteps() {
$args = func_get_args();
$this->_steps = array_merge( $this->_steps, $args );
}
/**
* Returns current step
*
* @return int
*/
public function getStep() {
return $this->_step;
}
/**
* Returns next step
*
* @return int
*/
public function getNextStep() {
return ! is_null( $this->_nextStep ) ? $this->_nextStep : $this->_step += 1;
}
/**
* Sets current step
*
* @param int $num
*/
public function setStep( $num ) {
$this->_step = intval( $num );
}
/**
* Forcing next step
*
* @param int $num
*/
public function setNextStep( $num ) {
$this->_nextStep = intval( $num );
}
/**
* Calculates bar width
*
* @return int Should be used as percentage width (%)
*/
public function barWidth() {
return round( ( $this->_step * 100 ) / count( $this->_steps ) );
}
/**
* Calls current step's function
*
* @return mixed
*/
public function init() {
if ( $this->_step !== 0 && isset( $this->_steps[ $this->_step ] )
&& is_callable( $this->_steps[ $this->_step ] ) ) {
return call_user_func_array( $this->_steps[ $this->_step ], array( $this->_step, $this ) );
}
}
/**
* Returns initial HTML formatted screen
*
* @param string $message Message to be displayed
* @return string
*/
public function render( $message = '' ) {
$output = '<div class="progress-bar" style="width: 100%; height: 15px; background-color: #FFFFFFF; border: 1px solid #e6db55;">
<div class="progress" style="height: 100%; background-color: Yellow; width: ' . $this->barWidth() . '%;"></div>
</div>
<div class="message" style="clear:both;">' . $message . '</div>';
return $output;
}
}

View File

@@ -0,0 +1,92 @@
<?php
function update_string_statuses() {
global $wpdb;
$wpdb->update(
$wpdb->prefix . 'icl_string_translations',
array(
'status' => ICL_TM_COMPLETE,
'batch_id' => 0,
),
array(
'batch_id' => -1,
'status' => 1,
)
);
$wpdb->update(
$wpdb->prefix . 'icl_string_translations',
array(
'status' => ICL_TM_NEEDS_UPDATE,
'batch_id' => 0,
),
array(
'batch_id' => -1,
'status' => 2,
)
);
$wpdb->update(
$wpdb->prefix . 'icl_string_translations',
array(
'status' => ICL_TM_WAITING_FOR_TRANSLATOR,
'batch_id' => 0,
),
array(
'batch_id' => -1,
'status' => 11,
)
);
$sql = "ALTER TABLE `{$wpdb->prefix}icl_string_translations` CHANGE batch_id batch_id int DEFAULT 0 NOT NULL;";
$wpdb->query( $sql );
}
function fix_icl_string_status() {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}icl_strings s
SET s.status = %d
WHERE EXISTS ( SELECT 1
FROM {$wpdb->prefix}icl_string_translations st
WHERE string_id = s.id AND st.status = %d )",
ICL_TM_NEEDS_UPDATE,
ICL_TM_NEEDS_UPDATE
)
);
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}icl_strings s
SET s.status = %d
WHERE ( SELECT COUNT(string_id)
FROM {$wpdb->prefix}icl_string_translations st
WHERE st.string_id = s.id AND st.status = %d ) = (( SELECT COUNT(*)
FROM {$wpdb->prefix}icl_languages
WHERE active = 1) - 1)",
ICL_TM_COMPLETE,
ICL_TM_COMPLETE
)
);
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}icl_strings s
SET s.status = %d
WHERE ( SELECT COUNT(string_id)
FROM {$wpdb->prefix}icl_string_translations st
WHERE st.string_id = s.id AND st.status = %d ) < (( SELECT COUNT(*)
FROM {$wpdb->prefix}icl_languages
WHERE active = 1) - 1)
AND ( SELECT COUNT(string_id)
FROM {$wpdb->prefix}icl_string_translations st2
WHERE st2.string_id = s.id AND st2.status = %d ) > 0 ",
2,
ICL_TM_COMPLETE,
ICL_TM_COMPLETE
)
);
}

View File

@@ -0,0 +1,319 @@
<?php
function icl_upgrade_2_0_0_steps( $step, $stepper ) {
global $wpdb, $sitepress, $wp_post_types, $sitepress_settings;
if ( ! isset( $sitepress ) ) {
$sitepress = new SitePress();
}
$TranslationManagement = new TranslationManagement();
$default_language = $sitepress->get_default_language();
define( 'ICL_TM_DISABLE_ALL_NOTIFICATIONS', true ); // make sure no notifications are being sent
ini_set( 'max_execution_time', 300 );
$post_types = array_keys( $wp_post_types );
foreach ( $post_types as $pt ) {
$types[] = 'post_' . $pt;
}
$temp_upgrade_data = get_option(
'icl_temp_upgrade_data',
array(
'step' => 0,
'offset' => 0,
)
);
switch ( $step ) {
case 1:
// if the tables are missing, call the plugin activation routine
$table_name = $wpdb->prefix . 'icl_translation_status';
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) != $table_name ) {
icl_sitepress_activate();
}
$wpdb->query( "ALTER TABLE `{$wpdb->prefix}icl_translations` CHANGE `element_type` `element_type` VARCHAR( 32 ) NOT NULL DEFAULT 'post_post'" );
$wpdb->query( "ALTER TABLE `{$wpdb->prefix}icl_translations` CHANGE `element_id` `element_id` BIGINT( 20 ) NULL DEFAULT NULL " );
// fix source_language_code
// all source documents must have null
if ( isset( $types ) ) {
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}icl_translations SET source_language_code = NULL
WHERE element_type IN('" . join( "','", $types ) . "') AND source_language_code = '' AND language_code=%s",
$default_language
)
);
// get translated documents with missing source language
$res = $wpdb->get_results(
$wpdb->prepare(
"
SELECT translation_id, trid, language_code
FROM {$wpdb->prefix}icl_translations
WHERE (source_language_code = '' OR source_language_code IS NULL)
AND element_type IN('" . join( "','", $types ) . "')
AND language_code <> %s
",
$default_language
)
);
foreach ( $res as $row ) {
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}icl_translations SET source_language_code = %s WHERE translation_id=%d", $default_language, $row->translation_id ) );
}
}
$temp_upgrade_data['step'] = 2;
update_option( 'icl_temp_upgrade_data', $temp_upgrade_data );
return array( 'message' => __( 'Processing translations...', 'sitepress' ) );
break;
case 2:
$limit = 100;
$offset = $temp_upgrade_data['offset'];
$processing = false;
// loop existing translations
if ( isset( $types ) ) {
$res = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}icl_translations
WHERE element_type IN(" . wpml_prepare_in( $types ) . ' )
AND source_language_code IS NULL LIMIT %d OFFSET %d',
array( $limit, $offset )
)
);
foreach ( $res as $row ) {
$processing = true;
// grab translations
$translations = $sitepress->get_element_translations( $row->trid, $row->element_type );
$md5 = 0;
$table_name = $wpdb->prefix . 'icl_node';
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {
list($md5, $links_fixed) = $wpdb->get_row(
$wpdb->prepare(
"
SELECT md5, links_fixed FROM {$wpdb->prefix}icl_node
WHERE nid = %d
",
$row->element_id
),
ARRAY_N
);
}
if ( ! $md5 ) {
$md5 = $TranslationManagement->post_md5( $row->element_id );
}
$translation_package = $TranslationManagement->create_translation_package( $row->element_id );
foreach ( $translations as $lang => $t ) {
if ( ! $t->original ) {
// determine service and status
$service = 'local';
$needs_update = 0;
list($rid, $status, $current_md5) = $wpdb->get_row(
$wpdb->prepare(
"
SELECT c.rid, n.status , c.md5
FROM {$wpdb->prefix}icl_content_status c
JOIN {$wpdb->prefix}icl_core_status n ON c.rid = n.rid
WHERE c.nid = %d AND target = %s
ORDER BY rid DESC
LIMIT 1
",
$row->element_id,
$lang
),
ARRAY_N
);
$translator_id = false;
if ( $rid ) {
if ( $current_md5 != $md5 ) {
$needs_update = 1;
}
if ( $status == 3 ) {
$status = 10;
} else {
$status = 2;
}
$service = 'icanlocalize';
foreach ( $sitepress_settings['icl_lang_status'] as $lpair ) {
if ( $lpair['from'] == $row->language_code && $lpair['to'] == $lang && isset( $lpair['translators'][0]['id'] ) ) {
$translator_id = $lpair['translators'][0]['id'];
break;
}
}
} else {
$status = 10;
$translator_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_author FROM {$wpdb->posts} WHERE ID=%d", $t->element_id ) );
$tlp = get_user_meta( $translator_id, $wpdb->prefix . 'language_pairs', true );
$tlp[ $row->language_code ][ $lang ] = 1;
if ( method_exists( $TranslationManagement, 'edit_translator' ) ) {
$TranslationManagement->edit_translator( $translator_id, $tlp );
}
}
// add translation_status record
list($newrid) = $TranslationManagement->update_translation_status(
array(
'translation_id' => $t->translation_id,
'status' => $status,
'translator_id' => $translator_id,
'needs_update' => $needs_update,
'md5' => $md5,
'translation_service' => $service,
'translation_package' => serialize( $translation_package ),
'links_fixed' => intval( isset( $links_fixed ) ? $links_fixed : 0 ),
)
);
$job_id = $TranslationManagement->add_translation_job( $newrid, $translator_id, $translation_package );
if ( $job_id && $status == 10 ) {
do_action( 'wpml_save_job_fields_from_post', $job_id );
}
}
}
}
}
if ( $processing ) {
update_option(
'icl_temp_upgrade_data',
array(
'step' => 2,
'offset' => intval( $offset + 100 ),
)
);
$stepper->setNextStep( 2 );
} else {
update_option(
'icl_temp_upgrade_data',
array(
'step' => 3,
'offset' => 99999999999999999999,
)
);
}
$message = $processing ? __( 'Processing translations...', 'sitepress' ) : __( 'Finalizing upgrade...', 'sitepress' );
return array( 'message' => $message );
break;
case 3:
// removing the plugins text table; importing data into a SitePress setting
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_plugins_texts" );
if ( ! empty( $results ) ) {
foreach ( $results as $row ) {
$cft[ $row->attribute_name ] = $row->translate + 1;
}
if ( isset( $cft ) ) {
$iclsettings['translation-management']['custom_fields_translation'] = $cft;
$sitepress->save_settings( $iclsettings );
}
$wpdb->query( "DROP TABLE {$wpdb->prefix}icl_plugins_texts" );
}
$iclsettings['language_selector_initialized'] = 1;
if ( get_option( '_force_mp_post_http' ) ) {
$iclsettings['troubleshooting_options']['http_communication'] = intval( get_option( '_force_mp_post_http' ) );
delete_option( '_force_mp_post_http' );
}
$sitepress->save_settings( $iclsettings );
$iclsettings['migrated_2_0_0'] = 1;
$sitepress->save_settings( $iclsettings );
delete_option( 'icl_temp_upgrade_data' );
return array(
'message' => __( 'Done', 'sitepress' ),
'completed' => 1,
);
break;
default:
return array(
'error' => __( 'Missing step', 'sitepress' ),
'stop' => 1,
);
}
}
// $iclsettings defined in upgrade.php
if ( empty( $iclsettings['migrated_2_0_0'] ) ) {
wp_enqueue_script( 'icl-stepper', ICL_PLUGIN_URL . '/inc/upgrade-functions/2.0.0/stepper.js', array( 'jquery' ) );
add_filter( 'admin_notices', 'icl_migrate_2_0_0' );
add_action( 'icl_ajx_custom_call', 'icl_ajx_upgrade_2_0_0', 1, 2 );
}
function icl_migrate_2_0_0() {
$ajax_action = 'wpml_upgrade_2_0_0';
$ajax_action_none = wp_create_nonce( $ajax_action );
$link = 'index.php?icl_ajx_action=' . $ajax_action . '&nonce=' . $ajax_action_none;
$txt = get_option( 'icl_temp_upgrade_data', false ) ? __( 'Resume Upgrade Process', 'sitepress' ) : __( 'Run Upgrade Process', 'sitepress' );
echo '<div class="message error" id="icl-migrate"><p><strong>' . __( 'WPML requires database upgrade', 'sitepress' ) . '</strong></p>'
. '<p>' . __( 'This normally takes a few seconds, but may last up to several minutes of very large databases.', 'sitepress' ) . '</p>'
. '<p><a href="' . $link . '" style="" id="icl-migrate-start">' . $txt . '</a></p>'
. '<div id="icl-migrate-progress" style="display:none; margin: 10px 0 20px 0;">'
. '</div></div>';
}
function icl_ajx_upgrade_2_0_0( $call, $request ) {
if ( $call == 'wpml_upgrade_2_0_0' ) {
$error = 0;
$completed = 0;
$stop = 0;
$message = __( 'Starting the upgrade process...', 'sitepress' );
include_once WPML_PLUGIN_PATH . '/inc/upgrade-functions/2.0.0/stepper.php';
include_once WPML_PLUGIN_PATH . '/inc/upgrade-functions/upgrade-2.0.0.php';
$temp_upgrade_data = get_option(
'icl_temp_upgrade_data',
array(
'step' => 0,
'offset' => 0,
)
);
$step = isset( $request['step'] ) ? $request['step'] : $temp_upgrade_data['step'];
$migration = new Icl_Stepper( $step );
$migration->registerSteps(
'icl_upgrade_2_0_0_steps',
'icl_upgrade_2_0_0_steps',
'icl_upgrade_2_0_0_steps'
);
if ( isset( $request['init'] ) ) {
echo json_encode(
array(
'error' => $error,
'output' => $migration->render(),
'step' => $migration->getNextStep(),
'message' => __( 'Creating new tables...', 'sitepress' ),
'stop' => $stop,
)
);
exit;
}
$data = $migration->init();
@extract( $data, EXTR_OVERWRITE );
echo json_encode(
array(
'error' => $error,
'completed' => $completed,
'message' => $message,
'step' => $migration->getNextStep(),
'barWidth' => $migration->barWidth(),
'stop' => $stop,
)
);
}
}

View File

@@ -0,0 +1,8 @@
<?php
global $wpdb;
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['remember_language'] = 24;
update_option( 'icl_sitepress_settings', $iclsettings );
$wpdb->update( $wpdb->prefix . 'icl_languages', array( 'default_locale' => 'it_IT' ), array( 'code' => 'it' ) );

View File

@@ -0,0 +1,10 @@
<?php
global $wpdb;
$iclsettings = get_option( 'icl_sitepress_settings' );
if ( is_array( $iclsettings['translation-management']['custom_fields_readonly_config'] ) ) {
$iclsettings['translation-management']['custom_fields_readonly_config'] = array_unique( $iclsettings['translation-management']['custom_fields_readonly_config'] );
update_option( 'icl_sitepress_settings', $iclsettings );
}
delete_option( $wpdb->prefix . 'icl_translators_cached' );
delete_option( $wpdb->prefix . 'icl_non_translators_cached' );

View File

@@ -0,0 +1,33 @@
<?php
global $wpdb;
$icl_rc_widget = get_option( 'widget_recent_comments' );
if ( ! empty( $icl_rc_widget ) ) {
$rc_widgets = get_option( 'widget_recent-comments' );
if ( ! empty( $rc_widgets ) ) {
$rc_widgets[] = $icl_rc_widget;
} else {
$rc_widgets = array(
'1' => $icl_rc_widget,
'_multiwidget' => 1,
);
}
update_option( 'widget_recent-comments', $rc_widgets );
delete_option( 'widget_recent_comments' );
}
$wpdb->query( "ALTER TABLE {$wpdb->prefix}icl_string_translations MODIFY COLUMN value TEXT NULL DEFAULT NULL" );
$wpdb->query( "ALTER TABLE {$wpdb->prefix}icl_string_translations ADD translator_id bigint(20) NULL DEFAULT NULL, ADD translation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP" );
// Disable the auto registration of strings if we are upgrading to 2.3.0
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['st']['icl_st_auto_reg'] = 'disable';
update_option( 'icl_sitepress_settings', $iclsettings );
// The icl_translators_cached format has change at some point.
// Let's clear the cache so it gets rebuilt.
delete_option( $wpdb->prefix . 'icl_translators_cached' );
delete_option( $wpdb->prefix . 'icl_non_translators_cached' );

View File

@@ -0,0 +1,19 @@
<?php
global $wpdb;
$iclsettings = get_option( 'icl_sitepress_settings' );
if ( $iclsettings['theme_localization_type'] == 2 && ! empty( $iclsettings['gettext_theme_domain_name'] ) ) {
$iclsettings['theme_localization_load_textdomain'] = 1;
update_option( 'icl_sitepress_settings', $iclsettings );
} elseif ( empty( $iclsettings['theme_localization_type'] ) ) {
$iclsettings['theme_localization_type'] = 2;
$iclsettings['theme_localization_load_textdomain'] = 0;
update_option( 'icl_sitepress_settings', $iclsettings );
}
$sql = "ALTER TABLE {$wpdb->prefix}icl_locale_map CHANGE locale VARCHAR(32) NOT NULL";
$wpdb->query( $sql );
$wpdb->query( "DELETE m FROM {$wpdb->postmeta} m JOIN {$wpdb->posts} p ON p.ID = m.post_id WHERE m.meta_key='_alp_processed' AND p.post_type='nav_menu_item'" );

View File

@@ -0,0 +1,2 @@
<?php
delete_option( 'category_children' );

View File

@@ -0,0 +1,10 @@
<?php
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['st']['translated-users'] = array_keys( $wp_roles->roles );
update_option( 'icl_sitepress_settings', $iclsettings );

View File

@@ -0,0 +1,13 @@
<?php
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['translated_document_page_url'] = 'auto-generate';
$iclsettings['sync_comments_on_duplicates'] = 0;
update_option( 'icl_sitepress_settings', $iclsettings );
global $wpdb;
$sql = "ALTER TABLE {$wpdb->prefix}icl_languages ADD COLUMN encode_url TINYINT(1) NOT NULL DEFAULT 0";
$wpdb->query( $sql );
$encurls = array( 'ru', 'uk', 'zh-hans', 'zh-hant', 'ja', 'ko', 'vi', 'th', 'he', 'ar', 'el', 'fa' );
$sql = "UPDATE {$wpdb->prefix}icl_languages SET encode_url = 1 WHERE code IN ('" . join( "','", $encurls ) . "')";
$wpdb->query( $sql );

View File

@@ -0,0 +1,19 @@
<?php
global $wpdb;
$sql = "UPDATE {$wpdb->prefix}icl_flags SET flag = 'eo.png' WHERE lang_code = 'eo' AND flag = 'nil.png' ";
$wpdb->query( $sql );
$sql = "UPDATE {$wpdb->prefix}icl_flags SET flag = 'qu.png' WHERE lang_code = 'qu' AND flag = 'nil.png' ";
$wpdb->query( $sql );
$sql = "UPDATE {$wpdb->prefix}icl_flags SET flag = 'zu.png' WHERE lang_code = 'zu' AND flag = 'nil.png' ";
$wpdb->query( $sql );
$cols = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}icl_languages" );
if ( empty( $cols[6] ) || $cols[6]->Field != 'encode_url' ) {
$sql = "ALTER TABLE {$wpdb->prefix}icl_languages ADD COLUMN encode_url TINYINT(1) NOT NULL DEFAULT 0";
$wpdb->query( $sql );
$encurls = array( 'ru', 'uk', 'zh-hans', 'zh-hant', 'ja', 'ko', 'vi', 'th', 'he', 'ar', 'el', 'fa' );
$sql = "UPDATE {$wpdb->prefix}icl_languages SET encode_url = 1 WHERE code IN ('" . join( "','", $encurls ) . "')";
$wpdb->query( $sql );
}

View File

@@ -0,0 +1,9 @@
<?php
global $wpdb;
$sql = "ALTER TABLE `{$wpdb->prefix}icl_translations` CHANGE `element_type` `element_type` VARCHAR( 36 ) NOT NULL DEFAULT 'post_post'";
$wpdb->query( $sql );
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['seo']['head_langs'] = 1;
update_option( 'icl_sitepress_settings', $iclsettings );

View File

@@ -0,0 +1,13 @@
<?php
global $wpdb;
$sql = "ALTER TABLE `{$wpdb->prefix}icl_strings` CHANGE `language` `language` VARCHAR( 7 ) NOT NULL";
$wpdb->query( $sql );
$sql = "ALTER TABLE `{$wpdb->prefix}icl_locale_map` CHANGE `code` `code` VARCHAR( 7 ) NOT NULL";
$wpdb->query( $sql );
$iclsettings = get_option( 'icl_sitepress_settings' );
$iclsettings['posts_slug_translation']['on'] = 0;
update_option( 'icl_sitepress_settings', $iclsettings );

View File

@@ -0,0 +1,14 @@
<?php
global $wpdb;
$keys = $wpdb->get_results( "SHOW KEYS FROM `{$wpdb->prefix}icl_translations` WHERE `Column_name`='trid' AND `Key_name`<>'trid_lang'" );
if ( empty( $keys ) ) {
$sql = "ALTER TABLE `{$wpdb->prefix}icl_translations` ADD KEY `trid` (`trid`)";
$wpdb->query( $sql );
}
$sql = "ALTER TABLE `{$wpdb->prefix}icl_languages` ADD tag VARCHAR(8)";
$wpdb->query( $sql );
$sql = "UPDATE `{$wpdb->prefix}icl_languages` SET tag = REPLACE(default_locale, '_', '-')";
$wpdb->query( $sql );
icl_cache_clear();

View File

@@ -0,0 +1,17 @@
<?php
global $wpdb;
$widget_strings = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_strings WHERE context = 'Widgets' AND name LIKE 'widget body - %'" );
foreach ( $widget_strings as $string ) {
$wpdb->update( $wpdb->prefix . 'icl_strings', array( 'name' => 'widget body - ' . md5( $string->value ) ), array( 'id' => $string->id ) );
}
$widget_strings = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_strings WHERE context = 'Widgets' AND name LIKE 'widget title - %'" );
foreach ( $widget_strings as $string ) {
$wpdb->update( $wpdb->prefix . 'icl_strings', array( 'name' => 'widget title - ' . md5( $string->value ) ), array( 'id' => $string->id ) );
}
// Add a new `language_context` index to icl_strings table
$sql = "ALTER TABLE `{$wpdb->prefix}icl_strings` ADD INDEX `language_context` ( `context` , `language` )";
$wpdb->query( $sql );

View File

@@ -0,0 +1,66 @@
<?php
global $wpdb;
$ms = array(
'code' => 'ms',
'english_name' => 'Malay',
'major' => 0,
'active' => 0,
'default_locale' => 'ms_MY',
'tag' => 'ms-MY',
'encode_url' => 0,
);
$wpdb->insert( $wpdb->prefix . 'icl_languages', $ms );
$wpdb->insert(
$wpdb->prefix . 'icl_languages_translations',
array(
'language_code' => 'ms',
'display_language_code' => 'en',
'name' => 'Malay',
)
);
$wpdb->insert(
$wpdb->prefix . 'icl_languages_translations',
array(
'language_code' => 'ms',
'display_language_code' => 'es',
'name' => 'Malayo',
)
);
$wpdb->insert(
$wpdb->prefix . 'icl_languages_translations',
array(
'language_code' => 'ms',
'display_language_code' => 'de',
'name' => 'Malay',
)
);
$wpdb->insert(
$wpdb->prefix . 'icl_languages_translations',
array(
'language_code' => 'ms',
'display_language_code' => 'fr',
'name' => 'Malay',
)
);
$wpdb->insert(
$wpdb->prefix . 'icl_languages_translations',
array(
'language_code' => 'ms',
'display_language_code' => 'ms',
'name' => 'Melayu',
)
);
$wpdb->insert(
$wpdb->prefix . 'icl_flags',
array(
'lang_code' => 'ms',
'flag' => 'ms.png',
'from_template' => 0,
)
);

View File

@@ -0,0 +1,43 @@
<?php
// Fix new Language Switcher widget implementation
// old sample -> unserialize('a:1:{i:1;a:1:{s:5:"title";b:0;}}');
// new sample -> unserialize('a:2:{i:1;a:1:{s:5:"title";b:0;}s:12:"_multiwidget";i:1;}');
$widget_icl_lang_sel_widget = get_option( 'widget_icl_lang_sel_widget' );
if ( is_admin() && $widget_icl_lang_sel_widget ) { // && !isset($widget_icl_lang_sel_widget['_multiwidget'])) {
$widget_icl_lang_sel_widget['_multiwidget'] = 1;
$sitepress_settings = get_option( 'icl_sitepress_settings' );
$icl_widget_title_show = isset( $sitepress_settings['icl_widget_title_show'] ) ? $sitepress_settings['icl_widget_title_show'] : false;
foreach ( $widget_icl_lang_sel_widget as $idx => $data ) {
if ( is_array( $data ) && ! isset( $data['title_show'] ) ) {
$widget_icl_lang_sel_widget[ $idx ]['title_show'] = $icl_widget_title_show;
}
}
update_option( 'widget_icl_lang_sel_widget', $widget_icl_lang_sel_widget );
}
// $sidebars = 'a:5:{s:19:"wp_inactive_widgets";a:0:{}s:9:"sidebar-1";a:8:{i:0;s:21:"icl_lang_sel_widget-2";i:1;s:10:"calendar-2";i:2;s:8:"search-2";i:3;s:14:"recent-posts-2";i:4;s:17:"recent-comments-2";i:5;s:10:"archives-2";i:6;s:12:"categories-2";i:7;s:6:"meta-2";}s:9:"sidebar-2";a:0:{}s:9:"sidebar-3";a:0:{}s:13:"array_version";i:3;}';
// $sidebars = unserialize($sidebars);
$sidebars = get_option( 'sidebars_widgets' );
// Fix widget id from single to multi instance
$fixed = false;
foreach ( $sidebars as $sidebar_id => $widgets ) {
if ( is_array( $widgets ) ) {
foreach ( $widgets as $index => $widget_id ) {
if ( $widget_id == 'icl_lang_sel_widget' ) {
$sidebars[ $sidebar_id ][ $index ] = 'icl_lang_sel_widget-1';
$fixed = true;
break;
}
}
}
if ( $fixed ) {
break;
}
}
if ( $fixed ) {
update_option( 'sidebars_widgets', $sidebars );
}

View File

@@ -0,0 +1,2 @@
<?php
require dirname( __FILE__ ) . '/upgrade-3.1.5.php';

View File

@@ -0,0 +1,5 @@
<?php
global $wpdb;
$sql = 'ALTER TABLE `' . $wpdb->prefix . 'icl_translations` ADD KEY `id_type_language` ( `element_id`, `element_type`, `language_code`)';
$wpdb->query( $sql );

View File

@@ -0,0 +1,3 @@
<?php
repair_el_type_collate();

View File

@@ -0,0 +1,8 @@
<?php
global $wpdb;
// Add a new `language_context` index to icl_strings table
$sql = "ALTER TABLE `{$wpdb->prefix}icl_translate` CHANGE field_data field_data longtext NOT NULL";
$wpdb->query( $sql );
$sql = "ALTER TABLE `{$wpdb->prefix}icl_translate` CHANGE field_data_translated field_data_translated longtext NOT NULL";
$wpdb->query( $sql );

View File

@@ -0,0 +1,102 @@
<?php
/**
* @package wpml-core
*/
function update_gettext_context_schema() {
if ( ! icl_table_column_exists( 'icl_strings', 'domain_name_context_md5' ) ) {
$columns_definitions = array();
if ( ! icl_table_column_exists( 'icl_strings', 'gettext_context' ) ) {
$columns_definitions[] = array(
'action' => 'ADD',
'name' => 'gettext_context',
'type' => 'TEXT',
'null' => false,
'after' => 'status',
);
}
$columns_definitions[] = array(
'action' => 'ADD',
'name' => 'domain_name_context_md5',
'type' => 'VARCHAR(32)',
'charset' => 'LATIN1',
'null' => false,
'default' => '',
'after' => 'gettext_context',
);
if ( icl_alter_table_columns( 'icl_strings', $columns_definitions ) ) {
if ( icl_table_index_exists( 'icl_strings', 'context_name' ) ) {
if ( icl_drop_table_index( 'icl_strings', 'context_name' ) ) {
}
}
if ( icl_table_index_exists( 'icl_strings', 'context_name_gettext_context' ) ) {
if ( icl_drop_table_index( 'icl_strings', 'context_name_gettext_context' ) ) {
}
}
}
update_domain_name_context();
$index_definition = array(
'name' => 'uc_domain_name_context_md5',
'type' => 'BTREE',
'choice' => 'UNIQUE',
'columns' => array( 'domain_name_context_md5' ),
);
icl_create_table_index( 'icl_strings', $index_definition );
}
if ( icl_table_column_exists( 'icl_strings', 'gettext_context_md5' ) ) {
$columns_definitions = array(
array(
'action' => 'DROP',
'name' => 'gettext_context_md5',
),
);
icl_alter_table_columns( 'icl_strings', $columns_definitions );
}
}
function update_domain_name_context() {
global $wpdb;
$results = $wpdb->get_results( "SELECT id, name, value, context as domain, gettext_context FROM {$wpdb->prefix}icl_strings WHERE id > 0" );
$domain_name_context_md5_used = array();
$duplicate_count = 0;
foreach ( $results as $string ) {
$domain_name_context_md5 = md5( $string->domain . $string->name . $string->gettext_context );
while ( in_array( $domain_name_context_md5, $domain_name_context_md5_used ) ) {
/*
We need to handle duplicates because previous versions of WPML didn't strictly
* disallow them when handling gettext contexts.
* This solution doesn't solve the problem because there is no solution
* It just stops any DB errors about duplicate keys.
*/
$duplicate_count++;
$domain_name_context_md5 = md5( $string->domain . $string->name . 'duplicate-' . $duplicate_count . '-' . $string->gettext_context );
}
$domain_name_context_md5_used[] = $domain_name_context_md5;
$data = array(
'domain_name_context_md5' => $domain_name_context_md5,
);
$where = array( 'id' => $string->id );
$wpdb->update( $wpdb->prefix . 'icl_strings', $data, $where );
}
}
update_gettext_context_schema();

View File

@@ -0,0 +1,124 @@
<?php
/**
* @package wpml-core
*/
global $wpdb;
global $sitepress_settings;
if ( ! isset( $sitepress_settings ) ) {
$sitepress_settings = get_option( 'icl_sitepress_settings' );
}
// change icl_translate.field_type size to 160
$sql = "ALTER TABLE {$wpdb->prefix}icl_translate MODIFY COLUMN field_type VARCHAR( 160 ) NOT NULL";
$wpdb->query( $sql );
// Add 'batch_id' column to icl_translation_status
$sql = $wpdb->prepare(
"SELECT count(*) FROM information_schema.COLUMNS
WHERE COLUMN_NAME = 'batch_id'
and TABLE_NAME = '{$wpdb->prefix}icl_translation_status'AND TABLE_SCHEMA = %s",
DB_NAME
);
$batch_id_exists = $wpdb->get_var( $sql );
if ( ! $batch_id_exists || ! (int) $batch_id_exists ) {
$sql = "ALTER TABLE `{$wpdb->prefix}icl_translation_status` ADD batch_id int DEFAULT 0 NOT NULL;";
$wpdb->query( $sql );
}
// Add 'batch_id' column to icl_string_translations
$sql = $wpdb->prepare(
"SELECT count(*) FROM information_schema.COLUMNS
WHERE COLUMN_NAME = 'batch_id'
and TABLE_NAME = '{$wpdb->prefix}icl_string_translations' AND TABLE_SCHEMA = %s",
DB_NAME
);
$batch_id_exists = $wpdb->get_var( $sql );
if ( ! $batch_id_exists || ! (int) $batch_id_exists ) {
$sql = "ALTER TABLE `{$wpdb->prefix}icl_string_translations` ADD batch_id int DEFAULT -1 NOT NULL;";
$wpdb->query( $sql );
require dirname( __FILE__ ) . '/3.2/wpml-upgrade-string-statuses.php';
update_string_statuses();
fix_icl_string_status();
}
// Add 'translation_service' column to icl_string_translations
$sql = $wpdb->prepare(
"SELECT count(*) FROM information_schema.COLUMNS
WHERE COLUMN_NAME = 'translation_service'
and TABLE_NAME = '{$wpdb->prefix}icl_string_translations' AND TABLE_SCHEMA = %s",
DB_NAME
);
$batch_id_exists = $wpdb->get_var( $sql );
if ( ! $batch_id_exists || ! (int) $batch_id_exists ) {
$sql = "ALTER TABLE `{$wpdb->prefix}icl_string_translations` ADD translation_service varchar(16) DEFAULT '' NOT NULL;";
$wpdb->query( $sql );
}
// Add 'icl_translation_batches' table
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}icl_translation_batches (
`id` int(11) NOT NULL AUTO_INCREMENT,
`batch_name` text NOT NULL,
`tp_id` int NULL,
`ts_url` text NULL,
`last_update` DATETIME NULL,
PRIMARY KEY (`id`)
);";
$wpdb->query( $sql );
$res = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}icl_strings" );
$icl_strings_columns = array();
foreach ( $res as $row ) {
$icl_strings_columns[] = $row->Field;
}
if ( ! in_array( 'string_package_id', $icl_strings_columns ) ) {
$wpdb->query(
"ALTER TABLE {$wpdb->prefix}icl_strings
ADD `string_package_id` BIGINT unsigned NULL AFTER value,
ADD `type` VARCHAR(40) NOT NULL DEFAULT 'LINE' AFTER string_package_id,
ADD `title` VARCHAR(160) NULL AFTER type,
ADD INDEX (`string_package_id`)
"
);
}
$wpdb->update( $wpdb->prefix . 'postmeta', array( 'meta_key' => '_wpml_original_post_id' ), array( 'meta_key' => 'original_post_id' ) );
$sitepress_settings = get_option( 'icl_sitepress_settings' );
if ( isset( $sitepress_settings['translation-management'] ) ) {
$updated_tm_settings = false;
$tm_settings = $sitepress_settings['translation-management'];
$tm_setting_keys = array(
'custom_fields_translation',
'custom_fields_readonly_config',
'custom_fields_translation_custom_readonly',
);
foreach ( $tm_setting_keys as $tm_setting_key ) {
$updated_tm_settings_key = false;
if ( isset( $tm_settings[ $tm_setting_key ] ) ) {
$tm_custom_fields_settings = $tm_settings[ $tm_setting_key ];
if ( array_key_exists( 'original_post_id', $tm_custom_fields_settings ) ) {
$tm_custom_fields_settings['_wpml_original_post_id'] = $tm_custom_fields_settings['original_post_id'];
unset( $tm_custom_fields_settings['original_post_id'] );
$updated_tm_settings_key = true;
}
$index = array_search( 'original_post_id', $tm_custom_fields_settings, true );
if ( $index ) {
$tm_custom_fields_settings[ $index ] = '_wpml_original_post_id';
$updated_tm_settings_key = true;
}
if ( $updated_tm_settings_key ) {
$tm_settings[ $tm_setting_key ] = $tm_custom_fields_settings;
$updated_tm_settings = true;
}
}
}
if ( $updated_tm_settings ) {
$sitepress_settings['translation-management'] = $tm_settings;
update_option( 'icl_sitepress_settings', $sitepress_settings );
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @package wpml-core
*/
global $wpdb;
$current_table = 'icl_languages';
$sql = "ALTER TABLE {$wpdb->prefix}icl_languages MODIFY default_locale varchar(35), MODIFY tag varchar(35);";
$result = $wpdb->query( $sql );
if ( false !== $result ) {
$current_table = 'icl_locale_map';
$sql = "ALTER TABLE {$wpdb->prefix}icl_locale_map MODIFY locale varchar(35);";
$result = $wpdb->query( $sql );
}
function update_seo_settings() {
global $wpdb;
$sql = "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s;";
$sql_prepared = $wpdb->prepare( $sql, array( 'icl_sitepress_settings' ) );
$data = $wpdb->get_var( $sql_prepared );
$sitepress_settings = unserialize( $data );
$settings_updated = false;
if ( ! array_key_exists( 'seo', $sitepress_settings ) ) {
$sitepress_settings['seo'] = array();
}
if ( ! array_key_exists( 'head_langs', $sitepress_settings['seo'] ) ) {
$sitepress_settings['head_langs'] = 1;
$settings_updated = true;
}
if ( ! array_key_exists( 'canonicalization_duplicates', $sitepress_settings['seo'] ) ) {
$sitepress_settings['canonicalization_duplicates'] = 1;
$settings_updated = true;
}
if ( ! array_key_exists( 'head_langs_priority', $sitepress_settings['seo'] ) ) {
$sitepress_settings['head_langs_priority'] = 1;
$settings_updated = true;
}
if ( $settings_updated ) {
$data = serialize( $sitepress_settings );
$wpdb->update( $wpdb->options, array( 'option_value' => $data ), array( 'option_name' => 'icl_sitepress_settings' ) );
}
}
update_seo_settings();
if ( false == $result ) {
throw new Exception( 'Error upgrading schema for table "' . $current_table . '": ' . $wpdb->last_error );
}

View File

@@ -0,0 +1,11 @@
<?php
/**
* @package wpml-core
*/
global $wpdb;
// change icl_translation_status.translation_package from text to longtext
$sql = "ALTER TABLE {$wpdb->prefix}icl_translation_status MODIFY COLUMN translation_package longtext NOT NULL";
$wpdb->query( $sql );

View File

@@ -0,0 +1,31 @@
<?php
function update_icl_strings_charset_and_collations() {
global $wpdb;
$charset = 'CHARACTER SET ' . $wpdb->charset;
$collate = '';
if ( method_exists( $wpdb, 'has_cap' ) && $wpdb->has_cap( 'collation' ) && ! empty( $wpdb->collate ) ) {
$collate .= 'COLLATE ' . $wpdb->collate;
}
$sql_template = "ALTER TABLE `{$wpdb->prefix}icl_strings` MODIFY `%s` VARCHAR(%d) {$charset} {$collate}";
$fields = array(
'name' => WPML_STRING_TABLE_NAME_CONTEXT_LENGTH,
'context' => WPML_STRING_TABLE_NAME_CONTEXT_LENGTH,
'domain_name_context_md5' => 32,
);
foreach ( $fields as $field => $size ) {
$sql = sprintf( $sql_template, $field, $size );
if ( $wpdb->query( $sql ) === false ) {
throw new Exception( $wpdb->last_error );
}
}
}
update_icl_strings_charset_and_collations();

View File

@@ -0,0 +1,72 @@
<?php
function update_icl_strings_charset_and_collations() {
global $wpdb;
if ( ! icl_table_column_exists( 'icl_strings', 'domain_name_context_md5' ) ) {
include_once dirname( __FILE__ ) . '/upgrade-3.2.3.php';
}
$collate = false;
if ( method_exists( $wpdb, 'has_cap' ) && $wpdb->has_cap( 'collation' ) ) {
$collate = true;
}
$language_data = upgrade_3_5_1_get_language_charset_and_collation();
$sql_template = "ALTER TABLE `{$wpdb->prefix}%s` MODIFY `%s` VARCHAR(%d) CHARACTER SET %s %s";
$fields = array(
array(
'table' => 'icl_strings',
'column' => 'name',
'size' => WPML_STRING_TABLE_NAME_CONTEXT_LENGTH,
'charset' => 'UTF8',
'collation' => $collate ? 'COLLATE utf8_general_ci' : '',
),
array(
'table' => 'icl_strings',
'column' => 'context',
'size' => WPML_STRING_TABLE_NAME_CONTEXT_LENGTH,
'charset' => 'UTF8',
'collation' => $collate ? 'COLLATE utf8_general_ci' : '',
),
array(
'table' => 'icl_strings',
'column' => 'domain_name_context_md5',
'size' => 32,
'charset' => 'LATIN1',
'collation' => $collate ? 'COLLATE latin1_general_ci' : '',
),
);
foreach ( $fields as $setting ) {
if ( $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}{$setting['table']}'" ) ) {
$sql = sprintf( $sql_template, $setting['table'], $setting['column'], $setting['size'], $setting['charset'], $setting['collation'] );
if ( $wpdb->query( $sql ) === false ) {
throw new Exception( $wpdb->last_error );
}
}
}
}
function upgrade_3_5_1_get_language_charset_and_collation() {
global $wpdb;
$data = null;
$column_data = $wpdb->get_results( "SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='{$wpdb->prefix}icl_strings' AND TABLE_SCHEMA='{$wpdb->dbname}' " );
foreach ( $column_data as $column ) {
if ( 'language' === $column->COLUMN_NAME ) {
$data['collation'] = $column->COLLATION_NAME;
$data['charset'] = $column->CHARACTER_SET_NAME;
}
}
return $data;
}
update_icl_strings_charset_and_collations();