* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
                  
                  
                       */
                  
                  
                      public function run()
                  
                  
                      {
                  
                  
                          $json              = File::get("database/data/data.json");
                  
                  
                          $products          = json_decode($json, true);
                  
                  
                  
                  
                  
                          unset($json);
                  
                  
                  
                  
                  
                          $temporaryFile     = tmpfile();
                  
                  
                          $temporaryFileName = stream_get_meta_data($temporaryFile);
                  
                  
                          $temporaryFilePath = $temporaryFileName["uri"];
                  
                  
                  
                  
                  
                          foreach ($products as $key => $product) {
                  
                  
                              $articleNumber = $product["article_number"];
                  
                  
                  
                  
                  
                              if (empty($articleNumber)) {
                  
                  
                                  continue;
                  
                  
                              }
                  
                  
                  
                  
                  
                              $imageURL = $product["image_url"];
                  
                  
                  
                  
                  
                              if ($imageURL) {
                  
                  
                                  fwrite($temporaryFile, $imageURL . "\n");
                  
                  
                              }
                  
                  
                  
                  
                  
                              $wholesalerName = $product["brand"];
                  
                  
                              $wholesaler     = App\Http\Models\Wholesaler::firstOrCreate(["name" => $wholesalerName]);
                  
                  
                  
                  
                  
                              $brandName      = (string)$product["collection"];
                  
                  
                              $brand          = App\Http\Models\Brand::firstOrCreate(["name" => $brandName]);
                  
                  
                  
                  
                  
                              / @var \App\Http\Models\Product $productInstance */
                  
                  
                  
                  
                  
                              $productInstance = App\Http\Models\Product::firstOrCreate([
                  
                  
                                  "wholesaler_id"    => $wholesaler->id,
                  
                  
                                  "article_number"   => $articleNumber
                  
                  
                              ], [
                  
                  
                                  "name"             => $product["name"],
                  
                  
                                  "description"      => $product["description"],
                  
                  
                                  "articles_per_box" => (int)$product["articles_per_box"],
                  
                  
                                  "burning_time"     => $product["burning_time"],
                  
                  
                                  "brand_id"         => $brand->id
                  
                  
                              ]);
                  
                  
                  
                  
                  
                              App\Http\Models\ProductAsset::firstOrCreate([
                  
                  
                                  "product_id" => $productInstance->id
                  
                  
                              ], [
                  
                  
                                  "type" => "image",
                  
                  
                                  "code" => basename($imageURL)
                  
                  
                              ]);
                  
                  
                  
                  
                  
                              $effectColors = $product["effect_colors"];
                  
                  
                  
                  
                  
                              if (gettype($effectColors) === "array") {
                  
                  
                                  foreach ($effectColors as $effectColor) {
                  
                  
                                      /** @var \App\Http\Models\EffectColor $productEffectColor */
                  
                  
                  
                  
                  
                                      $productEffectColor = App\Http\Models\EffectColor::firstOrCreate(["color" => $effectColor]);
                  
                  
                  
                  
                  
                                      $productInstance->effectColors()->attach($productEffectColor->id);
                  
                  
                                  }
                  
                  
                              }
                  
                  
                  
                  
                  
                              $effectTypes = $product["effect_types"];
                  
                  
                  
                  
                  
                              if (gettype($effectTypes) === "array") {
                  
                  
                                  foreach ($effectTypes as $effectType) {
                  
                  
                                      $productEffectType = App\Http\Models\EffectType::firstOrCreate(["type" => $effectType]);
                  
                  
                  
                  
                  
                                      $productInstance->effectTypes()->attach($productEffectType->id);
                  
                  
                                  }
                  
                  
                              }
                  
                  
                  
                  
                  
                              unset($products[$key]);
                  
                  
                          }
                  
                  
                  
                  
                  
                          echo "Downloading images..." . PHP_EOL;
                  
                  
                  
                  
                  
                          exec("aria2c —max-connection-per-server=16 —max-concurrent-downloads=100 —dir=public/uploads -i " . $temporaryFilePath);
                  
                  
                  
                  
                  
                          unlink($temporaryFilePath);
                  
                  
                      }
                  
                  
                  }
                  
                  
                
https://pastebin.com/
Обсуждают сегодня