Skip to content

Commit 7b01d7a

Browse files
committed
Add update admin-tools index migrations
Signed-off-by: Riddhesh Sanghvi <riddheshsanghvi96@gmail.com>
1 parent 19b08da commit 7b01d7a

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
11+
class UpdateIndex extends Base {
12+
13+
private $sites;
14+
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */
15+
private static $rsp;
16+
17+
public function __construct() {
18+
19+
parent::__construct();
20+
$this->sites = Site::all();
21+
if ( $this->is_first_execution || ! $this->sites ) {
22+
$this->skip_this_migration = true;
23+
} else {
24+
$this->skip_this_migration = true;
25+
foreach ( $this->sites as $site ) {
26+
if ( $site->admin_tools ) {
27+
$this->skip_this_migration = false;
28+
}
29+
}
30+
}
31+
}
32+
33+
/**
34+
* Execute php config updates.
35+
*
36+
* @throws EE\ExitException
37+
*/
38+
public function up() {
39+
40+
if ( $this->skip_this_migration ) {
41+
EE::debug( 'Skipping update-index migration as it is not needed.' );
42+
43+
return;
44+
}
45+
self::$rsp = new RevertableStepProcessor();
46+
47+
48+
EE::debug( 'Starting update-admin-tools-index' );
49+
50+
$admin_tools_index = EE_ROOT_DIR . '/admin-tools/index.php';
51+
$backup_index = EE_BACKUP_DIR . '/admin-tools/index.php';
52+
$new_index_file = EE_BACKUP_DIR . '/admin-tools/new-index.php';
53+
54+
$index_path_data = [
55+
'db_path' => DB,
56+
'ee_admin_path' => '/var/www/htdocs/ee-admin',
57+
];
58+
$index_file = EE\Utils\mustache_render( ADMIN_TEMPLATE_ROOT . '/index.mustache', $index_path_data );
59+
$this->fs->dumpFile( $new_index_file, $index_file );
60+
61+
self::$rsp->add_step(
62+
'take-admin-tools-index-backup',
63+
'EE\Migration\SiteContainers::backup_restore',
64+
'EE\Migration\SiteContainers::backup_restore',
65+
[ $admin_tools_index, $backup_index ],
66+
[ $backup_index, $admin_tools_index ]
67+
);
68+
69+
self::$rsp->add_step(
70+
'update-admin-tools-index',
71+
'EE\Migration\SiteContainers::backup_restore',
72+
'EE\Migration\SiteContainers::backup_restore',
73+
[ $new_index_file, $admin_tools_index ],
74+
[ $admin_tools_index, $new_index_file ]
75+
);
76+
77+
if ( ! self::$rsp->execute() ) {
78+
throw new \Exception( 'Unable run update-index migrations.' );
79+
}
80+
}
81+
82+
/**
83+
* Bring back the existing old config and path.
84+
*
85+
* @throws EE\ExitException
86+
*/
87+
public function down() {
88+
}
89+
}

0 commit comments

Comments
 (0)