Thursday, October 24, 2019

Drupal 7 / Ubercart 7 - How to Restore the Anonymous User

Drupal core 7.67 / Ubercart 7.x-3.13 


Following years of frustratingly hard-to-reach, disinterested and/or incompetent and needlessly expensive Drupal developers we have set up an affordable commercial service for Small and Medium sized Enterprise (SME) decision-makers who rely on Drupal to support their business, like us.  So, if you need help with this problem, or any other form of Drupal Wizardry, feel free to contact us via our new division, Drupal Wizard, which provides support for all versions of Drupal.  

We offer the following services to serve the unique and evolving needs of your business:
  • 24/7 Emergency Support
  • Low-Cost Annual Support Packages
  • Drupal Module Integration and Development
  • Linux and Drupal Scheduled Systems Maintenance
Visit www.drupalwizard.com for more information.


How to Restore the Anonymous User


After removing what I thought was an erroneous insert in my users table, anonymous visitors to the website became unable to add products to their shopping cart if they had not already logged in.

Turns out the "anonymous" user entry in the users table looks like this:

> select * from users where uid=0;
+-----+------+------+------+-------+-----------+------------------+---------+--------+-------+--------+----------+----------+---------+------+------+------+
| uid | name | pass | mail | theme | signature | signature_format | created | access | login | status | timezone | language | picture | init | data | uuid |
+-----+------+------+------+-------+-----------+------------------+---------+--------+-------+--------+----------+----------+---------+------+------+------+
|   0 |      |      |      |       |           | NULL             |       0 |      0 |     0 |      0 | NULL     | en       |       0 |      | NULL |      |
+-----+------+------+------+-------+-----------+------------------+---------+--------+-------+--------+----------+----------+---------+------+------+------+

This is an awfully stupid way to designate an anonymous user in a database, because it really looks like a bad insert.

Anyways, if the anonymous user has been removed from the users table, your shoppers will see this error message after trying to add a product to the shopping cart:

There are no products in your shopping cart

To recover from this error, simply execute the following code at the CLI:

Log into MySQL:

# mysql -p

Connect to correct Drupal 7 database:

> use <database>;
> INSERT INTO users (uid, language, uuid) VALUES (0, "en", "");

After that, unauthenticated shoppers will be able to place products in the cart again.


No comments:

Post a Comment