" . $_string . "";
} else {
echo '
' . $_string . '
';
}
}
public static function printSeparateur(){
self::print("**********************");
}
public static function start(){
self::printSeparateur();
self::print(">> Démarrage de la mise à jour de " . DOMAIN_CMS, self::$colorLineGrey);
historique::recRef("/parametres.html");
historique::add(array(
"idType" => historique::getIdRef("ACTION"),
"idUser" => session::getId(),
"idPage" => historique::getIdRef("/parametres.html"),
"log" => "Lancement de la mise à jour [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]"
));
// Activation du mode maintenance
self::printSeparateur();
self::print(">> Mode maintenance activé", self::$colorLineGrey);
debug::addFile("maintenance");
// Création d'un backUp
self::printSeparateur();
self::print(">> Création du backup", self::$colorLineGrey);
backup::create();
file::cleanFilesByOrder(DIR_BACKUP, BACKUP_LIMIT);
self::printSeparateur();
self::print(">> Récupération de la branche GIT", self::$colorLineGrey);
// Git
$gitReturn = self::bashMaj();
if($gitReturn == FALSE){
self::printSeparateur();
self::print("ERROR : Repo GIT [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]", self::$colorLineRed);
self::printSeparateur();
self::print(">> ROLLBACK : Restauration des données", self::$colorLineOrange);
backup::restore(DIR_BACKUP . backup::last());
alert::recError("Mise à jour en erreur de [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]");
historique::recRef("/parametres.html");
historique::add(array(
"idType" => historique::getIdRef("ERROR"),
"idUser" => session::getId(),
"idPage" => historique::getIdRef("/parametres.html"),
"log" => "Erreur lors de la mise à jour [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]"
));
} else {
self::printSeparateur();
self::print("Mise à jour du repo GIT [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "] effectué", self::$colorLineGrey);
}
if($gitReturn == TRUE){
self::printSeparateur();
$sql = maj::readFileSQL();
$tmpMajSQL = md5($sql);
if($tmpMajSQL != core::getConfig("LAST_MD5_MYSQL")) {
if($sql != NULL AND strlen(trim($sql)) != 0){
$sqlReturn = maj::query($sql);
if($sqlReturn == FALSE){
self::print("ERROR : Maj SQL", self::$colorLineRed);
self::print(">> ROLLBACK : Restauration des données", self::$colorLineOrange);
backup::restore(DIR_BACKUP . backup::last());
alert::recError("ERROR : Maj SQL");
historique::recRef("/parametres.html");
historique::add(array(
"idType" => historique::getIdRef("ERROR"),
"idUser" => session::getId(),
"idPage" => historique::getIdRef("/parametres.html"),
"log" => "ERROR : Maj SQL"
));
} else {
core::updateConfig("LAST_MD5_MYSQL", $tmpMajSQL);
self::print("La mise à jour de la base de données s'est correctement réalisée", self::$colorLineGrey);
}
} else {
$sqlReturn = TRUE;
self::print("Pas de Maj SQL à réaliser", self::$colorLineGrey);
}
} else {
$sqlReturn = TRUE;
self::print("Le fichier maj.sql a déjà été exécuté et a été ignoré.", self::$colorLineOrange);
}
self::printSeparateur();
self::print(">> Réinitialisation des JSON", self::$colorLineGrey);
json::create("salaries");
json::create("excel");
json::create("excel-proweb");
json::create("events");
json::create("users");
json::create("salaries-proweb");
json::create("lotterys");
json::create("banque-lignes-1");
json::create("banque-lignes-2");
json::create("banque-lignes-3");
json::create("banque-lignes-4");
json::create("banque-csv");
json::create("documents");
json::create("documents-limited");
}
self::printSeparateur();
self::print(">> Mode maintenance désactivé", self::$colorLineGrey);
debug::removeFile("maintenance");
self::printSeparateur();
self::print(">> Fin de la mise à jour de " . DOMAIN_CMS, self::$colorLineGrey);
self::printSeparateur();
if($gitReturn == TRUE AND $sqlReturn == TRUE){
historique::recRef("/parametres.html");
historique::add(array(
"idType" => historique::getIdRef("ACTION"),
"idUser" => session::getId(),
"idPage" => historique::getIdRef("/parametres.html"),
"log" => "Mise à jour [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "] terminée"
));
self::print("MAJ EN SUCCES [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]", self::$colorLineGrey);
self::printSeparateur();
} else {
self::print("MAJ EN ERREUR [" . MAJ_TARGET . " - " . git::getCommitHash(MAJ_TARGET) . "]", self::$colorLineRed);
self::printSeparateur();
}
}
public static function bashMaj(){
$output = NULL;
$retval = NULL;
$bash = DIR_MAJ . MAJ . ".sh";
$error = 0;
// Affichage du chemin du script
self::print("Script path: " . $bash, self::$colorLineGrey);
if(is_file($bash)){
try {
// Exécution du script avec redirection des erreurs
exec("bash " . $bash . " 2>&1", $output, $retval);
// Affichage du code de retour
self::print("Return code: " . $retval, self::$colorLineGrey);
foreach ($output as $value) {
self::print($value, self::$colorLineGrey);
if(git::checkError($value) == TRUE){
$error = 1;
}
}
} catch (\Throwable $th) {
self::print("ERROR : " . $bash, self::$colorLineRed);
return FALSE;
}
return ($error == 0) ? TRUE : FALSE;
} else {
self::print("ERROR : " . $bash . " not found", self::$colorLineRed);
return FALSE;
}
}
public static function bashFetch(){
$output = NULL;
$retval = NULL;
$bash = DIR_MAJ . "get-origin.sh";
$error = 0;
if(is_file($bash)){
try {
// Exécution du script avec redirection des erreurs
exec("bash " . $bash . " 2>&1", $output, $retval);
} catch (\Throwable $th) {
alert::recError("ERROR : " . $bash);
return FALSE;
}
return $error == 0 ? TRUE : FALSE;
} else {
alert::recError("ERROR : " . $bash . " not found");
return FALSE;
}
}
}