From 643cda03024aeb39bb435d4e6681d26148676829 Mon Sep 17 00:00:00 2001 From: Kanti Date: Tue, 11 Nov 2014 08:38:00 +0100 Subject: [PATCH] composer updater && Added .updateignore --- composer.json | 2 +- composer.lock | 21 ++- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 8 +- vendor/composer/installed.json | 80 ++++----- vendor/kanti/hub-updater/.updateignore | 1 + vendor/kanti/hub-updater/CacheOneFile.php | 23 ++- vendor/kanti/hub-updater/HubUpdater.php | 259 +++++++++++++++++------------- vendor/kanti/hub-updater/composer.json | 4 +- vendor/kanti/hub-updater/example.php | 2 +- vendor/kanti/hub-updater/example2.php | 22 +-- 11 files changed, 231 insertions(+), 193 deletions(-) create mode 100644 vendor/kanti/hub-updater/.updateignore diff --git a/composer.json b/composer.json index c4f9204..70a30cb 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,6 @@ "require": { "michelf/php-markdown": "1.4.*@dev", "suin/php-rss-writer": ">=1.0", - "kanti/hub-updater": "dev-master" + "kanti/hub-updater": "0.1" } } diff --git a/composer.lock b/composer.lock index b605dc8..a2d12e4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,24 +4,24 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "09a845c7ac1f579f79cdd0196a86199d", + "hash": "d7bc647b7c26ac62864fbe9199d1565a", "packages": [ { "name": "kanti/hub-updater", - "version": "dev-master", + "version": "0.1", "source": { "type": "git", "url": "https://github.com/Kanti/hub-updater.git", - "reference": "fd965ed3524720d70a0cdddbd95e83f536c9b24f" + "reference": "fc70ff8ad8e68db921914106e5f4b56557358dfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/fd965ed3524720d70a0cdddbd95e83f536c9b24f", - "reference": "fd965ed3524720d70a0cdddbd95e83f536c9b24f", + "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/fc70ff8ad8e68db921914106e5f4b56557358dfb", + "reference": "fc70ff8ad8e68db921914106e5f4b56557358dfb", "shasum": "" }, "require": { - "php": ">=5.4.0" + "php": ">=5.3.0" }, "type": "library", "autoload": { @@ -29,7 +29,7 @@ "Kanti\\": "" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "http://packagist.org/downloads/", "license": [ "GPL-2.0" ], @@ -41,8 +41,8 @@ "role": "Developer" } ], - "description": "Simple Github Updater for Web Projects [PHP]", - "time": "2014-10-31 18:20:52" + "description": "Simple Github Updater for Web Projects", + "time": "2014-11-11 07:32:09" }, { "name": "michelf/php-markdown", @@ -145,8 +145,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "michelf/php-markdown": 20, - "kanti/hub-updater": 20 + "michelf/php-markdown": 20 }, "prefer-stable": false, "platform": [], diff --git a/vendor/autoload.php b/vendor/autoload.php index 31e0459..4dd19fa 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3::getLoader(); +return ComposerAutoloaderInit94770e161b9a4024b163320059f87e51::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 7e17f32..d883f20 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3 +class ComposerAutoloaderInit94770e161b9a4024b163320059f87e51 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit94770e161b9a4024b163320059f87e51', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit94770e161b9a4024b163320059f87e51', 'loadClassLoader')); $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -44,7 +44,7 @@ class ComposerAutoloaderInit181c8f31ce07c1aa29ef78a7a9b430c3 } } -function composerRequire181c8f31ce07c1aa29ef78a7a9b430c3($file) +function composerRequire94770e161b9a4024b163320059f87e51($file) { require $file; } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index b3d4567..2fa832e 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1,44 +1,4 @@ [ - { - "name": "kanti/hub-updater", - "version": "dev-master", - "version_normalized": "9999999-dev", - "source": { - "type": "git", - "url": "https://github.com/Kanti/hub-updater.git", - "reference": "fd965ed3524720d70a0cdddbd95e83f536c9b24f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/fd965ed3524720d70a0cdddbd95e83f536c9b24f", - "reference": "fd965ed3524720d70a0cdddbd95e83f536c9b24f", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "time": "2014-10-31 18:20:52", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-4": { - "Kanti\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0" - ], - "authors": [ - { - "name": "Kanti", - "email": "git@kanti.de", - "homepage": "https://kanti.de", - "role": "Developer" - } - ], - "description": "Simple Github Updater for Web Projects [PHP]" - }, { "name": "michelf/php-markdown", "version": "dev-lib", @@ -138,5 +98,45 @@ "rss", "writer" ] + }, + { + "name": "kanti/hub-updater", + "version": "0.1", + "version_normalized": "0.1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Kanti/hub-updater.git", + "reference": "fc70ff8ad8e68db921914106e5f4b56557358dfb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kanti/hub-updater/zipball/fc70ff8ad8e68db921914106e5f4b56557358dfb", + "reference": "fc70ff8ad8e68db921914106e5f4b56557358dfb", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2014-11-11 07:32:09", + "type": "library", + "installation-source": "source", + "autoload": { + "psr-4": { + "Kanti\\": "" + } + }, + "notification-url": "http://packagist.org/downloads/", + "license": [ + "GPL-2.0" + ], + "authors": [ + { + "name": "Kanti", + "email": "git@kanti.de", + "homepage": "https://kanti.de", + "role": "Developer" + } + ], + "description": "Simple Github Updater for Web Projects" } ] diff --git a/vendor/kanti/hub-updater/.updateignore b/vendor/kanti/hub-updater/.updateignore new file mode 100644 index 0000000..b43bf86 --- /dev/null +++ b/vendor/kanti/hub-updater/.updateignore @@ -0,0 +1 @@ +README.md diff --git a/vendor/kanti/hub-updater/CacheOneFile.php b/vendor/kanti/hub-updater/CacheOneFile.php index 95ea118..d9def00 100644 --- a/vendor/kanti/hub-updater/CacheOneFile.php +++ b/vendor/kanti/hub-updater/CacheOneFile.php @@ -2,31 +2,38 @@ namespace Kanti; -class CacheOneFile { - +class CacheOneFile +{ protected $fileName = ""; protected $holdTime = 43200; //12h - public function __construct($fileName, $holdTime = 43200) { + public function __construct($fileName, $holdTime = 43200) + { $this->fileName = $fileName; $this->holdTime = $holdTime; } - public function is() { - if (!file_exists($this->fileName)) + public function is() + { + if (! file_exists($this->fileName)) { return false; + } if (filemtime($this->fileName) < ( time() - $this->holdTime )) { unlink($this->fileName); + return false; } + return true; } - public function get() { + public function get() + { return file_get_contents($this->fileName); } - public function set($content) { + public function set($content) + { file_put_contents($this->fileName, $content); } -} \ No newline at end of file +} diff --git a/vendor/kanti/hub-updater/HubUpdater.php b/vendor/kanti/hub-updater/HubUpdater.php index 4bd905d..0af789f 100644 --- a/vendor/kanti/hub-updater/HubUpdater.php +++ b/vendor/kanti/hub-updater/HubUpdater.php @@ -2,88 +2,85 @@ namespace Kanti; -class HubUpdater { - - protected $options = [ - "cacheFile" => "downloadInfo.json", - "versionFile" => "installedVersion.json", - "zipFile" => "tmpZipFile.zip", - - "name" => "", - "branch" => "master", - "cache" => "cache/", - "save" => "", - "prerelease" => false, - ]; - - protected $allRelease = []; - protected $newestRelease = []; +class HubUpdater +{ + protected $options = array( + "cacheFile" => "downloadInfo.json", + "versionFile" => "installedVersion.json", + "zipFile" => "tmpZipFile.zip", + "updateignore" => ".updateignore", + + "name" => "", + "branch" => "master", + "cache" => "cache/", + "save" => "", + "prerelease" => false, + ); + + protected $allRelease = array(); + protected $newestRelease = array(); protected $streamContext = null; - public function __construct($option) { - if(is_array($option)) - { - if(! isset($option['name'])) - { - throw new Exception('No Name in Option Set'); - } - $this->options = $option + $this->options; - } - else if(is_string($option)) - { - $this->options['name'] = $option; - } - else - { - throw new Exception('No Option Set'); - } - - $this->options['cache'] = rtrim($this->options['cache'],'/'); - if($this->options['cache'] !== ''){ - $this->options['cache'] .= '/'; - if (!file_exists($this->options['cache'])) { - mkdir($this->options['cache']); - } - } - $this->options['save'] = rtrim($this->options['save'],'/'); - if($this->options['save'] !== ''){ - $this->options['save'] .= '/'; - if (!file_exists($this->options['save'])) { - mkdir($this->options['save']); - } - } - - $this->cachedInfo = new CacheOneFile($this->options['cache'] . $this->options['cacheFile']); + public function __construct($option) + { + if (is_array($option)) { + if (! isset($option['name'])) { + throw new Exception('No Name in Option Set'); + } + $this->options = $option + $this->options; + } elseif (is_string($option)) { + $this->options['name'] = $option; + } else { + throw new Exception('No Option Set'); + } + + $this->options['save'] = rtrim($this->options['save'], '/'); + if ($this->options['save'] !== '') { + $this->options['save'] .= '/'; + if (!file_exists($this->options['save'])) { + mkdir($this->options['save']); + } + } + $this->options['cache'] = $this->options['save'] . rtrim($this->options['cache'], '/'); + if ($this->options['cache'] !== '') { + $this->options['cache'] .= '/'; + if (!file_exists($this->options['cache'])) { + mkdir($this->options['cache']); + } + } + + $this->cachedInfo = new CacheOneFile($this->options['cache'] . $this->options['cacheFile']); $this->streamContext = stream_context_create( - array( - 'http' => array( - 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n - Accept: application/vnd.github.v3+json", - ), - 'ssl' => array( - 'cafile' => dirname(__FILE__) . '/ca_bundle.crt', - 'verify_peer' => true, - ), - ) + array( + 'http' => array( + 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n + Accept: application/vnd.github.v3+json", + ), + 'ssl' => array( + 'cafile' => dirname(__FILE__) . '/ca_bundle.crt', + 'verify_peer' => true, + ), + ) ); $this->streamContext2 = stream_context_create( - array( - 'http' => array( - 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n", - ), - 'ssl' => array( - 'cafile' => dirname(__FILE__) . '/ca_bundle.crt', - 'verify_peer' => true, - ), - ) + array( + 'http' => array( + 'header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n", + ), + 'ssl' => array( + 'cafile' => dirname(__FILE__) . '/ca_bundle.crt', + 'verify_peer' => true, + ), + ) ); $this->allRelease = $this->getRemoteInfos(); } - protected function getRemoteInfos() { + protected function getRemoteInfos() + { $path = "https://api.github.com/repos/" . $this->options['name'] ."/releases"; - if ($this->cachedInfo->is()) { + if ($this->cachedInfo->is()) { $fileContent = $this->cachedInfo->get(); } else { if (!in_array('https', stream_get_wrappers())) { @@ -95,103 +92,143 @@ class HubUpdater { return array(); } $json = json_decode($fileContent, true); - if(isset($json['message'])) - { - $json = []; - } + if (isset($json['message'])) { + $json = array(); + } $fileContent = json_encode($json, JSON_PRETTY_PRINT); $this->cachedInfo->set($fileContent); + return $json; } + return json_decode($fileContent, true); } - public function able() { - if (!in_array('https', stream_get_wrappers())) + public function able() + { + if (!in_array('https', stream_get_wrappers())) { return false; - if (empty($this->allRelease)) + } + if (empty($this->allRelease)) { return false; - - foreach($this->allRelease as $release) - { - if(!$this->options['prerelease'] && $release['prerelease']) - continue; - if($this->options['branch'] !== $release['target_commitish']) - continue; - $this->newestRelease = $release; - break; - } - + } + + foreach ($this->allRelease as $release) { + if (!$this->options['prerelease'] && $release['prerelease']) { + continue; + } + if ($this->options['branch'] !== $release['target_commitish']) { + continue; + } + $this->newestRelease = $release; + break; + } + if (file_exists($this->options['cache'] . $this->options['versionFile'])) { $fileContent = file_get_contents($this->options['cache'] . $this->options['versionFile']); $current = json_decode($fileContent, true); - if (isset($current['id']) && $current['id'] == $this->newestRelease['id']) + if (isset($current['id']) && $current['id'] == $this->newestRelease['id']) { return false; - if (isset($current['tag_name']) && $current['tag_name'] == $this->newestRelease['tag_name']) + } + if (isset($current['tag_name']) && $current['tag_name'] == $this->newestRelease['tag_name']) { return false; + } } + return true; } - public function update() { + public function update() + { if ($this->able()) { - if ($this->download($this->newestRelease['zipball_url'] )) { + if ($this->download($this->newestRelease['zipball_url'])) { if ($this->unZip()) { unlink($this->options['cache'] . $this->options['zipFile']); file_put_contents($this->options['cache'] . $this->options['versionFile'], json_encode(array( "id" => $this->newestRelease['id'], "tag_name" => $this->newestRelease['tag_name'] ), JSON_PRETTY_PRINT)); + return true; } } } + return false; } - protected function download($url) { + protected function download($url) + { $file = @fopen($url, 'r', false, $this->streamContext2); - if ($file == false) + if ($file == false) { return false; - file_put_contents(dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile'], $file); - fclose($file); + } + file_put_contents( + dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile'], + $file + ); + fclose($file); + return true; } - protected function unZip() { + protected function unZip() + { $path = dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->options['cache'] . $this->options['zipFile']; - - $zip = new \ZipArchive; + $updateIgnore = array(); + if (file_exists($this->options['updateignore'])) { + $updateIgnore = file($this->options['updateignore']); + foreach($updateIgnore as &$ignore) { + $ignore = $this->options['save'] . trim($ignore); + } + } + + $zip = new \ZipArchive(); if ($zip->open($path) === true) { $cutLength = strlen($zip->getNameIndex(0)); for ($i = 1; $i < $zip->numFiles; $i++) {//iterate throw the Zip - $fileName = $zip->getNameIndex($i); - $stat = $zip->statIndex($i); - if ($stat["crc"] == 0) { - $dirName = $this->options['save'] . substr($fileName, $cutLength); - if (!file_exists($dirName)) { - mkdir($dirName); + $name = $this->options['save'] . substr($zip->getNameIndex($i), $cutLength); + + $do = true; + + foreach($updateIgnore as $ignore) { + if (substr($name, 0, strlen($ignore)) == $ignore) { + $do = false; + break; + } + } + + if ($do) { + $stat = $zip->statIndex($i); + if ($stat["crc"] == 0) { + if (!file_exists($name)) { + mkdir($name); + } + } else { + copy("zip://" . $path . "#" . $zip->getNameIndex($i), $name); } - } else { - copy("zip://" . $path . "#" . $fileName, $this->options['save'] . substr($fileName, $cutLength)); } } $zip->close(); + return true; } else { return false; } } - public function printOne() { + public function printOne() + { $string = "

Updated to

"; $string .= "

[" . $this->newestRelease['tag_name'] . "] " . $this->newestRelease['name'] . "

\n"; $string .= "

" . $this->newestRelease['body'] . "

\n"; + return $string; } - public function getName() { + public function getName() + { return $this->newestRelease['tag_name']; } -} \ No newline at end of file +} diff --git a/vendor/kanti/hub-updater/composer.json b/vendor/kanti/hub-updater/composer.json index 9e15f5d..6a915b5 100644 --- a/vendor/kanti/hub-updater/composer.json +++ b/vendor/kanti/hub-updater/composer.json @@ -1,6 +1,6 @@ { "name": "kanti/hub-updater", - "description": "Simple Github Updater for Web Projects [PHP]", + "description": "Simple Github Updater for Web Projects", "license": "GPL-2.0", "authors": [ { @@ -17,7 +17,7 @@ }, "minimum-stability": "dev", "require": { - "php": ">=5.4.0" + "php": ">=5.3.0" }, "autoload": { "psr-4": { diff --git a/vendor/kanti/hub-updater/example.php b/vendor/kanti/hub-updater/example.php index 553fa97..a9fa297 100644 --- a/vendor/kanti/hub-updater/example.php +++ b/vendor/kanti/hub-updater/example.php @@ -2,4 +2,4 @@ require 'vendor/autoload.php'; $updater = new \Kanti\HubUpdater('kanti/test'); -$updater->update(); \ No newline at end of file +$updater->update(); diff --git a/vendor/kanti/hub-updater/example2.php b/vendor/kanti/hub-updater/example2.php index 33aa33c..24c6a69 100644 --- a/vendor/kanti/hub-updater/example2.php +++ b/vendor/kanti/hub-updater/example2.php @@ -1,26 +1,20 @@ 'kanti/test',//Repository to watch "branch" => 'master',//wich branch to watch "cache" => 'cache/',//were to put the caching stuff "save" => 'save/',//there to put the downloaded Version[default ./] "prerelease" => true,//accept prereleases? -]); -if($updater->able()) -{ - if(isset($_GET['update'])) - { +)); +if ($updater->able()) { + if (isset($_GET['update'])) { $updater->update(); echo '

updated :)

'; + } else { + echo 'Update Me'; //only update if they klick this link } - else - { - echo 'Update Me'; //only update if they klick this link - } -} -else -{ +} else { echo '

uptodate :)

'; -} \ No newline at end of file +}