Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix admin-tools for public-dir #41

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace EE\Migration;

use EE;
use EE\Migration\Base;
use EE\Migration\SiteContainers;
use EE\RevertableStepProcessor;
use EE\Model\Site;

class UpdateIndexForPubliDir extends Base {

private $sites;
/** @var RevertableStepProcessor $rsp Keeps track of migration state. Reverts on error */
private static $rsp;

public function __construct() {

parent::__construct();
$this->sites = Site::all();
if ( $this->is_first_execution || ! $this->sites ) {
$this->skip_this_migration = true;
} else {
$this->skip_this_migration = true;
foreach ( $this->sites as $site ) {
if ( $site->admin_tools ) {
$this->skip_this_migration = false;
}
}
}
}

/**
* Execute php config updates.
*
* @throws EE\ExitException
*/
public function up() {

if ( $this->skip_this_migration ) {
EE::debug( 'Skipping update-index migration as it is not needed.' );

return;
}
self::$rsp = new RevertableStepProcessor();


EE::debug( 'Starting update-admin-tools-index' );

$admin_tools_index = EE_ROOT_DIR . '/admin-tools/index.php';
$backup_index = EE_BACKUP_DIR . '/admin-tools/index.php';
$new_index_file = EE_BACKUP_DIR . '/admin-tools/new-index.php';

$index_path_data = [
'db_path' => DB,
'ee_admin_path' => '/var/www/htdocs/ee-admin',
];
$index_file = EE\Utils\mustache_render( ADMIN_TEMPLATE_ROOT . '/index.mustache', $index_path_data );
$this->fs->dumpFile( $new_index_file, $index_file );

self::$rsp->add_step(
'take-admin-tools-index-backup',
'EE\Migration\SiteContainers::backup_restore',
'EE\Migration\SiteContainers::backup_restore',
[ $admin_tools_index, $backup_index ],
[ $backup_index, $admin_tools_index ]
);

self::$rsp->add_step(
'update-admin-tools-index',
'EE\Migration\SiteContainers::backup_restore',
'EE\Migration\SiteContainers::backup_restore',
[ $new_index_file, $admin_tools_index ],
[ $admin_tools_index, $new_index_file ]
);

if ( ! self::$rsp->execute() ) {
throw new \Exception( 'Unable run update-index migrations.' );
}
}

/**
* Bring back the existing old config and path.
*
* @throws EE\ExitException
*/
public function down() {
}
}
2 changes: 1 addition & 1 deletion src/Admin_Tools_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function enable( $args, $assoc_args ) {
$docker_compose_data = [
'ee_root_dir' => EE_ROOT_DIR,
'db_path' => DB,
'ee_admin_path' => '/var/www/htdocs/ee-admin',
'ee_admin_path' => $this->site_data->site_container_fs_path . '/ee-admin',
'redis_host' => $this->site_data->cache_host,
'db_host' => $this->site_data->db_host,
];
Expand Down
6 changes: 3 additions & 3 deletions templates/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ $services = populate_site_info();
unset( $services['id'] );
unset( $services['site_url'] );


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

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