Ajout de oci-framagrav.php
Script de migration de Framasite Grav vers un espace web d'Ouvaton.
This commit is contained in:
parent
1836013231
commit
8bec815bd2
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
|
||||
function dir_is_empty($dirname)
|
||||
{
|
||||
// Check if directory is empty but ignore install script
|
||||
if (!is_dir($dirname)) return false;
|
||||
foreach (scandir($dirname) as $file) {
|
||||
if (!in_array($file, array('.','..','oci-framagrav.php'))) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// If install directory is not empty stop processing
|
||||
$dest = dirname(__FILE__).'/';
|
||||
if (dir_is_empty($dest) === false) {
|
||||
echo nl2br("Le dossier httpdocs/ doit être vide pour y migrer votre Framasite.\r\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
// We have a ZIP file !
|
||||
if($_FILES["zip_file"]["name"]) {
|
||||
$filename = $_FILES["zip_file"]["name"];
|
||||
$source = $_FILES["zip_file"]["tmp_name"];
|
||||
$type = $_FILES["zip_file"]["type"];
|
||||
|
||||
$name = explode(".", $filename);
|
||||
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
|
||||
foreach($accepted_types as $mime_type) {
|
||||
if($mime_type == $type) {
|
||||
$okay = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$continue = strtolower($name[1]) == 'zip' ? true : false;
|
||||
if(!$continue) {
|
||||
$message = "Votre fichier n'est pas une archive ZIP.";
|
||||
}
|
||||
|
||||
/* PHP current path */
|
||||
$filenoext = basename ($filename, '.zip'); // absolute path (lowercase)
|
||||
$filenoext = basename ($filenoext, '.ZIP'); // absolute path (uppercase)
|
||||
|
||||
$targetdir = $path . $filenoext; // target directory
|
||||
$targetzip = $path . $filename; // target zip file
|
||||
|
||||
/* here it is really happening */
|
||||
if(move_uploaded_file($source, $targetzip)) {
|
||||
$zip = new ZipArchive();
|
||||
$x = $zip->open($targetzip); // open the zip file to extract
|
||||
if ($x === true) {
|
||||
$zip->extractTo('.'); // place in the directory with same name
|
||||
$zip->close();
|
||||
|
||||
unlink($targetzip);
|
||||
}
|
||||
} else {
|
||||
echo nl2br("Une erreur vient de se produire lors du téléversement de votre fichier.\r\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Download latest CMS zip with cURL
|
||||
$ch = curl_init();
|
||||
$source = "https://ouvaton.coop/oci/framagrav-themes.zip";
|
||||
curl_setopt($ch, CURLOPT_URL, $source);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$data = curl_exec($ch);
|
||||
// If any cURL error stop processing
|
||||
if(curl_errno($ch)) {
|
||||
echo nl2br("Une erreur vient de se produire. Rechargez la page pour essayer à nouveau, ou contactez l'assistance si le problème persiste.\r\n");
|
||||
echo 'Erreur cURL : '.curl_error($ch);
|
||||
curl_close($ch);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check HTTP code
|
||||
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
|
||||
case 200:
|
||||
// Create CMS zip
|
||||
$destination = "themes.zip";
|
||||
$file = fopen($destination, "w+");
|
||||
fputs($file, $data);
|
||||
fclose($file);
|
||||
curl_close($ch);
|
||||
|
||||
// Unzip archive file
|
||||
$file = 'themes.zip';
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($file) === TRUE) {
|
||||
$zip->extractTo('.');
|
||||
$zip->close();
|
||||
} else {echo nl2br("Une erreur lors de la décompression de l'archive vient de se produire, contactez l'assistance !\r\n");}
|
||||
// Zip archive is not needed anymore
|
||||
unlink('themes.zip');
|
||||
|
||||
// Redirecting user to CMS install page
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
|
||||
header("Location: http://$host$uri/");
|
||||
// Remove script
|
||||
unlink(__FILE__);
|
||||
exit;
|
||||
default:
|
||||
// If any HTTP error stop processing
|
||||
echo nl2br("Une erreur vient de se produire. Rechargez la page pour essayer à nouveau, ou contactez l'assistance si le problème persiste.\r\n");
|
||||
echo nl2br("Code HTTP : ".$http_code."\r\n");
|
||||
curl_close($ch);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>Migration de votre Framasite chez Ouvaton</title>
|
||||
</head>
|
||||
<body>
|
||||
<?php if($message) echo "<p>$message</p>"; ?>
|
||||
<form enctype="multipart/form-data" method="post" action="">
|
||||
<label>Sélectionnez l'archive ZIP de votre site : <input type="file" name="zip_file" /></label>
|
||||
<br />
|
||||
<input type="submit" name="submit" value="Envoyer" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue