diff --git a/contrib/update/main.php b/contrib/update/main.php
index 3a2f9a11..91ada364 100644
--- a/contrib/update/main.php
+++ b/contrib/update/main.php
@@ -9,18 +9,39 @@
class Update extends Extension {
public function onInitExt(InitExtEvent $event) {
global $config;
- $config->set_default_string("update_url", "http://nodeload.github.com/shish/shimmie2/zipball/master"); //best to avoid using https
- $config->set_default_string("commit_hash", "");
+ $config->set_default_string("update_guser", "shish");
+ $config->set_default_string("update_grepo", "shimmie2");
+ $config->set_default_string("commit_hash", "unknown");
+ $config->set_default_string("commit_time", "unknown");
}
public function onSetupBuilding(SetupBuildingEvent $event) {
global $config;
+ //Grab latest info via JSON.
+ $base = "https://api.github.com/repos/shish/shimmie2/commits";
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $base);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+ $content = curl_exec($curl);
+ curl_close($curl);
+
+
+ $commits = json_decode($content, true);
+ $latestCommit = $commits[0];
+ $commitMessage = $latestCommit["commit"]["message"];
+ $commitDT = explode("T", $latestCommit["commit"]["committer"]["date"]);
+ $commitTD = explode("-", $commitDT[1]);
+ $commitDateTime = $commitDT[0]." (".$commitTD[0].")";
+ $commitSHA = substr($latestCommit["sha"],0,7);
//Would prefer to use the admin panel for this.
//But since the admin panel is optional...kind of stuck to using this.
$sb = new SetupBlock("Update");
$sb->position = 75;
- $sb->add_label("Current Commit: ".$config->get_string('commit_hash'));
- $sb->add_text_option("update_url", "
Update URL: ");
+ $sb->add_label("Current Commit: ".$config->get_string('commit_hash')." | ".$config->get_string('commit_time'));
+ $sb->add_label("
Latest Commit: ".$commitSHA." | ".$commitDateTime." | ".$commitMessage);
+ $sb->add_text_option("update_guser", "
User: ");
+ $sb->add_text_option("update_grepo", "Repo: ");
$sb->add_label("
Update");
$event->panel->add_block($sb);
}
@@ -33,13 +54,30 @@ class Update extends Extension {
}
private function update_shimmie() {
- global $config, $page;
//This is a REALLY ugly function. (Damn my limited PHP knowledge >_<)
+ global $config, $page;
$html = "";
- $url = $config->get_string("update_url");
+ $g_user = $config->get_string("update_guser");
+ $g_repo = $config->get_string("update_grepo");
+ $base = "https://api.github.com/repos/".$g_user."/".$g_repo."/commits";
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $base);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+ $content = curl_exec($curl);
+ curl_close($curl);
+ $commits = json_decode($content, true);
+ $latestCommit = $commits[0];
+ $commitDT = explode("T", $latestCommit["commit"]["committer"]["date"]);
+ $commitTD = explode("-", $commitDT[1]);
+ $commitDateTime = $commitDT[0]." (".$commitTD[0].")";
+ $commitSHA = substr($latestCommit["sha"],0,7);
+
+
+ $url = "http://nodeload.github.com/".$g_user."/".$g_repo."/zipball/".$commitSHA;
$mfile = "master.zip";
- if(glob("*-shimmie2*")){ //#3
- $dir = glob("*-shimmie2*");
+ if(glob("*-shimmie2-".$commitSHA)){ //#3
+ $dir = glob("*-shimmie2-".$commitSHA);
preg_match('@^([a-zA-Z0-9]+\-[0-9a-z]+\-)([^/]+)@i', $dir[0], $matches);
if(!empty($matches[2])){
$html .= "commit: ".$matches[2];
@@ -59,25 +97,12 @@ class Update extends Extension {
$html .= "
data folder emptied!";
}
copy ("./config.php", "./backup/config.php");//Although this stays the same, will keep backup just incase.
- //FIXME: Somehow get rid of this massive rename list.
- rename ("./core", "./backup/core");
- rename ("./".$matches[0]."/core", "./core");
- rename ("./lib", "./backup/lib");
- rename ("./".$matches[0]."/lib", "./lib");
- rename ("./themes", "./backup/themes");
- rename ("./".$matches[0]."/themes", "./themes");
- rename ("./.htaccess", "./backup/.htaccess");
- rename ("./".$matches[0]."/.htaccess", "./.htaccess");
- rename ("./doxygen.conf", "./backup/doxygen.conf");
- rename ("./".$matches[0]."/doxygen.conf", "./doxygen.conf");
- rename ("./index.php", "./backup/index.php");
- rename ("./".$matches[0]."/index.php", "./index.php");
- rename ("./install.php", "./backup/install.php");
- rename ("./".$matches[0]."/install.php", "./install.php");
- rename ("./ext", "./backup/ext");
- rename ("./".$matches[0]."/ext", "./ext");
- rename ("./contrib", "./backup/contrib");
- rename ("./".$matches[0]."/contrib", "./contrib");
+ $folders = array("./core", "./lib", "./themes", "./.htaccess", "./doxygen.conf", "./index.php", "./install.php", "./ext", "./contrib");
+ foreach($folders as $folder){
+ //TODO: Check MD5 of each file, don't rename if same.
+ rename ($folder, "./backup".substr($folder, 1)); //Move old files to backup
+ rename ("./".$matches[0].substr($folder, 1), $folder); //Move new files to main
+ }
$html .= "
old shimmie setup has been moved to /backup/ (excluding images/thumbs)!";
if (is_dir($matches[0])) {
$objects = scandir($matches[0]);
@@ -93,6 +118,7 @@ class Update extends Extension {
$html .= "
shimmie updated (although you may have gotten errors, it should have worked!";
$html .= "
due to the way shimmie loads extensions, all optional extensions have been disabled";
$config->set_string("commit_hash", $commit);
+ $config->set_string("commit_time", $commitDateTime);
$html .= "
new commit_hash has been set!";
}else{
$html .= "Error! Folder does not exist!?"; //Although this should be impossible, shall have it anyway.
diff --git a/core/util.inc.php b/core/util.inc.php
index 158d1f2e..a6af136a 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -944,7 +944,7 @@ function get_debug_info() {
$i_mem = "???";
}
- if($config->get_string("commit_hash") == ""){
+ if($config->get_string("commit_hash") == "unknown"){
$commit = "";
}else{
$commit = " (".$config->get_string("commit_hash").")";