Skip to content

Instantly share code, notes, and snippets.

@robetus
Forked from klaude/generateWhmcsUuids.php
Last active September 7, 2020 07:01
Show Gist options
  • Save robetus/51e3287faf556002ac09209477842939 to your computer and use it in GitHub Desktop.
Save robetus/51e3287faf556002ac09209477842939 to your computer and use it in GitHub Desktop.

Revisions

  1. robetus revised this gist Nov 21, 2017. No changes.
  2. robetus revised this gist Nov 21, 2017. 1 changed file with 3 additions and 6 deletions.
    9 changes: 3 additions & 6 deletions generateWhmcsUuids.php
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,20 @@
    <?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
    * The WHMCS 7.4.1 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 Ramsey\Uuid\Uuid;
    use WHMCS\User\Admin;
    use WHMCS\User\Client;

    require_once __DIR__ . '/init.php';
    require_once dirname(__FILE__)."/../init.php";

    // Look for client and admin users with empty uuids.
    $clients = Client::where('uuid', '')->get();
    @@ -28,14 +27,12 @@
    $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);
    });
  3. @klaude klaude revised this gist Jan 9, 2016. 1 changed file with 6 additions and 10 deletions.
    16 changes: 6 additions & 10 deletions generateWhmcsUuids.php
    Original file line number Diff line number Diff line change
    @@ -26,20 +26,16 @@

    // Generate uuids for clients.
    $clients->each(function (Client $client) {
    if ($client->uuid == '') {
    $client->uuid = Uuid::uuid4();
    $client->save();
    $client->uuid = Uuid::uuid4();
    $client->save();

    var_dump('Generated uuid ' . $client->uuid . ' for client id ' . $client->id);
    }
    var_dump('Generated uuid ' . $client->uuid . ' for client id ' . $client->id);
    });

    // Generate uuids for admins.
    $admins->each(function (Admin $admin) {
    if ($admin->uuid == '') {
    $admin->uuid = Uuid::uuid4();
    $admin->save();
    $admin->uuid = Uuid::uuid4();
    $admin->save();

    var_dump('Generated uuid ' . $admin->uuid . ' for admin id ' . $admin->id);
    }
    var_dump('Generated uuid ' . $admin->uuid . ' for admin id ' . $admin->id);
    });
  4. @klaude klaude created this gist Jan 9, 2016.
    45 changes: 45 additions & 0 deletions generateWhmcsUuids.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    <?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) {
    if ($client->uuid == '') {
    $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) {
    if ($admin->uuid == '') {
    $admin->uuid = Uuid::uuid4();
    $admin->save();

    var_dump('Generated uuid ' . $admin->uuid . ' for admin id ' . $admin->id);
    }
    });