Skip to content

Commit 95b8112

Browse files
committed
NEW Move also the value of dolibarr_main_instance_unique_id
1 parent 905b7d5 commit 95b8112

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

scripts/master_move_instance.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@
524524
}
525525

526526
// Create virgin envelop for the new instance. The register_instance will use the $oldinstance name
527+
// Note that if the old instance had a value into instance_unique_id, the creation of the new one should reuse it.
527528
$command='php '.DOL_DOCUMENT_ROOT."/custom/sellyoursaas/myaccount/register_instance.php ".escapeshellarg($productref)." ".escapeshellarg($newinstance)." ".escapeshellarg($newpass)." ".escapeshellarg($oldobject->thirdparty->id);
528529
$commandnopass='php '.DOL_DOCUMENT_ROOT."/custom/sellyoursaas/myaccount/register_instance.php ".escapeshellarg($productref)." ".escapeshellarg($newinstance)." --a-new-password-- ".escapeshellarg($oldobject->thirdparty->id);
529530
$command.=" ".escapeshellarg($oldinstance);
@@ -698,7 +699,7 @@
698699
//print 'SFTP old password '.$oldospass."\n";
699700

700701

701-
// First we get the files of the source to move
702+
// STEP 1 of synchro - We get the files of the source to move
702703
$command = "rsync";
703704
$param = array();
704705
//if (! in_array($mode, array('confirm', 'confirmredirect', 'confirmmaintenance'))) $param[]="-n";
@@ -762,7 +763,8 @@
762763
print $content_grabbed."\n";
763764

764765

765-
// Now we copy files on the target directory
766+
// STEP 2 of synchro - Now we copy files on the target directory
767+
766768
$sourcedir = $tmptargetdir;
767769
$targetdir = getDolGlobalString('DOLICLOUD_INSTANCES_PATH') . '/'.$newlogin.'/'.$newdatabasedb;
768770

@@ -838,12 +840,47 @@
838840
print $content_grabbed."\n";
839841

840842

843+
// STEP 3 of synchro - We should update the value of $dolibarr_main_instance_unique_id in case
844+
// it was not done during creation of instance.
845+
$value_of_dolibarr_main_instance_unique_id = '';
846+
if (file_exists($sourcedir.'/htdocs/conf/conf.php')) {
847+
$tmpfilecontent = file_get_contents($sourcedir.'/htdocs/conf/conf.php');
848+
foreach (explode("\n", $tmpfilecontent) as $line) {
849+
if (strpos($line, '=') === false) continue;
850+
if (preg_match('/^#/', $line)) continue;
851+
if (preg_match('/^\//', $line)) continue;
852+
[$key, $val] = explode('=', $line, 2);
853+
if (trim($key) === $param) {
854+
$value_of_dolibarr_main_instance_unique_id = str_replace("'", "", trim($val));
855+
break;
856+
}
857+
}
858+
859+
if (empty($nointeractive)) {
860+
print "Press ENTER to continue by running the ssh command to update the dolibarr_main_instance_unique_id on remote target host...\n";
861+
$input = trim(fgets(STDIN));
862+
}
863+
864+
$fullcommand = 'ssh '.$newlogin.'@'.$newserver.' "sed -i \'s/^param=.*/param='.$value_of_dolibarr_main_instance_unique_id.'/\' '.$targetdir.'/htdocs/conf/conf.php"';
865+
866+
print $fullcommand."\n";
867+
868+
$outputfile = $conf->admin->dir_temp.'/outsshsed.tmp';
869+
$resultarray = $utils->executeCLI($fullcommand, $outputfile, 0);
870+
}
871+
872+
841873
// Now we copy database from source to target
842874

875+
if (empty($nointeractive)) {
876+
print "Press ENTER to continue by running the dump/load of database...\n";
877+
$input = trim(fgets(STDIN));
878+
}
879+
843880
print '--- Dump database '.$olddbname.' into '.$tmptargetdir.'/mysqldump_'.$olddbname.'_'.dol_print_date(dol_now('gmt'), "%d", 'gmt').".sql\n";
844881

845882

846-
// First we backup the source database
883+
// STEP 1 of database copy - we backup the source database
847884
$command="mysqldump";
848885
$param=array();
849886
$param[]=$olddbname;
@@ -886,7 +923,7 @@
886923
}
887924

888925

889-
// We load the backup on target database
926+
// STEP 2 of database copy - We load the backup on target database
890927
print '--- Load database '.$newdatabasedb.' from '.$tmptargetdir.'/mysqldump_'.$olddbname.'_'.dol_print_date(dol_now('gmt'), "%d", 'gmt').".sql\n";
891928
//print "If the mysql fails, try to run mysql -u".$newloginbase." -p".$newpasswordbase." -D ".$newobject->database_db."\n";
892929

0 commit comments

Comments
 (0)