From 1dcae965deb0626380bf0a072be643ea47fc9c49 Mon Sep 17 00:00:00 2001 From: Webysther Nunes Date: Sun, 10 Jun 2018 01:21:26 -0300 Subject: [PATCH] Fixed index.html render to use flysystem Signed-off-by: Webysther Nunes --- .gitignore | 1 + src/Command/Base.php | 2 +- src/Command/Clean.php | 2 +- src/Command/Create.php | 13 +++++++++---- src/Filesystem.php | 14 +++++++++++++- tests/Command/CreateTest.php | 2 +- tests/fixture/.env | 19 +++++++++++++++---- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index eaab12ee0..453c9ce2f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ coverage vendor legacy /.env +cs_fixer* diff --git a/src/Command/Base.php b/src/Command/Base.php index 17e044dc2..a032cbb18 100644 --- a/src/Command/Base.php +++ b/src/Command/Base.php @@ -125,7 +125,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) */ public function init(InputInterface $input, OutputInterface $output) { - if(isset($this->input) && isset($this->output)){ + if (isset($this->input) && isset($this->output)) { return $this; } diff --git a/src/Command/Clean.php b/src/Command/Clean.php index 309923895..315027d90 100644 --- a/src/Command/Clean.php +++ b/src/Command/Clean.php @@ -106,7 +106,7 @@ public function bootstrap():void */ protected function flushProviders():Clean { - if (!$this->filesystem->hasFile(self::MAIN)){ + if (!$this->filesystem->hasFile(self::MAIN)) { return $this; } diff --git a/src/Command/Create.php b/src/Command/Create.php index 6536b03fe..8c7628371 100644 --- a/src/Command/Create.php +++ b/src/Command/Create.php @@ -380,12 +380,17 @@ protected function generateHtml():Create $maintainerLicense = getenv('MAINTAINER_LICENSE'); $tz = getenv('TZ'); $synced = getenv('SLEEP'); - $exists = file_exists(getenv('PUBLIC_DIR').'/packages.json'); - $lastModified = filemtime(getenv('PUBLIC_DIR').'/packages.json'); + $file = $this->filesystem->getGzName('packages.json'); + $exists = $this->filesystem->hasFile($file); + + $lastModified = false; + if ($exists) { + $lastModified = $this->filesystem->getTimestamp($file); + } $lastSync = null; - if ($exists && false !== $lastModified){ - $moment = new \Moment\Moment('now', $tz); + if ($exists && false !== $lastModified) { + $moment = new \Moment\Moment($lastModified, $tz); $momentJs = new \Moment\CustomFormats\MomentJs(); $format = $momentJs->format("dddd, MMMM Do YYYY HH:mm:ss ZZ"); $lastSync = $moment->format($format); diff --git a/src/Filesystem.php b/src/Filesystem.php index fad5e89f3..544c92e47 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -190,7 +190,7 @@ protected function symlink(string $file):Filesystem return $this; } - if (strpos($link, 'vfs://') !== false){ + if (strpos($link, 'vfs://') !== false) { return $this; } @@ -281,6 +281,18 @@ public function delete(string $fileOrDirectory):Filesystem return $this; } + /** + * Return the timestamp of modification + * + * @param string $path + * + * @return int + */ + public function getTimestamp(string $path):int + { + return $this->filesystem->getTimestamp($path); + } + /** * Calculates SHA256. * diff --git a/tests/Command/CreateTest.php b/tests/Command/CreateTest.php index 55b863b91..2d7d90ae6 100644 --- a/tests/Command/CreateTest.php +++ b/tests/Command/CreateTest.php @@ -106,7 +106,7 @@ protected function getPackagesJson(stdClass $json, string $name = 'archived'):st $newJson->{'provider-includes'} = new stdClass(); foreach ($json->{'provider-includes'} as $item => $value) { - if (strpos((string) $item, $name.'$') === false){ + if (strpos((string) $item, $name.'$') === false) { continue; } diff --git a/tests/fixture/.env b/tests/fixture/.env index bc049dc2b..eb25b0860 100644 --- a/tests/fixture/.env +++ b/tests/fixture/.env @@ -4,17 +4,28 @@ APP_NAME='Packagist Mirror' # Application version APP_VERSION='1.0.0' +# Language +APP_COUNTRY_NAME='Brazil' +APP_COUNTRY_CODE='br' + # Folder used to save the files PUBLIC_DIR=public +# Maintainer information +MAINTAINER_MIRROR='Webysther' +MAINTAINER_PROFILE='https://github.com/Webysther' +MAINTAINER_REPO='https://github.com/Webysther/packagist-mirror' +MAINTAINER_LICENSE='MIT License' + # Main mirror used to get providers MAIN_MIRROR=https://packagist.org # Data mirror used to download repositories data -DATA_MIRROR=https://packagist.jp,https://packagist.com.br,https://packagist.phpcomposer.com - -# URI of your mirror -URL=packagist.com.br +# Japan - https://packagist.jp +# Indonesia - https://packagist.phpindonesia.id +# Brazil - https://packagist.com.br +# China - https://packagist.phpcomposer.com (not fully compatible - too much broken packages) +DATA_MIRROR=https://packagist.jp,https://packagist.com.br,https://packagist.phpindonesia.id # Max connections by mirror MAX_CONNECTIONS=25