Bitcoin and Altcoin Wallets 6.4.0

Migration_Task extends Task
in package

Migrates transactions and addresses from the old MySQL tables to custom posts.

This cron job migrates the transactions and addresses from the custom MySQL tables of version 5.x and below to custom posts for version 6 and greater.

The process will create any currencies not already declared. It does its best to guess the currency from the symbol name.

While the process runs, the UIs are unavailable.

The process is not destructive. i.e. the old data will continue to exist, so you can safely roll back to version 5.x if needed.

To repeat the migration process, delete the wallets_migration_state option.

The process will generate transaction tags for all the tags found in the old tables.

If a transaction or address fails to be converted for whatever reason, it is skipped. Admins are notified by email about the contents of the transaction.

If the old tables don't exist, migration is marked as finished and does not do anything.

If the old tables do exist and migration has finished, admins are notified by email.

Statistics about the migration progress are shown in the admin screens to all admins.

Tags
author

Alexandros Georgiou info@dashed-slug.net

since
6.0.0

Introduced.

Table of Contents

MAX_BATCH_SIZE_ADDRESSES  = 100
MAX_BATCH_SIZE_TRANSACTIONS  = 100
$name  : mixed
$priority  : mixed
$task_start_time  : mixed
$timeout  : mixed
$verbose  : mixed
$coingecko_currencies  : mixed
Array of objects with fields: id, name, symbol
$start_memory  : mixed
$start_time  : mixed
$state  : mixed
Counters related to the current state of the migration progress. Are persisted with a WordPress option.
$table_name_adds  : mixed
Name for the deposit addresses MySQL table.
$table_name_txs  : mixed
Name for the transactions MySQL table.
__construct()  : mixed
Constructor hooks this task into the cron job action.
create_address()  : void
create_transaction()  : void
get_address_rows()  : array<string|int, mixed>
Gets a batch of address rows from the old address table.
is_running()  : bool
Tells you whether the migration task is currently active.
log()  : void
Cron task logging.
register()  : void
run()  : void
Do the task.
get_balance_rows()  : array<string|int, mixed>
Gets a user ID and returns the SQL balances for each symbol.
get_cron_interval()  : int
get_ids_of_migrated_posts()  : array<string|int, mixed>
get_next_user_id_after()  : int|null
get_or_make_currency()  : Currency
get_transaction_rows()  : array<string|int, mixed>
map_status()  : string

Constants

Properties

$priority

protected mixed $priority = 10

int The priority with which to attach to cron action.

$task_start_time

protected mixed $task_start_time = 0

int Timestamp at which this task is starting execution.

$timeout

protected mixed $timeout = DEFAULT_CRON_TASK_TIMEOUT

How many seconds this task is allowed to run. The task's run() method must respect this limit.

$verbose

protected mixed $verbose = false

boolean Whether to write all log() output to debug log.

$coingecko_currencies

Array of objects with fields: id, name, symbol

private static mixed $coingecko_currencies = null

$start_memory

private static mixed $start_memory = 0

int Memory used at start of tasks batch execution, measured in bytes.

$start_time

private static mixed $start_time = 0

int Timestamp at which tasks batch starts execution.

$state

Counters related to the current state of the migration progress. Are persisted with a WordPress option.

private static mixed $state = []

$table_name_adds

Name for the deposit addresses MySQL table.

private mixed $table_name_adds = ''

$table_name_txs

Name for the transactions MySQL table.

private mixed $table_name_txs = ''

Methods

__construct()

Constructor hooks this task into the cron job action.

public __construct() : mixed

Call this after your sub-class constructor. This way, any changes you make to $this->priority will have an effect. WARNING: If you forget to call parent::__construct();, your task will not run.

Return values
mixed

create_address()

public create_address(object $row) : void
Parameters
$row : object
Return values
void

create_transaction()

public create_transaction(object $row) : void
Parameters
$row : object
Return values
void

get_address_rows()

Gets a batch of address rows from the old address table.

public get_address_rows(int $last_id[, int $batch_size = self::MAX_BATCH_SIZE_ADDRESSES ]) : array<string|int, mixed>
Parameters
$last_id : int

ID of last address already processed. This batch will begin immediately after.

$batch_size : int = self::MAX_BATCH_SIZE_ADDRESSES

The requested batch size. Up to this many addresses are returned.

Tags
throws
Exception

If the DB queries fail.

Return values
array<string|int, mixed>

Array of objects representing the address rows.

is_running()

Tells you whether the migration task is currently active.

public static is_running() : bool

While a task is active, there should be no transactions or other user changes to the DB. The APIs should therefore check for this and fail if it returns true.

Return values
bool

log()

Cron task logging.

public final log(string $message[, bool $force = false ]) : void

Migration task is always logged.

Parameters
$message : string

The string to log.

$force : bool = false

Whether to force log the string, even if no verbose logging is checked.

Return values
void

register()

public final static register() : void
Return values
void

run()

Do the task.

public run() : void

Concrete implementations must do the work here in chuncks. The max execution time, usually about 15 or 30 secs must be eenough for all the tasks. So be careful!

Return values
void

get_balance_rows()

Gets a user ID and returns the SQL balances for each symbol.

private get_balance_rows(int $user_id) : array<string|int, mixed>
Parameters
$user_id : int

The ID of the user.

Return values
array<string|int, mixed>

Map of ticker symbols to balances as floats.

get_cron_interval()

private static get_cron_interval() : int
Return values
int

get_ids_of_migrated_posts()

private static get_ids_of_migrated_posts(string $post_type) : array<string|int, mixed>
Parameters
$post_type : string
Return values
array<string|int, mixed>

get_next_user_id_after()

private static get_next_user_id_after(int $user_id) : int|null
Parameters
$user_id : int
Return values
int|null

get_transaction_rows()

private get_transaction_rows(int $last_id[, int $batch_size = self::MAX_BATCH_SIZE_TRANSACTIONS ]) : array<string|int, mixed>
Parameters
$last_id : int
$batch_size : int = self::MAX_BATCH_SIZE_TRANSACTIONS
Return values
array<string|int, mixed>

map_status()

private map_status(string $status) : string
Parameters
$status : string
Return values
string

Search results