Skip to content
Snippets Groups Projects
Commit 914dad43 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

cosmo : possibilité d'avoir des patchs php + patch de reprise des auteurs existants dans les album

parent c096bc31
Branches
Tags
No related merge requests found
<?PHP
// Constantes
define("VERSION_COSMOGRAMME","6.42");
define("PATCH_LEVEL","190");
define("PATCH_LEVEL","191");
define("APPLI","cosmogramme");
define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs");
define("CRLF", chr(13) . chr(10));
......
......@@ -118,11 +118,12 @@ class sql
// ---------------------------------------------------
public function update($req,$data)
{
foreach($data as $col => $valeur)
{
$set = null;
foreach($data as $col => $valeur) {
if($set) $set.=",";
$set.= $col . "='".addslashes($valeur)."'";
}
$req=str_replace("@SET@",$set,$req);
try
{
......
......@@ -22,103 +22,162 @@
// PATCHES SGBD
/////////////////////////////////////////////////////////////////////////
include("_init_frame.php");
include '_init_frame.php';
function versionForFile($file) {
return (int)substr($file, -7, 3);
}
function extensionForFile($file) {
return substr($file, -4);
}
// Entete
print("<h1>Mise à niveau de la base de données</h1>");
$niveau_client=getVariable("patch_level");
print('<h3>Niveau de patch : '.$niveau_client.' / '.PATCH_LEVEL.'</h3>');
print '<h1>Mise à niveau de la base de données</h1>';
$niveau_client = getVariable("patch_level");
print('<h3>Niveau de patch : ' . $niveau_client . ' / ' . PATCH_LEVEL . '</h3>');
// Recup des patches a executer
$path="./sql/patch/";
$path = './sql/patch/';
$handle = @opendir($path);
if(!$handle) afficherErreur("Impossible d'ouvrir le dossier : ".$path,true);
while (false !== ($fic = readdir($handle)))
{
if(substr($fic,-4)!=".sql") continue;
$numero=(int)substr($fic,6,3);
if($numero > $niveau_client) $scripts[]=$path.$fic;
if (!$handle)
afficherErreur('Impossible d\'ouvrir le dossier : '.$path, true);
while (false !== ($fic = readdir($handle))) {
if (!in_array(extensionForFile($fic), ['.sql', '.php']))
continue;
$numero = versionForFile($fic);
if ($numero > $niveau_client)
$scripts[] = $path . $fic;
}
sort($scripts);
closedir($handle);
//---------------------------------------------------------------------------------
// Execution des patches
//---------------------------------------------------------------------------------
if($_REQUEST["action"]=="LANCER")
{
if ('LANCER' == $_REQUEST['action']) {
$sql->ignoreErreurs(true);
foreach($scripts as $script)
{
$num_patch=(int)substr($script,-7,3);
print('<h3>Execution patch n° '.$num_patch.'</h3>');
$num_instruction=0;
$data=file($script);
$instructions = [];
$contents = implode(" ", $data);
if (false !== strpos($contents, 'CREATE FUNCTION'))
$instructions[] = $contents;
else {
foreach($scripts as $script) {
$num_patch = versionForFile($script);
print('<h3>Execution patch n° ' . $num_patch . '</h3>');
switch(extensionForFile($script)) {
case '.php':
runPhpUpgrade($script);break;
case '.sql':
runSqlUpgrade($script, $sql);break;
}
// Ecrire le patch dans la base
setVariable('patch_level', $num_patch);
}
print('<h3>Mise à niveau de la base effectuée avec succès</h3>' . BR . BR);
exit;
}
function runPhpUpgrade($script) {
if (isset($_REQUEST['skip_php'])) {
unset($_REQUEST['skip_php']);
return;
}
set_error_handler(
function($no, $message, $file, $line, $context) {
print('<h3 class="erreur">Erreur PHP</h3>');
print('<div class="erreur_sql">');
print("<b>Code : </b>".$no.BR);
print('<b>Erreur : </b>'.$message
. ' file : ' . $file
. ' line : ' . $line
.BR.BR);
print(rendBouton("Ignorer l'erreur et continuer" ,
'util_patch_sgbd.php' ,
'action=LANCER&skip_php=1'));
print('</div>');
die(255);
});
try {
include $script;
} catch (Exception $e) {
print('<h3 class="erreur">Erreur PHP</h3>');
print('<div class="erreur_sql">');
print("<b>Code : </b>".$e->getCode().BR);
print('<b>Erreur : </b>'.$e->getMessage().BR.BR);
print(rendBouton("Ignorer l'erreur et continuer" ,
'util_patch_sgbd.php' ,
'action=LANCER&skip_php=1'));
print('</div>');
exit;
}
}
function runSqlUpgrade($script, $sql) {
$num_instruction = 0;
$data = file($script);
$instructions = [];
$contents = implode(' ', $data);
if (false !== strpos($contents, 'CREATE FUNCTION'))
$instructions[] = $contents;
else {
$instruction = '';
foreach($data as $ligne) {
$ligne = trim($ligne);
if (!$ligne or substr($ligne,0,2)=="--") continue;
$instruction.=$ligne.' ';
if(substr($ligne,-1)!=";")
continue;
$instructions[] = $instruction;
$instruction = '';
foreach($data as $ligne)
{
$ligne=trim($ligne);
if(!$ligne or substr($ligne,0,2)=="--") continue;
$instruction.=$ligne.' ';
if(substr($ligne,-1)!=";") {
continue;
}
$instructions[]=$instruction;
$instruction = '';
}
}
}
foreach($instructions as $instruction)
{
print($instruction.BR);
flush();
// Executer
$num_instruction++;
if($_REQUEST["reprise"] > 0 and $_REQUEST["reprise"] >= $num_instruction){continue;}
try
{
$sql->execute($instruction);
}
catch(Exception $e)
{
print('<h3 class="erreur">Erreur SQL</h3>');
print('<div class="erreur_sql">');
print("<b>Code : </b>".$e->getCode().BR);
print('<b>Erreur : </b>'.$e->getMessage().BR.BR);
print(rendBouton("Ignorer l'erreur et continuer","util_patch_sgbd.php","action=LANCER&reprise=".$num_instruction));
print('</div>');
exit;
}
foreach($instructions as $instruction) {
print($instruction . BR);
flush();
// Executer
$num_instruction++;
if($_REQUEST['reprise'] > 0 and $_REQUEST["reprise"] >= $num_instruction)
continue;
try {
$sql->execute($instruction);
} catch(Exception $e) {
print('<h3 class="erreur">Erreur SQL</h3>');
print('<div class="erreur_sql">');
print("<b>Code : </b>".$e->getCode().BR);
print('<b>Erreur : </b>'.$e->getMessage().BR.BR);
print(rendBouton("Ignorer l'erreur et continuer" ,
'util_patch_sgbd.php' ,
'action=LANCER&reprise=' . $num_instruction));
print('</div>');
exit;
}
// Ecrire le patch dans la base
setVariable("patch_level",$num_patch);
}
print('<h3>Mise à niveau de la base effectuée avec succès</h3>'.BR.BR);
exit;
}
//---------------------------------------------------------------------------------
// Afficher
//---------------------------------------------------------------------------------
print('<div class="liste">');
print('<div style="width:100%;text-align:center">'.rendBouton("Lancer la mise à jour","util_patch_sgbd.php","action=LANCER").'</div>'.BR);
print('<div style="width:100%;text-align:center">'
. rendBouton('Lancer la mise à jour',
'util_patch_sgbd.php',
'action=LANCER') . '</div>' . BR);
print('<table>');
foreach($scripts as $script)
{
$data=file_get_contents($script);
print('<tr><th align="left">Patch n° '.(int)substr($script,-7,3).'</th></tr>');
print('<tr><td>'.str_replace(chr(13).chr(10),BR,$data).'</td></tr>');
foreach($scripts as $script) {
$data = file_get_contents($script);
print('<tr><th align="left">Patch n° ' . versionForFile($script) . '</th></tr>');
print('<tr><td><pre>' . htmlentities($data) . '</pre></td></tr>');
}
print('</table>');
print('</div>'.BR.BR);
?>
print('</table>');
print('</div>' . BR . BR);
?>
\ No newline at end of file
<?php
$albums = Class_Album::findAllBy(['where' => 'auteur is not null and auteur != ""']);
foreach($albums as $album) {
$album
->addAuthor($album->getAuteur())
->save();
}
?>
\ No newline at end of file
......@@ -338,11 +338,6 @@ class Class_Album extends Storm_Model_Abstract {
}
public function __construct() {
$this->path_flash = PATH_FLASH . 'page_flip/';
}
/** @return string */
public function getLibelle() {
return $this->getTitre();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment