Skip to content

Commit 490436e

Browse files
authored
Merge pull request #41 from mrrobot47/update/for-public-dir
Fix admin-tools for public-dir
2 parents 8730f97 + a2f4842 commit 490436e

3 files changed

Lines changed: 93 additions & 4 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 UpdateIndexForPubliDir 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+
}

src/Admin_Tools_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function enable( $args, $assoc_args ) {
127127
$docker_compose_data = [
128128
'ee_root_dir' => EE_ROOT_DIR,
129129
'db_path' => DB,
130-
'ee_admin_path' => '/var/www/htdocs/ee-admin',
130+
'ee_admin_path' => $this->site_data->site_container_fs_path . '/ee-admin',
131131
'redis_host' => $this->site_data->cache_host,
132132
'db_host' => $this->site_data->db_host,
133133
];

templates/index.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ $services = populate_site_info();
7171
unset( $services['id'] );
7272
unset( $services['site_url'] );
7373

74-
75-
$scan = scandir( '{{ee_admin_path}}' );
76-
$scan = array_diff( $scan, [ '.', '..', 'index.php' ] );
74+
$scan_dir = ( file_exists ( '/var/www/htdocs/current/ee-admin' ) ) ? '/var/www/htdocs/current/ee-admin' : '/var/www/htdocs/ee-admin';
75+
$scan = scandir( $scan_dir );
76+
$scan = array_diff( $scan, [ '.', '..', 'index.php' ] );
7777

7878
$tools = array_merge( $scan, [ 'nginx_status', 'ping', 'status' ] );
7979
if ( $services['mailhog_enabled'] ) {

0 commit comments

Comments
 (0)