Skip to content

Commit

Permalink
hopefully fixes issue chyrp#47, checks on every function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklightbody committed Nov 28, 2011
1 parent fca6992 commit d724e43
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions upgrade.php
Expand Up @@ -283,54 +283,70 @@ function fix_htaccess() {
* Downloads the newest version of chyrp
*/
function download_new_version(){
$e=0;
# delete everything from 2 versions back
if(is_dir("old"))
rmdir("old");
if(!rmdir("old"))
echo __("Please manually delete the directory root/updates"));
$e=1;
if(is_dir("updates"))
rmdir("updates");
mkdir("updates");
mkdir("old");

if(!rmdir("updates"))
echo __("Please manually delete the directory root/updates"));
$e=1;
if(!mkdir("updates"))
echo __("Please manually create the directory root/updates"));
$e=1;
if(!mkdir("old"))
echo __("Please manually create the directory root/old"));
$e=1;

$files = array("includes",
"admin",
"index.php",
"upgrade.php",
"modules",
"feathers",
"themes");

foreach ($files as $file) {
if (file_exists($file)) {
# move stuff to the old dir so we can download the new one
rename($file, 'old/'.$file);
if($e==0){
foreach ($files as $file) {
if (file_exists($file)) {
# move stuff to the old dir so we can download the new one
rename($file, 'old/'.$file);
if(!rename($file, 'old/'.$file))
echo __("Please move the file at root/".$file.' to root/old/'.$file));
}
}
}

$version=file_get_contents("http://api.chyrp.net/v1/chyrp_version.php");
$fp = fopen ("updates/latest.zip", 'w+');
$ch = curl_init("http://chyrp.net/releases/chyrp_v".$version.".zip"); # Here is the file we are downloading
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

$zip = new ZipArchive();
$x = $zip->open("updates/latest.zip");
if ($x === true) {
$zip->extractTo("updates/");
$zip->close();
unlink("updates/latest.zip");
$version=file_get_contents("http://api.chyrp.net/v1/chyrp_version.php");
$fp = fopen ("updates/latest.zip", 'w+');
$ch = curl_init("http://chyrp.net/releases/chyrp_v".$version.".zip"); # Here is the file we are downloading
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
if (function_exists('zip_open')) {
$zip = new ZipArchive();
$x = $zip->open("updates/latest.zip");
if ($x === true) {
$zip->extractTo("updates/");
$zip->close();
unlink("updates/latest.zip");
}
foreach($files as $file)
if (file_exists("updates/chyrp/".$file))
if(!rename("updates/chyrp/".$file, $file))
echo __("Please move the file at root/updates/chyrp/".$file." to root/".$file));
if(file_exists("old/includes/config.yaml.php"))
if(!copy("old/includes/config.yaml.php", "includes/config.yaml.php"))
echo __("Please manually copy the file root/old/includes/config.yaml.php to root/includes/config.yaml.php"));
if(is_dir("updates"))
if(!rmdir("updates"))
echo __("Please manually delete the directory root/updates"));
}
}

foreach($files as $file)
if (file_exists("updates/chyrp/".$file))
rename("updates/chyrp/".$file, $file);
if(file_exists("old/includes/config.yaml.php"))
copy("old/includes/config.yaml.php", "includes/config.yaml.php");
if(is_dir("updates"))
rmdir("updates");
}

/**
Expand Down

0 comments on commit d724e43

Please sign in to comment.