first commit
This commit is contained in:
@@ -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,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,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,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,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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user