Would you like to create a module to display some statistics from another Joomla site, hosted in the same server? That is perfectly possible and relatively simple, by using the Joomla database connection to an external database.
A proof of concept module, Databases, can be downloaded from https://extensions.talikka.com/downloads/databases/mod_databases-1.0.0.zip
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 4236
This example displays three user custom fields, fielda, fieldb and fieldc. It uses the PHP function array_column() and therefore it does not need a foreach loop.
use Joomla\CMS\Factory;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
$customFields = FieldsHelper::getFields('com_users.user', Factory::getUser(), true);
$values = array_column($customFields, 'value', 'name');
// echo 'values = ' . print_r($values, true);
echo 'fielda = ' . $values['fielda'] . ' fieldb = ' . $values['fieldb'] . ' fieldc = ' . $values['fieldc'];
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 23484
You may have seen the error message "JUser: :_load: Unable to load user" and wondered if it would be possible to easily update all articles that display an error after the author or editor of the article has been deleted from the system on purpose or by accident. The alternative, manual editing and updating each article, even though easy, can be boring and subject to mistakes, and it can take longer than expected.
If you have the numeric id of another user, who is going to replace the author or modifier of the article, the updates can be done through a SQL query.
Run the attached SQL statement first in a test environment, for example a cloned copy of the website, hosted on your workstation, using a bundle like Wampserver from https://wampserver.com/en. Make a backup of the content table before the test, in case something goes wrong.
The attached SQL script replaces the author of all articles created by the deleted original user, whose name and other details cannot be found from the users table in the database. The first SQL statement sets the user id of the new author. After that a CREATE statement creates a temporary table so that the article ids can be stored by the subsequent query, which finds all the articles where the author has been deleted and adds the article id to a temporary table.
The same pattern can be used to update the column 'modified_by'. Replace 'ep28r' with your own table prefix.
SET @author = 181;
DROP TEMPORARY TABLE IF EXISTS deleted_users;
CREATE TEMPORARY TABLE deleted_users (
`id` int(10) unsigned NOT NULL, PRIMARY KEY (`id`)
)
SELECT c.id FROM ep28r_content c
LEFT JOIN ep28r_users u ON c.created_by = u.id
WHERE u.id IS NULL;
UPDATE ep28r_content c SET c.created_by = @author
WHERE c.id IN(SELECT d.id FROM deleted_users d);
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 41817
If listing users with custom fields is a one-off requirement or only super users need to do that task from time to time, registered users and the contents of their custom fields can be listed by a custom query using phpMyAdmin or a similar MySQL client.
The following example creates temporary tables before generating the list. The query assumes that there are three custom fields, field4, field5 and field6, where the field ids are 4, 5 and 6. Replace 'epr28r' with your own table prefix.
CREATE TEMPORARY TABLE IF NOT EXISTS `ep28r_registered`
SELECT u.id, u.name, u.email FROM ep28r_users u
INNER JOIN ep28r_user_usergroup_map m ON u.id = m.user_id
WHERE m.group_id = 2 AND u.block = 0;
CREATE TEMPORARY TABLE IF NOT EXISTS `ep28r_work4`
SELECT u.id, v.value AS field4 FROM ep28r_registered r
LEFT JOIN ep28r_fields_values v ON r.id = v.item_id
INNER JOIN ep28r_fields f ON f.id = v.field_id
WHERE f.id = 4;
CREATE TEMPORARY TABLE IF NOT EXISTS `ep28r_work5`
SELECT u.id, v.value AS field5 FROM ep28r_registered r
LEFT JOIN ep28r_fields_values v ON r.id = v.item_id
INNER JOIN ep28r_fields f ON f.id = v.field_id
WHERE f.id = 5;
CREATE TEMPORARY TABLE IF NOT EXISTS `ep28r_work6`
SELECT u.id, v.value AS field6 FROM ep28r_registered r
LEFT JOIN ep28r_fields_values v ON r.id = v.item_id
INNER JOIN ep28r_fields f ON f.id = v.field_id
WHERE f.id = 6;
SELECT r.id, r.name, r.email, w4.field4, w5.field5, w6.field6 FROM `ep28r_registered` r
INNER JOIN `ep28r_work4` w4 ON r.id = w4.id
INNER JOIN `ep28r_work5` w5 ON r.id = w5.id
INNER JOIN `ep28r_work6` w6 ON r.id = w6.id;
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 5295
Sometimes websites produce warnings or error messages without giving any clues what caused the issue. Surely this has happened to everyone and it is annoying, especially if it happens at a website you are supposed to maintain.
Recently someone reported that they are unable to update articles because every time they try they get the message "Warning, Registration failed. Please try again." Clearly this message does not belong anywhere near the editing process where articles are updated or created. Something must have gone wrong in a third party extension or a home grown plugin.
If you have a similar situation where a seemingly unrelated error or a warning is reported in the browser, search for the text string from the website or clone or simply download the filesystem of the site and search on your workstation. A utility like grep or Windows grep are the easiest to use.
The text of the message is most likely to be found in one of the language files. This of course assumes that the extension that produced the message follows Joomla best practice of keeping the message texts in separate files, consisting of language constants and language strings.
Third party extensions add their own language files into the languages folder either at the front end or the back end of the site, or both. Extensions can also install their language files in a subfolder in the same folder where the extension itself is installed. Therefore a text search utility is the best approach to find any obscure messages where the origin can be anywhere in the system.
Once you find a match in a language file, copy the language constant from the start of the line and then search for that constant from the website filesystem or its copy exactly the same way, using a utility like grep or Windows grep. This way you can identify the file or all the files where the language constant has been used and you will be able to identify the extention.
If the message is not defined in one of the language files, it would have had to be hard coded in a third party extension, for example a plugin, which you may then be able to unpublish.
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 10420