[ Avaa Bypassed ]




Upload:

Command:

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

namespace MailPoet\Migrator;

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


use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;

class Repository {
  const MIGRATIONS_LEVEL_APP = 'app';
  const MIGRATIONS_LEVEL_DB = 'db';

  /** @var string */
  private $migrationsDir;

  /** @var string */
  private $templateFile;

  public function __construct() {
    $this->migrationsDir = __DIR__ . '/../Migrations';
    $this->templateFile = __DIR__ . '/{level}MigrationTemplate.php';
  }

  public function getMigrationsDir(): string {
    return $this->migrationsDir;
  }

  /** @return array{name: string, path: string} */
  public function create(string $level): array {
    if (!in_array($level, [self::MIGRATIONS_LEVEL_APP, self::MIGRATIONS_LEVEL_DB], true)) {
      throw MigratorException::invalidMigrationLevel($level);
    }
    $ucFirstLevel = ucfirst($level);
    $templateFile = str_replace('{level}', $ucFirstLevel, $this->templateFile);
    $template = @file_get_contents($templateFile);
    if (!$template) {
      throw MigratorException::templateFileReadFailed($templateFile);
    }
    $name = $this->generateName($level);
    $migration = str_replace('{level}', $ucFirstLevel, 'class {level}MigrationTemplate ');
    $migration = str_replace($migration, "class $name ", $template);
    $path = "$this->migrationsDir/$ucFirstLevel/$name.php";
    $result = @file_put_contents($path, $migration);
    if (!$result) {
      throw MigratorException::migrationFileWriteFailed($path);
    }
    return [
      'name' => $name,
      'path' => $path,
    ];
  }

  /**
   * Array of migration filenames and types.
   * Db migrations are loaded first, then app migrations. This ensures that Db migrator is run before app migrations
   * @return array<array{level: string, name: string}>
   */
  public function loadAll(): array {
    $migrations = array_merge(
      $this->loadForLevel(self::MIGRATIONS_LEVEL_DB),
      $this->loadForLevel(self::MIGRATIONS_LEVEL_APP)
    );
    $migrationNames = array_column($migrations, 'name');
    $duplicateNames = array_diff_assoc($migrationNames, array_unique($migrationNames));
    if (!empty($duplicateNames)) {
      throw MigratorException::duplicateMigrationNames($duplicateNames);
    }
    return $migrations;
  }

  /**
   * @return array<array{level: string, name: string}>
   */
  private function loadForLevel(string $level): array {
    $files = new RecursiveIteratorIterator(
      new RecursiveDirectoryIterator($this->migrationsDir . '/' . ucfirst($level), RecursiveDirectoryIterator::SKIP_DOTS)
    );

    $migrations = [];
    foreach ($files as $file) {
      if (!$file instanceof SplFileInfo || !$file->isFile()) {
        continue;
      }
      if (strtolower($file->getFilename()) === 'index.php') {
        continue;
      }
      if (strtolower($file->getExtension()) === 'php') {
        $migrations[] = $file->getBasename('.' . $file->getExtension());
      }
    }
    sort($migrations);
    return array_map(function ($migration) use ($level) {
      return [
        'level' => $level,
        'name' => $migration,
      ];
    }, $migrations);
  }

  private function generateName(string $level): string {
    return 'Migration_' . gmdate('Ymd_His') . '_' . ucfirst($level);
  }
}

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