Skip to content

Commit

Permalink
ENHANCEMENT: Add upgrade check
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Cheese committed Aug 3, 2012
1 parent e443aed commit 55f4671
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
8 changes: 8 additions & 0 deletions bin/silversmith.php
Expand Up @@ -98,6 +98,14 @@
SilverSmith::load_field_manifest();
SilverSmith::load_class_manifest();
SilverSmith::load_interface_manifest();

if($stamp = @file_get_contents($script_dir."/upgrade")) {
$diff = time() - (int) $stamp;
if($diff > 3600) {
say("Checking for upgrade...");
SilverSmith::upgrade();
}
}
say("done");
}
}
Expand Down
28 changes: 15 additions & 13 deletions code/SilverSmith.php
Expand Up @@ -39,9 +39,12 @@ protected static function get_subclasses($parentClassName) {


public static function is_upgrade_available() {
$url = "http://www.silversmithproject.com/check_version.php?v=" . self::get_silversmith_version();
$result = @file_get_contents($url);
return ($result == "upgrade");
exec(self::$script_dir."/git fetch");
$response = (self::$script_dir."/git diff master origin/master");
if(!empty($response)) {
return true;
}
return false;
}


Expand Down Expand Up @@ -674,11 +677,11 @@ public static function build_fixtures($params = array ()) {
}


public static function uninstall($params = array ()) {
$response = (isset($params['force'])) ? "y" : ask("Are you sure you want to uninstall SilverSmith? (y/n)");
public static function cli_uninstall($params = array ()) {
$response = (isset($params['force'])) ? "y" : ask("Are you sure you want to uninstall the SilverSmith CLI tools? (y/n)");
if (strtolower($response) == "y") {
exec("sudo rm -rf self::$script_dir");
exec("sudo rm /usr/local/bin/silversmith3");
exec("sudo rm -rf /usr/local/lib/silversmith");
exec("sudo rm /usr/local/bin/silversmith");
}
}

Expand Down Expand Up @@ -757,8 +760,11 @@ public static function upgrade($params = array ()) {
if (self::is_upgrade_available()) {
$response = ask("An upgrade is available. Install now? (y/n)");
if (strtolower($response) == "y") {
exec("silversmith uninstall --force");
exec("curl http://www.silversmithproject.com/install | sh");
exec(self::$script_dir."/git reset --hard");
exec(self::$script_dir."/git pull");
$fh = fopen(self::$script_dir."/upgrade","w");
fwrite($fh, time());
fclose($fh);
} else
die();
} else {
Expand All @@ -767,10 +773,6 @@ public static function upgrade($params = array ()) {
}


public static function version() {
say("Version ID: " . self::get_silversmith_version());
die();
}


public static function spec($params = array ()) {
Expand Down
Empty file added upgrade
Empty file.

0 comments on commit 55f4671

Please sign in to comment.