|
524 | 524 | } |
525 | 525 |
|
526 | 526 | // 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. |
527 | 528 | $command='php '.DOL_DOCUMENT_ROOT."/custom/sellyoursaas/myaccount/register_instance.php ".escapeshellarg($productref)." ".escapeshellarg($newinstance)." ".escapeshellarg($newpass)." ".escapeshellarg($oldobject->thirdparty->id); |
528 | 529 | $commandnopass='php '.DOL_DOCUMENT_ROOT."/custom/sellyoursaas/myaccount/register_instance.php ".escapeshellarg($productref)." ".escapeshellarg($newinstance)." --a-new-password-- ".escapeshellarg($oldobject->thirdparty->id); |
529 | 530 | $command.=" ".escapeshellarg($oldinstance); |
|
698 | 699 | //print 'SFTP old password '.$oldospass."\n"; |
699 | 700 |
|
700 | 701 |
|
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 |
702 | 703 | $command = "rsync"; |
703 | 704 | $param = array(); |
704 | 705 | //if (! in_array($mode, array('confirm', 'confirmredirect', 'confirmmaintenance'))) $param[]="-n"; |
|
762 | 763 | print $content_grabbed."\n"; |
763 | 764 |
|
764 | 765 |
|
765 | | -// Now we copy files on the target directory |
| 766 | +// STEP 2 of synchro - Now we copy files on the target directory |
| 767 | + |
766 | 768 | $sourcedir = $tmptargetdir; |
767 | 769 | $targetdir = getDolGlobalString('DOLICLOUD_INSTANCES_PATH') . '/'.$newlogin.'/'.$newdatabasedb; |
768 | 770 |
|
|
838 | 840 | print $content_grabbed."\n"; |
839 | 841 |
|
840 | 842 |
|
| 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 | + |
841 | 873 | // Now we copy database from source to target |
842 | 874 |
|
| 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 | + |
843 | 880 | print '--- Dump database '.$olddbname.' into '.$tmptargetdir.'/mysqldump_'.$olddbname.'_'.dol_print_date(dol_now('gmt'), "%d", 'gmt').".sql\n"; |
844 | 881 |
|
845 | 882 |
|
846 | | -// First we backup the source database |
| 883 | +// STEP 1 of database copy - we backup the source database |
847 | 884 | $command="mysqldump"; |
848 | 885 | $param=array(); |
849 | 886 | $param[]=$olddbname; |
|
886 | 923 | } |
887 | 924 |
|
888 | 925 |
|
889 | | -// We load the backup on target database |
| 926 | +// STEP 2 of database copy - We load the backup on target database |
890 | 927 | print '--- Load database '.$newdatabasedb.' from '.$tmptargetdir.'/mysqldump_'.$olddbname.'_'.dol_print_date(dol_now('gmt'), "%d", 'gmt').".sql\n"; |
891 | 928 | //print "If the mysql fails, try to run mysql -u".$newloginbase." -p".$newpasswordbase." -D ".$newobject->database_db."\n"; |
892 | 929 |
|
|
0 commit comments