[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.138.137.244: ~ $
<?php declare(strict_types = 1);

namespace MailPoet\Migrator;

if (!defined('ABSPATH')) exit;


use MailPoet\Config\Env;
use MailPoet\DI\ContainerWrapper;
use MailPoetVendor\Doctrine\DBAL\Connection;
use MailPoetVendor\Doctrine\DBAL\Exception;
use MailPoetVendor\Doctrine\ORM\EntityManager;

abstract class DbMigration {
  /** @var Connection */
  protected $connection;

  /** @var EntityManager */
  private $entityManager;

  public function __construct(
    ContainerWrapper $container
  ) {
    $this->connection = $container->get(Connection::class);
    $this->entityManager = $container->get(EntityManager::class);
  }

  abstract public function run(): void;

  /**
   * @param class-string<object> $entityClass
   */
  protected function getTableName(string $entityClass): string {
    return $this->entityManager->getClassMetadata($entityClass)->getTableName();
  }

  protected function createTable(string $tableName, array $attributes): void {
    $prefix = Env::$dbPrefix;
    $charsetCollate = Env::$dbCharsetCollate;
    $sql = implode(",\n", $attributes);
    $this->connection->executeStatement("
      CREATE TABLE IF NOT EXISTS {$prefix}{$tableName} (
        $sql
      ) {$charsetCollate};
    ");
  }

  protected function columnExists(string $tableName, string $columnName): bool {
    global $wpdb;
    $suppressErrors = $wpdb->suppress_errors();
    try {
      $this->connection->executeStatement("SELECT $columnName FROM $tableName LIMIT 0");
      return true;
    } catch (Exception $e) {
      return false;
    } finally {
      $wpdb->suppress_errors($suppressErrors);
    }
  }

  protected function tableExists(string $tableName): bool {
    global $wpdb;
    $suppressErrors = $wpdb->suppress_errors();
    try {
      $this->connection->executeStatement("SELECT 1 FROM $tableName LIMIT 0");
      return true;
    } catch (Exception $e) {
      return false;
    } finally {
      $wpdb->suppress_errors($suppressErrors);
    }
  }

  protected function indexExists(string $tableName, string $indexName): bool {
    global $wpdb;
    $suppressErrors = $wpdb->suppress_errors();
    try {
      $this->connection->executeStatement("ALTER TABLE $tableName ADD INDEX $indexName (__non__existent__column__name__)");
    } catch (Exception $e) {
      // Index creating index failed on not existing column we use a fallback. This can happen on MySQL 5.7 and lower and on some MariaDB versions.
      if ($e->getCode() === 1072) {
        $database = $wpdb->dbname;
        $result = $wpdb->get_var($wpdb->prepare(
          "SELECT count(*)
         FROM information_schema.statistics
         WHERE table_schema = COALESCE(DATABASE(), %s)
         AND table_name = %s
         AND index_name = %s",
          $database,
          $tableName,
          $indexName
        ));

        return $result > 0;
      }
      // Index exists when the error message contains its name. Otherwise, it's the non-existent column error.
      return strpos($e->getMessage(), $indexName) !== false;
    } finally {
      $wpdb->suppress_errors($suppressErrors);
    }
    return false;
  }
}

Filemanager

Name Type Size Permission Actions
AppMigration.php File 539 B 0644
AppMigrationTemplate.php File 787 B 0644
Cli.php File 4.47 KB 0644
DbMigration.php File 3.04 KB 0644
DbMigrationTemplate.php File 655 B 0644
Logger.php File 541 B 0644
Migrator.php File 3.03 KB 0644
MigratorException.php File 1.67 KB 0644
Repository.php File 3.23 KB 0644
Runner.php File 1.79 KB 0644
Store.php File 2.28 KB 0644
index.php File 6 B 0644