From b5bdd22a07318007bd8a99b1ddade02c566c4a12 Mon Sep 17 00:00:00 2001 From: Marcin Morawski Date: Sat, 1 Feb 2020 12:25:08 +0100 Subject: [PATCH] =?UTF-8?q?#100=20-=20Init=20projektu=20-=20pobieranie=20p?= =?UTF-8?q?rzyk=C5=82adowych=20zdj=C4=99=C4=87=20restauracji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Po zaƂadowaniu restauracji korzystamy z faker to pobrania losowych zdjec dla restauracji. Pobrane zdjecia nastepnie wrzucamy na minio. Dzieki temu na naszej stronie glownej pojawia sie loga restauracji. Obecnie faker korzysta tylko z lorempixel, ktore nie dziala (https://github.com/fzaninotto/Faker/issues/1884) Korzystamy wiec tymczasowo z forka, ktory dodaje usluge https://picsum.photos/ --- Makefile | 3 +- .../tests/unit/fixtures/RestaurantFixture.php | 20 ++++++++++ composer.json | 7 +++- composer.lock | 38 +++++++++++-------- console/controllers/InitController.php | 38 +++++++++++++++++++ 5 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 console/controllers/InitController.php diff --git a/Makefile b/Makefile index 185fc27c..63224b6f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ setup: .env mkdir -p frontend/web/assets chmod 777 frontend/web/assets docker-compose up -d mongo - # in future move to wait_for script + # in future move to wait_for script, also for minio sleep 5 docker-compose up -d mongo-init-replica docker-compose up -d @@ -18,6 +18,7 @@ setup: .env docker-compose exec cli bash -c "cd frontend && yarn install --frozen-lock-file" docker-compose exec cli bash -c 'cd frontend && yarn build' docker-compose exec cli bash -c "./yii migrate/up --interactive 0" + docker-compose exec cli bash -c "./yii init/create-bucket" docker-compose exec cli bash -c "./yii fixture/load '*' --interactive 0 " docker-compose exec cli bash -c "cd provision/rocketchat/ && npm ci" docker-compose exec cli bash -c "cd provision/rocketchat/ && node incomingIntegration.js" diff --git a/common/tests/unit/fixtures/RestaurantFixture.php b/common/tests/unit/fixtures/RestaurantFixture.php index e0ada028..e6935e60 100644 --- a/common/tests/unit/fixtures/RestaurantFixture.php +++ b/common/tests/unit/fixtures/RestaurantFixture.php @@ -2,7 +2,10 @@ namespace common\tests\unit\fixtures; +use common\enums\BucketEnum; +use common\services\FileService; use common\services\FixtureStore; +use Faker\Factory; use frontend\models\Restaurants; use yii\test\ActiveFixture; @@ -16,4 +19,21 @@ public function beforeLoad(): void parent::beforeLoad(); FixtureStore::getInstance()->addFixture($this); } + + public function afterLoad(): void + { + $faker = Factory::create(); + /** @var Restaurants $restaurant */ + foreach (array_keys($this->data) as $alias) { + $restaurant = $this->getModel($alias); + $path = $faker->picsum(null, 400, 400, true); + + $key = basename($path); + $restaurant->img_url = $key; + /** @var FileService $fileService */ + $fileService = \Yii::$container->get(FileService::class); + $fileService->storeFile(BucketEnum::RESTAURANT . '/' . $key, $path); + $restaurant->save(false); + } + } } diff --git a/composer.json b/composer.json index c74d9a9c..a368f192 100755 --- a/composer.json +++ b/composer.json @@ -17,6 +17,10 @@ { "type": "git", "url": "https://github.com/morawskim/yii2-utils" + }, + { + "type": "git", + "url": "https://github.com/morawskim/Faker" } ], "require": { @@ -62,7 +66,8 @@ "phpcompatibility/php-compatibility": "^9.1", "phpstan/phpstan-deprecation-rules": "^0.11.2", "phpstan/phpstan-strict-rules": "^0.11.1", - "ergebnis/phpstan-rules": "^0.14.2" + "ergebnis/phpstan-rules": "^0.14.2", + "fzaninotto/faker": "dev-picsum as v1.8.0" }, "config": { "process-timeout": 1800, diff --git a/composer.lock b/composer.lock index 664a622d..7fb8c939 100755 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4535c9c18cb7e029406b8dd24adcce05", + "content-hash": "60b1b2849db38705f289f6cc4d0e0230", "packages": [ { "name": "2amigos/yii2-disqus-widget", @@ -3609,17 +3609,11 @@ }, { "name": "fzaninotto/faker", - "version": "v1.8.0", + "version": "dev-picsum", "source": { "type": "git", - "url": "https://github.com/fzaninotto/Faker.git", - "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/f72816b43e74063c8b10357394b6bba8cb1c10de", - "reference": "f72816b43e74063c8b10357394b6bba8cb1c10de", - "shasum": "" + "url": "https://github.com/morawskim/Faker", + "reference": "38d148979252bb4a50eda55cc6f658d75f3ce4b8" }, "require": { "php": "^5.3.3 || ^7.0" @@ -3627,12 +3621,12 @@ "require-dev": { "ext-intl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7", - "squizlabs/php_codesniffer": "^1.5" + "squizlabs/php_codesniffer": "^2.9.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -3640,7 +3634,11 @@ "Faker\\": "src/Faker/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "Faker\\Test\\": "test/Faker/" + } + }, "license": [ "MIT" ], @@ -3655,7 +3653,7 @@ "faker", "fixtures" ], - "time": "2018-07-12T10:23:15+00:00" + "time": "2020-01-31T19:10:10+00:00" }, { "name": "jakub-onderka/php-parallel-lint", @@ -7890,12 +7888,20 @@ "time": "2018-12-08T10:07:49+00:00" } ], - "aliases": [], + "aliases": [ + { + "alias": "v1.8.0", + "alias_normalized": "1.8.0.0", + "version": "dev-picsum", + "package": "fzaninotto/faker" + } + ], "minimum-stability": "stable", "stability-flags": { "kartik-v/yii2-widget-datepicker": 20, "kartik-v/yii2-widget-fileinput": 20, - "mmo/yii2-utils": 20 + "mmo/yii2-utils": 20, + "fzaninotto/faker": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/console/controllers/InitController.php b/console/controllers/InitController.php new file mode 100644 index 00000000..605aa90a --- /dev/null +++ b/console/controllers/InitController.php @@ -0,0 +1,38 @@ +get(S3Client::class); + $s3Client->createBucket(['Bucket' => $bucket]); + + $policyJson = <<putBucketPolicy([ + 'Bucket' => $bucket, + 'Policy' => $policyJson + ]); + } +}