Created
February 6, 2020 21:30
-
-
Save austinginder/ace9db33b7b472f6cdeadab7e951ef16 to your computer and use it in GitHub Desktop.
Revisions
-
austinginder created this gist
Feb 6, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ <?php if ( count ( $args ) == 0 ) { echo "Error: missing <captain_id> argument."; return; } $json = $_SERVER['HOME'] . "/.captaincore-cli/config.json"; $config_data = json_decode ( file_get_contents( $json ) ); $system = $config_data[0]->system; $path = $system->path; $captain_id = $args[0]; if ( $system->captaincore_fleet == "true" ) { $path = "{$path}/$captain_id"; } $ids_sites_json = "ids-sites_{$captain_id}.json"; if ( ! file_exists( $ids_sites_json ) ) { echo "Error: missing file $ids_sites_json"; return; } $sites = json_decode( file_get_contents( $ids_sites_json ) ); foreach( $sites as $site ) { if ( ! empty( $site->new_id ) && ! empty( $site->legacy_id ) ) { $lookup = ( new CaptainCore\Sites )->get( $site->new_id ); // Skip records missing site field if ( empty( $lookup->site ) ) { continue; } $directory = "{$path}/{$lookup->site}_{$site->legacy_id}"; $directory_new = "{$path}/{$lookup->site}_{$site->new_id}"; // Check if unable to move if ( file_exists( $directory ) && file_exists( $directory_new ) ) { echo "Error can't move $directory as destination {$lookup->site}_{$site->new_id} exists\n"; continue; } // Rename CaptainCore directories given new ID if ( file_exists( $directory ) ) { echo "Renaming $directory to {$lookup->site}_{$site->new_id}\n"; rename( $directory, $directory_new ); } } }