Created
October 14, 2017 15:23
-
-
Save novia713/72a62c7d1d25893d6ab3eaca8cc79fdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = "/Users/leandro/.console/version"; | |
$saved_version = "0"; | |
$saved_date = ""; | |
if (file_exists($file)){ | |
$fp = fopen($file, 'r'); | |
list($saved_date, $saved_version) = explode("|", @fread($fp, filesize($file))); | |
} | |
//if never checked or today didn't check | |
if (date('Ymd') != $saved_date){ | |
$version = | |
@json_decode( | |
@file_get_contents( | |
"http://api.github.com/repos/hechoendrupal/drupal-console/releases/latest", | |
false, | |
stream_context_create([ 'http' => [ 'method' => 'GET', 'header' => [ 'User-Agent: PHP' ] ] ]) | |
))->tag_name; | |
if ( ((int)str_replace(".", "", $version) > (int)str_replace(".", "", $saved_version)) && ($saved_version > 0)){ | |
print "version $version update available"; | |
} | |
if ($version){ | |
$fp = fopen($file, 'w'); | |
fwrite($fp, date('Ymd'). "|". $version); | |
fclose($fp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment