12) { // $is_zip_file_exist = is_in_array(str_replace(" ","_",$data[2]), $listzipfile); $is_zip_file_exist = is_in_array("backup-".$data[0]."-", $listzipfile); if($is_zip_file_exist != false) { if(!array_key_exists($data[0],$all_course)) $all_course[$data[0]] = array($is_zip_file_exist, $data[1], $data[2], $data[3], $data[4], array(array($data[5], $data[6], $data[7], $data[8], $data[9], $data[10], $data[11], $data[12])) ); else $all_course[$data[0]][5][] = array($data[5], $data[6], $data[7], $data[8], $data[9], $data[10], $data[11], $data[12]); } else { write_log_err("zip introuvable : ".$data[2]); $list_cours_non_migre[] = $data[0]." : ".$data[1]." - ".$data[2]; } } else { write_log_err("données manquantes : ".$data[0]); } } fclose($handle); } write_log_ok("fin lecture du fichier csv. ".count($all_course)." cours à migrer"); write_log_ok("recuperation de tous les utilisateurs de la plateforme"); $token = ''; //token web service lille 1 $domainname = 'http://moodle.univ.fr'; /// FUNCTION NAME $functionname = 'local_wslille1_get_all_users'; header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; $post = xmlrpc_encode_request($functionname, array()); $all_users = xmlrpc_decode($curl->post($serverurl, $post)); write_log_ok("fin de la recuperation. ".count($all_users)." utilisateurs présents"); //All_course_allready_created //core_course_get_courses $token = ''; //token gestion_cours $domainname = 'http://moodle.univ.fr'; /// FUNCTION NAME $functionname = 'core_course_get_courses'; header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; $post = xmlrpc_encode_request($functionname, array()); $all_course_allready_created = xmlrpc_decode($curl->post($serverurl, $post)); write_log_ok(count($all_course_allready_created)." cours déjà présents dans la plateforme"); write_log_ok("-------"); write_log_ok("début de la migration"); foreach ($all_course as $key => $value) { write_log_ok("
traitement du cours ".$value[2]." - ".date('d m Y H:i')); $info_cours = is_in_array($value[2],$all_course_allready_created); $courseid = 0; if(is_array($info_cours)) { //si le cours existe déjà $courseid = $info_cours['id']; write_log_ok("Cours déjà existant id : ".$courseid); } else { //gestion de la categorie $idcat = 134; //categorie par defaut /* $token = ''; //token web service lille 1 $domainname = 'moodle.univ.fr'; /// FUNCTION NAME $functionname = 'local_wslille1_get_cat_by_id'; header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; write_log_ok("recherche cat id : ".$value[3]); $post = xmlrpc_encode_request($functionname, array($value[3])); $resp = xmlrpc_decode($curl->post($serverurl, $post)); if (array_key_exists('id', $resp)) { //on a trouve la categorie, on peut continuer write_log_ok("categorie trouve : ".$resp['id']." - ".$resp['name']); $idcat = $resp['id']; } else { //erreur lors de la recuperation de la categorie write_log_err("Erreur lors de la recuperation de la categorie : ".serialize($resp)); } */ //creation du cours write_log_ok("création du nouveau cours dans la categorie : ".$idcat); $param = array(array(array("fullname" => utf8_decode ($value[1]), 'shortname' => utf8_decode ($value[2]), 'categoryid' => intval($idcat)))); $info_cours = gestion_cours('core_course_create_courses', $param); //Array ( [faultCode] => 0 [faultString] => Ce nom abrégé est déjà utilisé pour un autre cours ) //Array ( [0] => Array ( [id] => 3 [shortname] => TICEC2I-2 ) ) if (array_key_exists('id', $info_cours[0])) { $courseid = $info_cours[0]['id']; write_log_ok("création ok id : ".$courseid); } else { write_log_err("Erreur lors de la creation du nouveau cours : ".serialize($info_cours)); } } if($courseid != 0) { //on a le course id !!!! $mapping_courses[$key] = $courseid; // on peut restaurer le cours $param = array($value[0],$courseid); write_log_ok("retauration du cours ".$courseid); $ret = restore_course($param); write_log_ok("fin restauration ".serialize($ret)); //traitement des enseignants write_log_ok("traitement des enseignants du cours ".$courseid); foreach($value[5] as $ens) { //MODIF ETUDIANT //etudiant $pos = stripos($ens[5],"etudiant.univ.fr"); if ($pos !== false) { write_log_ok($ens[1]." est un etudiant. son adresse mail est :".$ens[5]); } else { write_log_ok("traitement username : ".$ens[1]); //username $info_user = is_in_array($ens[1],$all_users); if(!is_array($info_user)) $info_user = is_in_array($ens[1]."@univ.fr",$all_users); $userid = 0; if(is_array($info_user)) { // le user est deja present $userid = $info_user['id']; } else { // creation du nouveau user write_log_ok("creation du user ".$ens[1]); if($ens[6] == "cas") $param = array(array(array("username" => $ens[1]."@univ.fr", 'password' => $ens[2], 'firstname' => utf8_decode ($ens[3]), 'lastname' => utf8_decode ($ens[4]), 'email' => $ens[5],'auth' => $ens[6]))); else $param = array(array(array("username" => $ens[1], 'password' => $ens[2], 'firstname' => utf8_decode ($ens[3]), 'lastname' => utf8_decode ($ens[4]), 'email' => $ens[5],'auth' => $ens[6]))); $new_user = gestion_cours('core_user_create_users', $param); if (array_key_exists('id', $new_user[0])) { $userid = $new_user[0]['id']; $all_users[] = $new_user[0]; write_log_ok("création ok new user : ".$userid); } else { write_log_err("Erreur lors de la creation du nouveau user : ".serialize($new_user)); } } if($userid != 0) { //on enrole dans le cours write_log_ok("ajout au cours"); if($ens[7] == "3") $param = array(array(array("roleid" => 3, 'userid' => $userid, 'courseid' => $courseid))); else $param = array(array(array("roleid" => 9, 'userid' => $userid, 'courseid' => $courseid))); $enrol = gestion_cours('enrol_manual_enrol_users', $param); write_log_ok("fin enrolement..."); } else { write_log_err("impossible de récupérer le user id pour ".$ens[1]); } } } } else { write_log_err("impossible de récupérer le course id "); } } write_log_ok("Fin migration : ".date('d m Y H:i')); echo "
";print_r($mapping_courses);echo "
"; $Fnm = "mapping_courses-".str_replace(" ","_",date('d m Y H i')).".csv"; $inF = fopen($Fnm,"w"); //$results = print_r($mapping_courses, true); // $results contient l'affichage de print_r foreach($mapping_courses as $key => $value) { //echo $value[0].","; //$healthy[] = ", ".$value[0].", "; //$yummy[] = ", ".$value[1].", "; fputs($inF,"\"".$key."\";\"".$value."\"\n"); } fclose($inF); echo "
";print_r($list_cours_non_migre);echo "
"; $Fnm = "cours_non_migre-".str_replace(" ","_",date('d m Y H i')).".csv"; $inF = fopen($Fnm,"w"); //$results = print_r($mapping_courses, true); // $results contient l'affichage de print_r foreach($list_cours_non_migre as $key => $value) { //echo $value[0].","; //$healthy[] = ", ".$value[0].", "; //$yummy[] = ", ".$value[1].", "; fputs($inF,"\"".$key."\";\"".$value."\"\n"); } fclose($inF); function restore_course($param) { $token = ''; //token web service lille 1 $domainname = 'http://moodle.univ.fr'; /// FUNCTION NAME $functionname = 'local_wslille1_restore_course'; //header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; $post = xmlrpc_encode_request($functionname, $param); $resp = xmlrpc_decode($curl->post($serverurl, $post)); return $resp; } function gestion_cours($functionname, $param) { $token = ''; //token gestion_cours $domainname = 'http://moodle.univ.fr'; /// FUNCTION NAME //$functionname = 'core_course_create_courses'; //header('Content-Type: text/plain'); $serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl; $post = xmlrpc_encode_request($functionname, $param); $resp = xmlrpc_decode($curl->post($serverurl, $post)); return $resp; } function is_in_array($val, $arr) { if($val == ""){ trigger_error("in_object expects parameter 1 must not empty", E_USER_WARNING); return false; } foreach($arr as $value) { if(is_array($value)) { $array = array_values($value); if(in_array($val, $array, true) == 1) return $value; } else { $pos = stripos(strtolower($value),strtolower($val)); if ($pos !== false) { //echo "FOUND"; return $value; } //else { echo "NOT FOUND";} //if(stripos(strtolower($value),strtolower($val))) return $value; } } return false; } function write_log_ok($msg){ echo " - ".$msg."
"; flush(); ob_flush(); usleep(1000); } function write_log_err($msg){ echo " - ".$msg."
"; flush(); ob_flush(); usleep(1000); } ?>