Skip to content

Commit ba4adba

Browse files
committed
Fix update conf file in move
1 parent b369289 commit ba4adba

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

scripts/master_move_instance.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,16 @@
621621
}
622622
}
623623
}
624-
print "--- Set end date of trial on new contract to the same value than the old contract.\n";
625-
$sql = 'UPDATE '.MAIN_DB_PREFIX."contrat_extrafields set date_endfreeperiod = '".$db->idate($oldobject->array_options['options_date_endfreeperiod'])."'";
624+
print "--- Update fields on new contract to the same value than the old contract (end date of trial, timezone).\n";
625+
$sql = 'UPDATE '.MAIN_DB_PREFIX."contrat_extrafields";
626+
$sql .= " SET date_endfreeperiod = '".$db->idate($oldobject->array_options['options_date_endfreeperiod'])."',";
627+
$sql .= " timezone = '".$db->escape($oldobject->array_options['options_timezone'])."'";
626628
$sql .= " WHERE fk_object = ".((int) $newobject->id);
627629
print $sql."\n";
628630
if ($mode == 'confirm' || $mode == 'confirmredirect' || $mode == 'confirmmaintenance') {
629631
$resql = $db->query($sql);
630632
if (!$resql) {
631-
print 'Failed to set end date of trial period'."\n";
633+
print 'Failed to set end date of trial period or timezone'."\n";
632634
exit(-1);
633635
}
634636
}
@@ -722,7 +724,7 @@
722724
$param[] = "--exclude .settings";
723725
$param[] = "--exclude .project";
724726
$param[] = "--exclude *.pdf_preview.png";
725-
$param[] = "--exclude htdocs/conf/conf.php";
727+
//$param[] = "--exclude htdocs/conf/conf.php"; // We want the conf file so we can also update param from this files later
726728
$param[] = "--exclude glpi_config/config_db.php";
727729
$param[] = "--exclude htdocs/inc/downstream.php";
728730

@@ -843,30 +845,51 @@
843845
// STEP 3 of synchro - We should update the value of $dolibarr_main_instance_unique_id if
844846
// it was not done during creation of instance.
845847
$value_of_dolibarr_main_instance_unique_id = '';
848+
$value_of_dolibarr_main_cookie_cryptkey = '';
846849
if (file_exists($sourcedir.'/htdocs/conf/conf.php')) {
847-
$tmpfilecontent = file_get_contents($sourcedir.'/htdocs/conf/conf.php');
850+
chmod($sourcedir.'/htdocs/conf', 0700);
851+
dol_move($sourcedir.'/htdocs/conf/conf.php', $sourcedir.'/htdocs/conf/conf.php.mastermove', '0', 1, 0, 0);
852+
853+
$tmpfilecontent = file_get_contents($sourcedir.'/htdocs/conf/conf.php.mastermove');
848854
foreach (explode("\n", $tmpfilecontent) as $line) {
849855
if (strpos($line, '=') === false) continue;
850856
if (preg_match('/^#/', $line)) continue;
851857
if (preg_match('/^\//', $line)) continue;
858+
if (preg_match('/;/', $line)) continue;
852859
[$key, $val] = explode('=', $line, 2);
853-
if (trim($key) === $param) {
860+
if (trim($key) === '$dolibarr_main_instance_unique_id') {
854861
$value_of_dolibarr_main_instance_unique_id = str_replace("'", "", trim($val));
855-
break;
862+
break;
856863
}
864+
if (trim($key) === '$dolibarr_main_cookie_cryptkey') {
865+
$value_of_dolibarr_main_cookie_cryptkey = str_replace("'", "", trim($val));
866+
}
867+
}
868+
869+
if (empty($value_of_dolibarr_main_instance_unique_id)) {
870+
$value_of_dolibarr_main_instance_unique_id = $value_of_dolibarr_main_cookie_cryptkey;
857871
}
858872

859873
if (empty($nointeractive)) {
860874
print "Press ENTER to continue by running the ssh command to update the dolibarr_main_instance_unique_id on remote target host...\n";
861875
$input = trim(fgets(STDIN));
862876
}
863877

864-
$fullcommand = 'ssh '.$newlogin.'@'.$newserver.' "sed -i \'s/^param=.*/param='.$value_of_dolibarr_main_instance_unique_id.'/\' '.$targetdir.'/htdocs/conf/conf.php"';
878+
$fullcommand = 'ssh -o StrictHostKeyChecking=accept-new '.$newlogin.'@'.$newserver;
879+
$fullcommand .= ' "';
880+
$fullcommand .= 'chmod u+w '.$targetdir.'/htdocs/conf; ';
881+
if ($value_of_dolibarr_main_instance_unique_id) {
882+
$fullcommand .= 'sed -i \'s/^\$dolibarr_main_instance_unique_id=.*/\$dolibarr_main_instance_unique_id=\"'.$value_of_dolibarr_main_instance_unique_id.'\";/\' '.$targetdir.'/htdocs/conf/conf.php; ';
883+
}
884+
$fullcommand .= 'chmod u-w '.$targetdir.'/htdocs/conf; ';
885+
$fullcommand .= '"';
865886

866887
print $fullcommand."\n";
867888

868889
$outputfile = $conf->admin->dir_temp.'/outsshsed.tmp';
869-
$resultarray = $utils->executeCLI($fullcommand, $outputfile, 0);
890+
$resultarray = $utils->executeCLI($fullcommand, $outputfile, 0, null, 1);
891+
892+
var_dump($resultarray);
870893
}
871894

872895

0 commit comments

Comments
 (0)