Skip to content

Instantly share code, notes, and snippets.

@renekreijveld
Last active March 15, 2023 09:17
Show Gist options
  • Save renekreijveld/bcac9925e2f2905dd3716d9451c55c6c to your computer and use it in GitHub Desktop.
Save renekreijveld/bcac9925e2f2905dd3716d9451c55c6c to your computer and use it in GitHub Desktop.
Simple Joomla 4 CLI script
<?php
// listusers.php - simple cli script to dump users on CLI
// Written by René Kreijveld
// Version history:
// 1.0, 2023-03-09: Initial version
use Joomla\CMS\Factory;
const _JEXEC = 1;
define('JDEBUG', false);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
// Get the framework
require_once JPATH_BASE . '/includes/framework.php';
// Function to output a message
function out($message)
{
echo $message . "\n";
}
// Setup database
$db = Factory::getContainer()->get('DatabaseDriver');
// Get data from users table
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__users'));
$db->setQuery($query);
$users = $db->loadObjectList();
foreach ($users as $user)
{
out("id: $user->id, username: $user->username, name: $user->name, email: $user->email");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment