parent
207c203366
commit
b8d3b4819a
@ -1,9 +0,0 @@ |
||||
<?php |
||||
// Store your Claroline database access settings here |
||||
//$sourceHost = 'localhost'; |
||||
//$sourcePort = '3306'; |
||||
//$sourceUser = 'claroline'; |
||||
//$sourcePass = 'claroline'; |
||||
//$sourceDB = 'claroline'; |
||||
//$sourceSingle = TRUE; //or FALSE. Find it in claroline/platform/conf/claro_main.conf.php as $GLOBALS['singleDbEnabled'] |
||||
//$sourcePref = 'cl_'; //tables prefix |
@ -1,99 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Functions used by migrate.php to migrate from Claroline to Chamilo |
||||
*/ |
||||
class Migrate { |
||||
public $db; |
||||
public $userIdChanges = array(); // Previous ID => New ID array |
||||
|
||||
public function __construct() { |
||||
require __DIR__.'/config.php'; |
||||
$this->db = new PDO( |
||||
"mysql:host=$sourceHost;dbname=$sourceDB", |
||||
$sourceUser, |
||||
$sourcePass |
||||
); |
||||
$this->dbName = $sourceDB; |
||||
$this->dbSingle = $sourceSingle; |
||||
$this->dbTablePrefix = $sourcePref; |
||||
} |
||||
/** |
||||
* Migrate users |
||||
* @return int Number of users migrated |
||||
*/ |
||||
public function migrateUsers() { |
||||
$count = 0; |
||||
// Claroline => Chamilo |
||||
$match = array( |
||||
'user_id' => 'id', |
||||
'nom' => 'lastname', |
||||
'prenom' => 'firstname', |
||||
'username' => 'username', |
||||
'password' => 'password', |
||||
'language' => 'language', |
||||
'authSource' => 'auth_source', //in Claroline: claroline. In Chamilo: platform |
||||
'email' => 'email', |
||||
'officialCode' => 'official_code', |
||||
'phoneNumber' => 'phone', |
||||
'pictureUri' => 'picture_uri', |
||||
'creatorId' => 'creator_id', |
||||
'isPlatformAdmin' => 'is_admin', //existence in admin table (see below) |
||||
'isCourseCreator' => 'status', //Claro: 1=teacher, 0=student. Chamilo: 1=teacher, 5=student |
||||
'lastLogin' => 'last_login', |
||||
); |
||||
|
||||
$sql = "SELECT * FROM ".$this->dbName.".".$this->dbTablePrefix."user ORDER BY user_id"; |
||||
$stmt = $this->db->prepare($sql); |
||||
$stmt->execute(); |
||||
$rows = $stmt->fetchAll(); |
||||
foreach ($rows as $row) { |
||||
//print_r($row); |
||||
$user = array(); |
||||
foreach ($match as $source => $dest) { |
||||
$user[$dest] = $row[$source]; |
||||
} |
||||
if ($row['user_id'] == 1) { |
||||
// skip first user to try and keep the same user IDs for all users |
||||
continue; |
||||
} |
||||
if ($row['isCourseCreator'] == 0) { |
||||
$user['status'] = 5; |
||||
} |
||||
if ($row['authSource'] == 'claroline') { |
||||
$user['auth_source'] = 'platform'; |
||||
} |
||||
$newUserId = UserManager::create_user( |
||||
$user['firstname'], |
||||
$user['lastname'], |
||||
$user['status'], |
||||
$user['email'], |
||||
$user['username'], |
||||
$user['password'], |
||||
$user['official_code'], |
||||
$user['language'], |
||||
$user['phone'], |
||||
$user['picture_uri'], |
||||
$user['auth_source'], |
||||
null, |
||||
null, |
||||
null, |
||||
null, |
||||
null, |
||||
null, |
||||
$user['is_admin'] |
||||
); |
||||
// Now we have created the user, but we'll try to give it the |
||||
// same ID as in the original database, or otherwise store the |
||||
// new ID in an array for later re-use |
||||
$sql = "SELECT username FROM user WHERE id = " . $user['id'] . " AND username != '".$user['username']."'"; |
||||
$res = Database::query($sql); |
||||
$num = Database::num_rows($res); |
||||
if ($num > 0) { |
||||
//The ID is already used by someone else |
||||
$this->userIdChanges[$user['id']] = $newUserId; |
||||
} |
||||
$count++; |
||||
} |
||||
return $count; |
||||
} |
||||
} |
@ -1,26 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* This script executes the migration from a Claroline 1.11.10 system to a |
||||
* Chamilo LMS 1.10.0 system. |
||||
* This should be launched on the command line to avoid maximum connection |
||||
* times defined by the browser or the web server. |
||||
* Configuration of the source should be set in the config.php file. |
||||
* Configuration of Chamilo is taken from the current folder (current |
||||
* already-installed Chamilo portal). |
||||
*/ |
||||
require_once __DIR__.'/config.php'; |
||||
if (!isset($sourceHost)) { |
||||
die ('Please define the source and other parameters in config.php'.PHP_EOL); |
||||
} |
||||
|
||||
require_once __DIR__.'/../../../../main/inc/global.inc.php'; |
||||
require_once __DIR__.'/migrate.class.php'; |
||||
|
||||
echo "Working" . PHP_EOL; |
||||
$migrate = new Migrate(); |
||||
|
||||
echo "Migrating users..." . PHP_EOL; |
||||
$count = $migrate->migrateUsers(); |
||||
echo $count . " users migrated." . PHP_EOL; |
||||
|
||||
echo "Done"; |
Loading…
Reference in new issue