Code snippets, tech tricks and other bits and bobs

Bugfix: JomSocial - Group Invitations don't send

Jomsocial 2.2 for Joomla!

Symptom:

When clicking Send Invitations, nothing happens

Cause:

AJAX request returns a Joomla! 500 Internal Server Error:

DB function failed with error number 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`creator`='67' WHERE `groupid`='97' AND `userid`='5417'' at line 1
SQL=UPDATE `jos_community_groups_invite` SET `groupid`='97', `userid`='5417' `creator`='67' WHERE `groupid`='97' AND `userid`='5417'

This is an obvious and very basic SQL syntax error - there is no comma after `userid`='5417'

JomSocial's AJAX error handling is... somewhat lacking - it simply fails to respond to most errors, including the dreaded 'Invalid Token' Joomla! error, meaning the user has no idea that an error has even occurred, and leaving them ill equipped to report problems.

Solution:

components\com_community\tables\groupinvite.php

89c89
<                     . $db->nameQuote( 'userid' ) . '=' . $db->Quote( $this->userid ) . ' '
---
>                     . $db->nameQuote( 'userid' ) . '=' . $db->Quote( $this->userid ) . ',' 

(Unix diff formatting)

Filed under  //   JomSocial   Joomla!   MySQL   PHP  

MySQL Error #1153 - Got a packet bigger than 'max_allowed_packet' bytes

Easily fixed

SSH into server

Edit MySQL config - in CentOS 5

# vi /etc/my.cnf

If:

there is no line with 'max_allowed_packet' add below the line ‘[mysqld]’:

max_allowed_packet=16M

Else:

increase the max_allowed_packet value

Then:

Save the file and restart mysql:

service mysqld restart

Done.

Filed under  //   MySQL  

Plesk 9.x - Access multiple databases with a single MySQL user

I have to set this up quite a lot for user sharing across multiple Joomla! sites. I will eventually get round to publishing the full instructions for that, but in the meantime I will start with this.

I got started on this with the aid of this post from Simple Steps:
Multiple mysql databases with single user
Fantastically useful as this is, it's slightly out of step with Plesk 9 (or at least the config for my host), so for my reference and yours, here are updated instructions.

For the purpose of this example, we shall pretend we are going to add the user 'ac_siteuser' to the database 'fh_testing'

Connect to MySQL

1. Using PuTTy, or your preferred terminal, connect to the server over SSH

2. Connect to MySQL as the admin user. Note in Plesk the MySQL user 'root' is replaced by 'admin'

# mysql -u admin -p

You will be prompted for the admin password.

Add existing user to different database with permissions

3. Select the database named 'mysql'

mysql> USE `mysql`;

If you need to check the permissions (all the 'Y's and 'N's in the INSERT statement below) against an existing user you can view the table like this:

mysql> SELECT * FROM `db`;

I found this to be necessary as the first time I attempted this, I receieved an error: ERROR 1136 (21S01): Column count doesn't match value count at row 1

If you already have a lot of users the results may be hard to read, so to just view one user:

mysql> SELECT * FROM `db` LIMIT 1;
+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+
| Host | Db   | User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Create_tmp_table_priv | Lock_tables_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Execute_priv |
+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+
| %    | test | user | Y           | Y           | Y           | Y           | Y           | Y         | N          | Y               | Y          | Y          | Y                     | Y                | Y                | Y              | Y                   | N                  | N            |
+------+------+------+-------------+-------------+-------------+-------------+-------------+-----------+------------+-----------------+------------+------------+-----------------------+------------------+------------------+----------------+---------------------+--------------------+--------------+

4. Insert the user into the `db` table with priveleges for the new database.
Having checked the privelege settings against those below and satisfying yourself they are good, you do the insertion:

mysql> INSERT INTO `db` VALUES('localhost','fh_testing','ac_siteuser','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N');

Note that to prevent access from any other server with this user, set the Host field to 'localhost' as in the above example. '%' means ANY mysql connections will be allowed from ANY host. 

And that is it.

Or is it? Your sites can now access another database with that user, but you have no access to that user in Plesk or through Plesk's PHPMyAdmin interface.

Add existing user and database to Plesk tables

4. Select the database named 'psa'

mysql> USE `psa`;

5. Check the account_id of the user being added to the database

mysql> SELECT * FROM `db_users`;
+----+------------------+------------+-------+
| id | login            | account_id | db_id |
+----+------------------+------------+-------+
|  1 | ac_siteuser      |          3 |     2 |
|  2 | ac_testinguser   |          4 |     3 |
|  3 | fh_testinguser   |          6 |     4 |
+----+------------------+------------+-------+

In this case, the id of user 'ac_site' is 3

6. Check the id of the database

mysql> select * from data_bases;
+----+----------------+-------+--------+--------------+-----------------+
| id | name           | type  | dom_id | db_server_id | default_user_id |
+----+----------------+-------+--------+--------------+-----------------+
|  2 | ac_livedb      | mysql |      1 |            1 |               1 |
|  3 | ac_testing     | mysql |      1 |            1 |               2 |
|  4 | fh_testing     | mysql |      1 |            1 |               3 | 
+----+----------------+-------+--------+--------------+-----------------+

In this case the id of the fh_testing database is 4

7. Insert user name, user account_id and database id into db_users table

INSERT INTO `db_users` VALUES ('','ac_site','3','4');

8. Finally exit and restart mysql

mysql> exit;

# service mysqld restart
 

Filed under  //   MySQL   PHPMyAdmin   Plesk 9