Skip to content

Instantly share code, notes, and snippets.

@klaude
Last active February 8, 2019 14:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save klaude/7f93bc7024705f4dab9a to your computer and use it in GitHub Desktop.
Save klaude/7f93bc7024705f4dab9a to your computer and use it in GitHub Desktop.
<?php
/**
* Generate uuids for clients and admins that don't have uuids set.
*
* The WHMCS 6.2.0 update process automatically inserts uuids, but if your
* installation bypasses WHMCS update routines then this will generate uuids for
* the client and admin users that don't have one yet.
*
* Warning! Please back up at least your tblclient and tbladmin tables before
* running this!
*/
use Rhumsaa\Uuid\Uuid;
use WHMCS\User\Admin;
use WHMCS\User\Client;
require_once __DIR__ . '/init.php';
// Look for client and admin users with empty uuids.
$clients = Client::where('uuid', '')->get();
$admins = Admin::where('uuid', '')->get();
var_dump('Found ' . $clients->count() . ' client(s) with no uuid.');
var_dump('Found ' . $admins->count() . ' admin(s) with no uuid.');
// Generate uuids for clients.
$clients->each(function (Client $client) {
$client->uuid = Uuid::uuid4();
$client->save();
var_dump('Generated uuid ' . $client->uuid . ' for client id ' . $client->id);
});
// Generate uuids for admins.
$admins->each(function (Admin $admin) {
$admin->uuid = Uuid::uuid4();
$admin->save();
var_dump('Generated uuid ' . $admin->uuid . ' for admin id ' . $admin->id);
});
@mukoshy
Copy link

mukoshy commented Jul 9, 2017

Line 14 should be:
use Ramsey\Uuid\Uuid;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment