403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.14.247.147
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/7779/task/7779/cwd/plugins/give/src/MigrationLog/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/7779/task/7779/cwd/plugins/give/src/MigrationLog/MigrationLogRepository.php
<?php

namespace Give\MigrationLog;

use Give\Framework\Database\DB;

/**
 * Class MigrationLogRepository
 * @package Give\MigrationLog
 *
 * @since 2.10.0
 */
class MigrationLogRepository
{
    /**
     * @var string
     */
    private $migration_table;

    /**
     * @var MigrationLogFactory
     */
    private $migrationFactory;

    /**
     * MigrationRepository constructor.
     *
     * @param MigrationLogFactory $migrationFactory
     */
    public function __construct(MigrationLogFactory $migrationFactory)
    {
        global $wpdb;
        $this->migration_table = $wpdb->give_migrations;
        $this->migrationFactory = $migrationFactory;
    }

    /**
     * Save Migration
     *
     * @param MigrationLogModel $model
     */
    public function save(MigrationLogModel $model)
    {
        $query = "
			INSERT INTO {$this->migration_table} (id, status, error, last_run )
			VALUES (%s, %s, %s, NOW())
			ON DUPLICATE KEY UPDATE
			status = %s,
			error = %s,
			last_run = NOW()
		";

        DB::query(
            DB::prepare(
                $query,
                $model->getId(),
                $model->getStatus(),
                $model->getError(),
                $model->getStatus(),
                $model->getError()
            )
        );
    }

    /**
     * Get all migrations
     *
     * @return MigrationLogModel[]
     */
    public function getMigrations()
    {
        $migrations = [];

        $result = DB::get_results("SELECT * FROM {$this->migration_table}");

        if ($result) {
            foreach ($result as $migration) {
                $migrations[] = $this->migrationFactory->make(
                    $migration->id,
                    $migration->status,
                    $migration->error,
                    $migration->last_run
                );
            }
        }

        return $migrations;
    }

    /**
     * Get migration by ID
     *
     * @param string $id
     *
     * @return MigrationLogModel|null
     */
    public function getMigration($id)
    {
        $migration = DB::get_row(
            DB::prepare("SELECT * FROM {$this->migration_table} WHERE id = %s", $id)
        );

        if ($migration) {
            return $this->migrationFactory->make(
                $migration->id,
                $migration->status,
                $migration->error,
                $migration->last_run
            );
        }

        return null;
    }

    /**
     * Get migrations by status
     *
     * @param string $status
     *
     * @return MigrationLogModel[]
     */
    public function getMigrationsByStatus($status)
    {
        $migrations = [];

        $result = DB::get_results(
            DB::prepare("SELECT * FROM {$this->migration_table} WHERE status = %s", $status)
        );

        if ($result) {
            foreach ($result as $migration) {
                $migrations[] = $this->migrationFactory->make(
                    $migration->id,
                    $migration->status,
                    $migration->error,
                    $migration->last_run
                );
            }
        }

        return $migrations;
    }

    /**
     * Get completed migrations IDs
     *
     * @return array
     */
    public function getCompletedMigrationsIDs()
    {
        $migrations = [];

        try {
            $result = DB::get_results(
                DB::prepare("SELECT * FROM {$this->migration_table} WHERE status = %s", MigrationLogStatus::SUCCESS)
            );
        } catch (\Exception $exception) {
            // This exception should happen only once, during the migration system storage update.
            // But, we will log this error just in case to see if this is a repeating problem.
            error_log($exception->getMessage());

            // Fallback to legacy migration storage system
            return get_option('give_database_migrations', []);
        }

        if ($result) {
            foreach ($result as $migration) {
                $migrations[] = $migration->id;
            }
        }

        return $migrations;
    }

    /**
     * Get migration count
     *
     * @return int|null
     */
    public function getMigrationsCount()
    {
        try {
            return DB::get_var("SELECT count(id) FROM {$this->migration_table}");
        } catch (\Exception $exception) {
            return 0;
        }
    }

    /**
     * Get failed migrations count by list of migrations ids
     *
     * @param array $migrationIds
     *
     * @return int
     */
    public function getFailedMigrationsCountByIds($migrationIds)
    {
        try {
            $query = sprintf(
                "SELECT count(id) FROM %s WHERE id IN ('%s') AND status != '%s'",
                $this->migration_table,
                implode("','", array_map('esc_sql', $migrationIds)),
                MigrationLogStatus::SUCCESS
            );

            return DB::get_var($query);
        } catch (\Exception $exception) {
            // Fallback
            return 0;
        }
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit