first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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` )';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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' ];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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')";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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` )';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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` )';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use WPML\Plugins;
|
||||
|
||||
class AddTMAllowedOption extends WPML_Upgrade_Run_All {
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function run() {
|
||||
add_action('init', [ Plugins::class, 'updateTMAllowedOption' ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?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( \WPML_Manage_Translations_Role::CAPABILITY );
|
||||
do_action( 'wpml_tm_ate_synchronize_managers' );
|
||||
wp_get_current_user()->get_role_caps(); // Refresh the current user capabilities.
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Upgrade\Commands;
|
||||
|
||||
class DropCodeLocaleIndexFromLocaleMap extends DropIndexFromTable {
|
||||
|
||||
protected function get_table() {
|
||||
return 'icl_locale_map';
|
||||
}
|
||||
|
||||
protected function get_index() {
|
||||
return 'code';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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 ) ] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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`';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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`';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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`';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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 = array_keys( wpml_get_capabilities() );
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
class WPML_Upgrade_Media_Duplication_In_Core implements IWPML_Upgrade_Command {
|
||||
|
||||
const DUPLICATE_FEATURED_META_KEY = '_wpml_media_featured';
|
||||
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() {
|
||||
$this->update_global_settings();
|
||||
|
||||
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 = '" . self::DUPLICATE_FEATURED_META_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, '" . self::DUPLICATE_FEATURED_META_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 );
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $post->ID, '_wpml_media_duplicate', true );
|
||||
}
|
||||
|
||||
private function should_duplicate_media() {
|
||||
$settings = $this->get_media_settings();
|
||||
|
||||
return isset( $settings['new_content_settings']['duplicate_media'] )
|
||||
&& $settings['new_content_settings']['duplicate_media'];
|
||||
}
|
||||
|
||||
public function update_global_settings() {
|
||||
|
||||
$settings = $this->get_media_settings();
|
||||
$settings['new_content_settings']['always_translate_media'] = true;
|
||||
$settings['new_content_settings']['duplicate_media'] = true;
|
||||
$settings['new_content_settings']['duplicate_featured'] = true;
|
||||
|
||||
update_option( WPML_Media_Duplication_Setup::MEDIA_SETTINGS_OPTION_KEY, $settings );
|
||||
}
|
||||
|
||||
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_settings() {
|
||||
return get_option( WPML_Media_Duplication_Setup::MEDIA_SETTINGS_OPTION_KEY, array() );
|
||||
}
|
||||
|
||||
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' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user