<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class AutoUploadColorFile extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //490-887
        $startId = 490;
        $start = 1575;
        $end = 2005;
        $path = public_path('uploads/colors/490-887/');
        $newPath = public_path('uploads/colors/490-887-edited/');
        $missingItems = "";

        $checkMissing = false;
        for ($i = $start; $i <= $end; $i++) {
            if (file_exists($path . "IMG_" . $i . ".PNG")) {
                print "[" . $startId . "] Found: " . "IMG_" . $i . ".PNG\r\n";
                copy($path . "IMG_" . $i . ".PNG", $newPath . $startId . "_IMG_" . $i . ".PNG");
                $startId++;
            } else {
                $missingItems .= "Error: File not found [" . $startId . "] => " . "IMG_" . $i . ".PNG\r\n";
                $checkMissing = true;
            }
        }

        //print "=========================================================\r\n" . $missingItems . "\r\n";

        if (!$checkMissing) {
            print "Start importing...\r\n";
        }
    }
}
