namespace WPForms\Tasks\Actions;
* Class Font Awesome Upgrade task.
class IconChoicesFontAwesomeUpgradeTask extends Task {
* Action name for this task.
const ACTION = 'wpforms_process_font_awesome_upgrade';
const STATUS = 'wpforms_process_font_awesome_upgrade_status';
const IN_PROGRESS = 'in_progress';
const COMPLETED = 'completed';
protected $log_title = 'Migration';
public function __construct() {
parent::__construct( self::ACTION );
// Bail out if migration is not started or completed.
$status = get_option( self::STATUS );
// This task is run in \WPForms\Pro\Migrations\Upgrade183::run(),
// and started in \WPForms\Migrations\UpgradeBase::run_async().
// Bail out if a task is not started or completed.
if ( ! $status || $status === self::COMPLETED ) {
// Mark that migration is in progress.
update_option( self::STATUS, self::IN_PROGRESS );
$tasks = wpforms()->obj( 'tasks' );
// Add new if none exists.
if ( $tasks->is_scheduled( self::ACTION ) !== false ) {
$tasks->create( self::ACTION )->async()->register();
private function hooks() {
add_action( self::ACTION, [ $this, 'upgrade' ] );
public function upgrade() {
$upload_dir = wpforms_upload_dir();
$tmp_base_path = $upload_dir['path'] . '/icon-choices-tmp';
$cache_base_path = $upload_dir['path'] . '/icon-choices';
$icons_data_file = $cache_base_path . '/icons.json';
if ( ! file_exists( $icons_data_file ) ) {
$this->log( 'Font Awesome Upgrade: Font Awesome Upgrade: Library is not present, nothing to upgrade.' );
update_option( self::STATUS, self::COMPLETED );
require_once ABSPATH . 'wp-admin/includes/file.php';
$wp_filesystem->rmdir( $tmp_base_path, true );
wpforms()->obj( 'icon_choices' )->run_install( $tmp_base_path );
if ( is_dir( $tmp_base_path ) ) {
$this->log( 'Font Awesome Upgrade: Removing existing instance of the library.' );
$wp_filesystem->rmdir( $cache_base_path, true );
// Rename temporary directory.
$this->log( 'Font Awesome Upgrade: Renaming temporary directory.' );
$wp_filesystem->move( $tmp_base_path, $cache_base_path );
// Mark that migration is finished.
$this->log( 'Font Awesome Upgrade: Finished upgrading.' );
update_option( self::STATUS, self::COMPLETED );
$this->log( 'Font Awesome Upgrade: Something went wrong, library was not upgraded.' );