" . $_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);
core::addFileMaintenance();
// Création d'un backUp
self::printSeparateur();
self::print(">> Création du backup", self::$colorLineGrey);
backup::create();
file::cleanFilesByOrder(DIR_BACKUP, BACKUP_LIMIT);
// 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){
$sqlReturn = goSql();
include_once(DIR_MAJ . "sql/maj.php");
if($sqlReturn == FALSE){
self::printSeparateur();
self::print("ERROR : Maj SQL", self::$colorLineRed);
self::printSeparateur();
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 {
self::printSeparateur();
self::print("Maj SQL réalisée", self::$colorLineGrey);
}
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");
}
self::printSeparateur();
self::print(">> Mode maintenance désactivé", self::$colorLineGrey);
core::removeFileMaintenance();
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;
if(is_file($bash)){
try {
exec("bash " .$bash, $output, $retval);
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 {
exec("bash " .$bash, $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;
}
}
}