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.aviatechno.net/. 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: 42328
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: 5814
It was time to take inventory of third party extensions and remove those that were not needed on a test site. Found only a couple of extensions and the Akeeba Release System (ARS) was one of them. This was going to be easy! Clicked the Uninstall button, only to see a nasty PHP fatal error displayed on a blank page about a missing file in a library. The site was rendered unusable. How come?
A closer look at the error identified that the Admin Tools extension was trying to load the fof30 library. Interesting, one extension by Akeeba disabled the other! The manifest file of ARS revealed that the uninstallation of the package is done by the script /administrator/manifests/packages/ars/script.ars.php.
The uninstall() function has two lines of comments about the uninstallation of the FOF library possibly failing if other extensions are dependent on it. Instead, the relatively old version of the uninstallation script of the unsupported extension missed the existence of the latest version of Admin Tools completely and zapped the library.
Solution: comment out the following line from the uninstall() function before starting to uninstall.
// $this->uninstallFOF($parent);
The moral of this true story:
- run the uninstall script once on a test site before installing a new extension on a live site
- avoid unsupported extensions unless you are prepared to troubleshoot
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 7399
If you have issues with SMTP emails, you can get Joomla to record all the detailed messages exchanged with your SMTP server. Inspecting the low level transaction log often allows you to see what is going on between the two servers and resolve any connectivity issues with your IT or hosting provider. This custom method is quite simple to set up if you have FTP or SSH access to the Joomla folder in your web server.
This SMTP debug option involves a temporary modification to a file in the JMail class, an extension of the PHPMailer library. Warning: core modifications are not recommended and you should revert the file back to the original version as soon as possible.
First make a backup copy of the file your are going to modify, libraries/joomla/mail/mail.php. Then edit this file, mail.php, and add the following lines to the beginning of the function useSMTP(), after line 634:
// 20170221 SMTP log
$this->SMTPDebug = 4; // maximum level data output
// $this->Debugoutput = 'error_log'; // use the PHP error log, as configured in php.ini
$this->Debugoutput = function($message, $level) { $file = 'mail_log.txt'; $config = JFactory::getConfig(); $logfile = $config['log_path'] . '/' . $file;
$log = fopen($logfile, 'a'); fwrite ($log, $message); fclose($log);};
// 20170221 end
After you click the button Send Test Mail in the Global Configuration or any other mail function, you can download the file 'mail_log.txt' from the Joomla log folder, usually administrator/logs.
Remember to restore the original version of the file mail.php before the log file grows too much.
And here is the way you can log the mail debug entries by using the standard debug option. Configure the plugin 'System - Debug' with the following key settings:
- Allowed Groups: Super Users
- Log Priorities: All
- Log Categories: mail
- Log Almost Everything
Turn on the debug option in Global Configuration and you can find all the details of the SMTP connection requests and responses with error codes from the file administrator/logs/everything.php.
- Details
- Written by: Toivo Talikka
- Category: Joomla
- Hits: 23241