Is there any way I can export user details from joomla database such as name, password, email address, and import them into owncloud database via a cronjob?
1 Answer
There might be others, more elegant ways to do it but I did it pretty simple - I created a non-Joomla PHP file, which connects to Joomla's DB and dumps user table into a CSV file. I then scheduled to open this page with CRON.
Notice the headers for pushing the file as a download are commented out, so the file will be created and saved in the same directory with your PHP file.
<?php
// Database Connection
$host="localhost";
$uname="dbuser";
$pass="dbP@$$";
$database = "joomla_db";
$connection=mysql_connect($host,$uname,$pass);
echo mysql_error();
//or die("Database Connection Failed");
$selectdb=mysql_select_db($database) or
die("Database could not be selected");
$result=mysql_select_db($database)
or die("database cannot be selected <br>");
$output = "";
$table = "ab7cd_users"; // Enter Your Table Name
$sql = mysql_query("select id,name,username,email,block from $table");
$columns_total = mysql_num_fields($sql);
// Get The Field Name
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= $heading."\t";
}
$output = substr($output, 0, -1);
$output .="\r\n";
// Get Records from the table
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .=$row["$i"]."\t";
}
$output = substr($output, 0, -1);
$output .="\r\n";
}
// Download the file
$filename = "users.csv";
/*
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;
*/
file_put_contents ($filename , $output);
echo "Success";
exit;
?>
-
hi, thanks for the reply, that looks like a good script, i have one similar, what would you suggest to upload the data into owncloud db? and do you know whether importing joomla! passwords will work in owncloud? Aug 17, 2016 at 21:45
-
I am not familiar with owncloud but I doubt that it will work with Joomla password encryption algorithm. Aug 18, 2016 at 15:06
ROOT/cli
directory where you will find a couple of scripts that you base base your own script on.<?php $foo = 'bar'; ?>
and then try to push this value to the database.