Capsule::schema()->create('gamertags', function ($table) { $table->increments('id'); $table->string('gamertag', 255)->index()->unique(); $table->string('xuid', 255)->nullable()->index()->unique(); $table->text('error')->nullable(); $table->timestamps(); }); } // Setup our relationship models class Gamertag extends Model { protected $table = 'gamertags'; protected $hidden = []; protected $fillable = ['gamertag', 'xuid', 'error']; } if ($createSchema === true) { $dir = realpath(__DIR__ . '/../'); $file = "{$dir}/" . GAMERTAGS_CSV; try { $csv = new SplFileObject($file, 'r'); } catch (RuntimeException $e) { printf("Error opening .csv: %s\n", $e->getMessage()); exit; } while (!$csv->eof() && ($row = $csv->fgetcsv()) && $row[0] !== null) { print "Importing gamertag: {$row[0]}\n"; Gamertag::create(['gamertag' => $row[0]]); } $count = Gamertag::all()->count(); print "\nImported {$count} gamertags\n\n"; }
<?php date_default_timezone_set('Europe/London'); define('GAMERTAGS_CSV', 'gamertags.csv'); header('Content-Type: text/plain'); // get the composer autoloader include __DIR__ . '/vendor/autoload.php'; if (!file_exists(GAMERTAGS_CSV)) { touch(GAMERTAGS_CSV); include __DIR__ . '/generate_gamertags.php'; generate_gamertags(); } // get our config file include __DIR__ . '/config.php'; // load the helper files include __DIR__ . '/helpers/database.php'; include __DIR__ . '/helpers/xboxapi.php'; $count = Gamertag::whereNull('xuid')->count(); while ($count > 0) { $gamertags = Gamertag::whereNull('xuid')->take(500)->get(); foreach ($gamertags as $gamertag) { $gamertag = getXuid($gamertag); if ($gamertag !== false) { print $gamertag . PHP_EOL; $count--; } } $count = Gamertag::whereNull('xuid')->count(); }