HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux aritmodecarnaval.es 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/www/aritmodecarnaval/wp-content/plugins/wp-migrate-db/class/Common/Error/Logger.php
<?php

namespace DeliciousBrains\WPMDB\Common\Error;

use DeliciousBrains\WPMDB\Common\MigrationPersistence\Persistence;

/**
 * Adds log messages about migrations
 */
class Logger
{

    /**
     * register hooks
     **/
    public function register()
    {
        add_action('wpmdb_initiate_migration', [$this, 'initiate']);
        add_action('wpmdb_after_finalize_migration', [$this, 'complete']);
        add_action('wpmdb_cancellation', [$this, 'cancellation']);
        add_action('wpmdb_respond_remote_initiate', [$this, 'remoteInitiate'], 10, 1);
        add_action('wpmdb_remote_finalize', [$this, 'remoteFinalize'], 10, 1);
        add_action('wpmdb_respond_to_push_cancellation', [$this, 'remoteCancellation']);
    }

    /**
     * Logs message to error log
     *
     * @param array $args
     * @param array $state_data
     **/
    public function logMessage($args, $state_data = [])
    {
        $extra_data  = Persistence::getStateData();
        $state_data  = array_merge($state_data, $extra_data);
        $target      = ('pull' === $state_data['intent'] && 'local' === $args['location'])  || ('push' === $state_data['intent'] && 'remote' === $args['location']);
        $log_message = 'WPMDB: ';
        $stats       = [
            'type'     => $args['type'],
            'location' => $args['location'],
            'target'   => isset($args['target']) ? $args['target'] : $target
        ];
       
        if (isset($state_data['site_url'], $state_data['url'])) {
            $stats['sites'] = [
                'local'  =>  $state_data['site_url'],
                'remote' => $state_data['url']
            ];
        }

        if (isset($state_data['migration_state_id'])) {
            $stats['migration_id'] = $state_data['migration_state_id'];
        }

         if (isset($state_data['remote_state_id'])) {
            $stats['migration_id'] = $state_data['remote_state_id'];
        }
                
        error_log($log_message . json_encode($stats));
    }

    /**
     * Hooked to 'wpmdb_initiate_migration'
     *
     * @param array $state_data
     **/
    public function initiate($state_data)
    {
        $args = [
            'type'     => 'initiate',
            'location' => 'local'
        ];
        $this->logMessage($args, $state_data);
    }

    /**
     * Hooked to 'wpmdb_respond_remote_initiate'
     *
     * @param array $state_data
     **/
    public function remoteInitiate($state_data)
    {
        $args = [
            'type'     => 'initiate',
            'location' => 'remote'
        ];
        $this->logMessage($args, $state_data);
    }

    /**
     * Hooked to 'wpmdb_remote_finalize'
     *
     * @param array $state_data
     **/
    public function remoteFinalize($state_data)
    {
        $args =  [
            'type'     => 'complete',
            'location' => 'remote',
            'target'   => true
        ];
        $this->logMessage($args, $state_data);
    }

    /**
     * Log on migration complete
     * Hooked to 'wpmdb_after_finalize_migration'
     **/
    public function complete()
    {
        $args = [
            'type'     => 'complete',
            'location' => 'local'
        ];
        $this->logMessage($args);
    }

    /**
     * Cancellation log
     * Hooked to 'wpmdb_cancellation'
     **/
    public function cancellation()
    {
        $args = [
            'type'     => 'cancel',
            'location' => 'local'
        ];
        $this->logMessage($args);
    }

    /**
     * Remote cancellation log
     * Hooked to 'wpmdb_respond_to_push_cancellation'
     **/
    public function remoteCancellation()
    {
        $args = [
            'type'     => 'cancel',
            'location' => 'remote'
        ];
        $this->logMessage($args);
    }
}