Skip to content

Instantly share code, notes, and snippets.

@RickR2H
Forked from renekreijveld/listusers.php
Created March 15, 2023 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickR2H/135fbe2547cf60d17c6da8aa3c04353c to your computer and use it in GitHub Desktop.
Save RickR2H/135fbe2547cf60d17c6da8aa3c04353c 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