Skip to content

Commit 82812e3

Browse files
Merge pull request #3 from TuxSoftLimited/v-0.0.1-rc-1
Update for Release Candidate 1, Version 0.0.1.
2 parents 072d135 + 1b1b91c commit 82812e3

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

updater/update.php

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
11
<?php
2+
/**
3+
* Update Script for Updating BlogDraw to v0.0.1-rc-1
4+
**/
5+
////Development error reporting. Should usually be turned off in production systems.
26
//error_reporting(E_ALL);
37
//ini_set('display_errors', 'On');
4-
//Update Script for Updating BlogDraw to v0.0.1-beta-2.1
8+
59
echo '<h1>Starting Update...</h1>';
610
echo '<p>Thank you for your patience.</p>';
711

8-
file_put_contents("BlogDrawSrc.tar.gz", fopen("https://github.com/TuxSoftLimited/BlogDraw/archive/v0.0.1-beta-2.1.tar.gz", 'r'));// Get the release from GitHub.
12+
file_put_contents("BlogDrawSrc.tar.gz", fopen("https://github.com/TuxSoftLimited/BlogDraw/archive/v0.0.1-rc-1.tar.gz", 'r'));// Get the release from GitHub.
913
exec('tar -xf BlogDrawSrc.tar.gz');// Unpack it.
1014

1115
//Alter the functions file
1216
$functionsFile = file_get_contents('../functions.php');
1317
$functionsFileData = explode('?><?php', $functionsFile);// Split the client data from the primary functions.
14-
$functionsFile = $functionsFileData[0] . "?>" . file_get_contents('./BlogDraw-0.0.1-beta-2.1/functions.php');
18+
$functionsFile = $functionsFileData[0] . "?>" . file_get_contents('./BlogDraw-0.0.1-rc-1/functions.php');
1519
file_put_contents('../functions.php', $functionsFile);// replace the functions.
1620

1721
//Alter the .htaccess file
1822
$htaccessFile = file_get_contents('../.htaccess');
19-
if (!(strpos($htaccessFile, 'RewriteRule ^(Back/functions) - [F,L,NC]') !== false))// If they don't have the new rewrite rule:
20-
{
21-
$htaccessFileData = explode('RewriteRule ^(functions\.php) - [F,L,NC]', $htaccessFile);
22-
$htaccessFile = $htaccessFileData[0] . "RewriteRule ^(functions\.php) - [F,L,NC]
23-
RewriteRule ^(Back/functions) - [F,L,NC]" . $htaccessFileData[1];
24-
file_put_contents('../.htaccess', $htaccessFile);// Write it in.
25-
}
23+
$htaccessFile = str_replace("Back/", "control/", $htaccessFile);
24+
file_put_contents('../.htaccess', $htaccessFile);// Write it in.
2625

27-
//Remove old analytics table from database
28-
$dBServerLocation = explode("DBSERVER', '", $functionsFileData[0]);
29-
$DBSERVER = explode("')", $dBServerLocation[1])[0];
30-
$dBUserLocation = explode("DBUSER', '", $functionsFileData[0]);
31-
$DBUSER = explode("')", $dBUserLocation[1])[0];
32-
$dBPassLocation = explode("DBPASS', '", $functionsFileData[0]);
33-
$DBPASS = explode("')", $dBPassLocation[1])[0];
34-
$dBNameLocation = explode("DBNAME', '", $functionsFileData[0]);
35-
$DBNAME = explode("')", $dBNameLocation[1])[0];
36-
$dBPrefixLocation = explode("DBPREFIX', '", $functionsFileData[0]);
37-
$DBPREFIX = explode("')", $dBPrefixLocation[1])[0];
38-
$dBConnection = mysqli_connect($DBSERVER,$DBUSER,$DBPASS,$DBNAME);
39-
if (!$dBConnection)
40-
die('Could not connect to database. Please try again later.');
41-
$dBQuery = "CREATE TABLE ". $DBPREFIX . "_AnalyticsTable IF NOT EXISTS;";
42-
mysqli_query($dBConnection,$dBQuery);// To ensure we're not deleting a non-existent table.
43-
$dBQuery = "DROP TABLE ". $DBPREFIX . "_AnalyticsTable;";
44-
mysqli_query($dBConnection,$dBQuery);// Get rid of the table.
45-
mysqli_close($dBConnection);
26+
//Alter the robots.txt file
27+
$robotsFile = file_get_contents('../robots.txt');
28+
$robotsFile = str_replace("/Back", "/control", $robotsFile);
29+
file_put_contents('../robots.txt', $robotsFile);// Write it in.
4630

4731
//Change files
48-
$rootDir = "BlogDraw-0.0.1-beta-2.1";// The root node containing new files.
32+
$rootDir = "BlogDraw-0.0.1-rc-1";// The root node containing new files.
4933
scan_folder($rootDir);// Replaces old BlogDraw files with new ones from the root node.
5034

35+
//Update Database
36+
require_once('../functions.php');
37+
$DBConnection = mysqli_connect(DBSERVER,DBUSER,DBPASS,DBNAME);
38+
if (!$DBConnection)
39+
die('Failed to update Database.');
40+
$DBQuery = "ALTER TABLE ". DBPREFIX . "_LoginTable ADD COLUMN DisplayName VARCHAR(25) NOT NULL;";// Add the rc-1 DisplayName feature.
41+
mysqli_query($DBConnection,$DBQuery);
42+
mysqli_close($DBConnection);
43+
44+
echo "<p>Done! You can now close this window and delete the &quot;updater&quot; directory.</p>";
45+
echo "<p><strong>NEXT STEPS: </strong> For your previous uploads to appear in future versions of BlogDraw, please copy and paste them from the \"Uploads\"directory to the \"uploads\" directory. To ensure better system security, please delete the \"Back\" directory. New versions of those files are now available in the \"control\" directory.</p>";
46+
5147
/**
5248
* This recursively reads a directory and all of it's subdirectories given a relative filepath, then replaces the old files with the new ones.
5349
* Essentially filesystem traversal.
@@ -68,11 +64,12 @@ function scan_folder($dir)
6864
if ($file != ".htaccess" && $file != "functions.php" && $file != "install.php" )// Files we don't want to deal with.
6965
{
7066
$from = explode("updater", realpath($dir) . '/' . $file);
71-
$to = explode("BlogDraw-0.0.1-beta-2.1", realpath($dir) . '/' . $file);
67+
$to = explode("BlogDraw-0.0.1-rc-1", realpath($dir) . '/' . $file);
7268
if (!file_put_contents($_SERVER['DOCUMENT_ROOT'] . $to[1], file_get_contents('.' . $from[1])))
7369
{
7470
$copyToDir = implode('/', explode('/', ($_SERVER['DOCUMENT_ROOT'] . $to[1]), -1));
75-
mkdir($copyToDir, 0755);
71+
if (! mkdir($copyToDir, 0755, TRUE))
72+
echo '<br />Failed to create directory ' . $copyToDir . '!';
7673
$newFile = fopen($_SERVER['DOCUMENT_ROOT'] . $to[1], "w");
7774
fwrite($newFile, file_get_contents('.' . $from[1]));
7875
fclose($newFile);
@@ -81,6 +78,4 @@ function scan_folder($dir)
8178
}
8279
}
8380
}
84-
85-
echo "<p>Done! You can now close this window and delete the &quot;updater&quot; directory.</p>";
86-
?>
81+
?>

0 commit comments

Comments
 (0)