|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace EE\Migration; |
| 4 | + |
| 5 | +use EE; |
| 6 | +use EE\Migration\Base; |
| 7 | +use EE\Migration\SiteContainers; |
| 8 | +use EE\RevertableStepProcessor; |
| 9 | +use EE\Model\Site; |
| 10 | +use function EE\Utils\random_password; |
| 11 | + |
| 12 | +class UpdatePmaConfig extends Base { |
| 13 | + |
| 14 | + private $sites; |
| 15 | + /** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */ |
| 16 | + private static $rsp; |
| 17 | + |
| 18 | + public function __construct() { |
| 19 | + |
| 20 | + parent::__construct(); |
| 21 | + $this->sites = Site::all(); |
| 22 | + if ( $this->is_first_execution || ! $this->sites ) { |
| 23 | + $this->skip_this_migration = true; |
| 24 | + } else { |
| 25 | + $this->skip_this_migration = true; |
| 26 | + if ( $this->fs->exists( EE_ROOT_DIR . '/admin-tools/pma/config.inc.php' ) ) { |
| 27 | + $this->skip_this_migration = false; |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Execute pma config updates. |
| 34 | + * |
| 35 | + * @throws EE\ExitException |
| 36 | + */ |
| 37 | + public function up() { |
| 38 | + |
| 39 | + if ( $this->skip_this_migration ) { |
| 40 | + EE::debug( 'Skipping pma-config migration as it is not needed.' ); |
| 41 | + |
| 42 | + return; |
| 43 | + } |
| 44 | + self::$rsp = new RevertableStepProcessor(); |
| 45 | + |
| 46 | + |
| 47 | + EE::debug( 'Starting update-pma-config' ); |
| 48 | + |
| 49 | + $pma_config = EE_ROOT_DIR . '/admin-tools/pma/config.inc.php'; |
| 50 | + $backup_config = EE_BACKUP_DIR . '/admin-tools/pma/config.inc.php'; |
| 51 | + $new_config = EE_BACKUP_DIR . '/admin-tools/new-pma/config.inc.php'; |
| 52 | + |
| 53 | + $pma_config_data = [ |
| 54 | + 'blowfish_secret' => random_password( 32 ), |
| 55 | + ]; |
| 56 | + $pma_config_content = EE\Utils\mustache_render( ADMIN_TEMPLATE_ROOT . '/pma.config.mustache', $pma_config_data ); |
| 57 | + $this->fs->dumpFile( $new_config, $pma_config_content ); |
| 58 | + |
| 59 | + self::$rsp->add_step( |
| 60 | + 'take-admin-tools-pma-config-backup', |
| 61 | + 'EE\Migration\SiteContainers::backup_restore', |
| 62 | + 'EE\Migration\SiteContainers::backup_restore', |
| 63 | + [ $pma_config, $backup_config ], |
| 64 | + [ $backup_config, $pma_config ] |
| 65 | + ); |
| 66 | + |
| 67 | + self::$rsp->add_step( |
| 68 | + 'update-pma-config', |
| 69 | + 'EE\Migration\SiteContainers::backup_restore', |
| 70 | + 'EE\Migration\SiteContainers::backup_restore', |
| 71 | + [ $new_config, $pma_config ], |
| 72 | + [ $pma_config, $new_config ] |
| 73 | + ); |
| 74 | + |
| 75 | + if ( ! self::$rsp->execute() ) { |
| 76 | + throw new \Exception( 'Unable run pma-config migrations.' ); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Bring back the existing old config and path. |
| 82 | + * |
| 83 | + * @throws EE\ExitException |
| 84 | + */ |
| 85 | + public function down() { |
| 86 | + } |
| 87 | +} |
0 commit comments