sync only

This commit is contained in:
afornerot 2019-12-13 15:13:46 +01:00
parent 8e9ff10223
commit 5e9d7765ce
3 changed files with 209 additions and 47 deletions

View File

@ -186,6 +186,7 @@ class OnlyCommand extends Command
// Controler les utilisateurs ninegate
$this->writeln('');
$this->writeln('== CONTROLE USER NINEGATE============================');
/*
$users=$this->em->getRepository("CadolesCoreBundle:User")->findAll();
foreach($users as $user) {
$response = \Unirest\Request::get($this->only_url.'/people/'.$user->getUsername(),$headers);
@ -193,6 +194,7 @@ class OnlyCommand extends Command
$this->writelnred("ERREUR ".$user->getUsername()." existe dans Ninegate mais pas dans OnlyOffice");
}
}
*/
// On recherche la page template de group
$pagetemplate=$this->em->getRepository("CadolesPortalBundle:Page")->findOneBy(["parentfor"=>"group"]);
@ -208,12 +210,16 @@ class OnlyCommand extends Command
if($this->koresponse($response)) return 0;
$projects=$response->body->response;
while(isset($response->body->nextIndex)) {
$response = \Unirest\Request::get($this->only_url.'/people?startIndex='.$response->body->nextIndex,$headers);
$response = \Unirest\Request::get($this->only_url.'/project?status=0&startIndex='.$response->body->nextIndex,$headers);
if($this->koresponse($response)) return 0;
$projects=array_merge($projects,$response->body->response);
}
foreach($projects as $onlygroup) {
// On ne scanne que les groupe ouvert
if($onlygroup->status!=0)
continue;
// Le groupe existe-t-il dans ninegate
$group=$this->em->getRepository("CadolesCoreBundle:Group")->findBy(["idonlyoffice"=>$onlygroup->id]);
if(!$group) {
@ -253,7 +259,6 @@ class OnlyCommand extends Command
$this->writelnred("ERREUR Propriétaire du Groupe n'existe pas. Group = ".$namegroup. " - User = ".$onlygroup->responsible->displayName);
}
else {
// Création du groupe
$user=$this->em->getRepository("CadolesCoreBundle:User")->findOneBy(["username"=>$onlyusers[$onlygroup->responsible->id]]);
$this->writeln("Création du groupe Ninegate = ".$namegroup);
@ -272,6 +277,7 @@ class OnlyCommand extends Command
$group->setOwner($user);
$group->setPagetemplate($pagetemplate);
$group->setIdonlyoffice($onlygroup->id);
$group->setNosynconly(true);
$this->em->persist($group);
$this->em->flush();
@ -281,12 +287,15 @@ class OnlyCommand extends Command
// On controle que le groupe a bien page / calendrier / blog
$this->ctrlFgcanshare($group,$user,$pagetemplate);
}
// Rattachement des membres au groupe
$group=$this->em->getRepository("CadolesCoreBundle:Group")->findOneBy(["idonlyoffice"=>$onlygroup->id]);
$members = \Unirest\Request::get($this->only_url.'/project/'.$onlygroup->id.'/team',$headers);
if($this->koresponse($members)) return 0;
foreach($members->body->response as $member) {
// Si non propriétaire du groupe
if($member->userName!=$onlyusers[$onlygroup->responsible->id]) {
@ -311,10 +320,16 @@ class OnlyCommand extends Command
}
}
}
if(!$simulate) {
$this->em->persist($group);
$this->em->flush();
}
}
}
}
}
// Injection des groupes ninegate non existant dans only
$this->writeln('');
@ -346,13 +361,32 @@ class OnlyCommand extends Command
// Si le projet existe
if(!$this->koresponse($respgroup)) {
// On regarde s'il y a des changement
if($respgroup->body->response->responsible->userName!=$groupowner->getUsername()||$respgroup->body->response->title!=$grouptitle||$respgroup->body->response->description!=$groupdescription||$respgroup->body->response->isPrivate!=$groupisprivate) {
if($respgroup->body->response->responsible->userName!=$groupowner->getUsername()||$respgroup->body->response->status!=0||$respgroup->body->response->title!=$grouptitle||$respgroup->body->response->description!=$groupdescription||$respgroup->body->response->isPrivate!=$groupisprivate) {
$this->writeln("Modification du groupe dans Only. Group = ".$group->getLabel());
if(!$simulate) {
// Liste des membres Only
$membersOnly=[];
$respmember = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice().'/team',$headers);
if($this->koresponse($respmember)) {
$this->writelnred("ERREUR SUR RECUPERATION DES MEMBRES du Group = ".$group->getLabel());
continue;
}
foreach($respmember->body->response as $member) {
array_push($membersOnly,$member->id);
}
// On modifie le groupe only
$query = array('title' => $grouptitle, 'description' => $groupdescription, 'responsibleId' => $respuser->body->response->id, 'private' => $groupisprivate);
$query = array(
'status' => 0,
'title' => $grouptitle,
'description' => $groupdescription,
'responsibleId' => $respuser->body->response->id,
'participants' => $membersOnly,
'private' => $groupisprivate,
'notify' => true
);
$body = \Unirest\Request\Body::json($query);
$respmodif = \Unirest\Request::put($this->only_url.'/project/'.$respgroup->body->response->id."/withSecurityInfo",$headers,$body);
$respmodif = \Unirest\Request::put($this->only_url.'/project/'.$respgroup->body->response->id,$headers,$body);
if($this->koresponse($respmodif)) {
$this->writelnred("ERREUR SUR MODIFICATION du Group = ".$group->getLabel());
}
@ -395,13 +429,19 @@ class OnlyCommand extends Command
}
}
}
}
$this->writeln('');
$this->writeln('== RATTACHER LES UTILISATEURS =======================');
$groups=$this->em->getRepository("CadolesCoreBundle:Group")->findBy(["fgcanshare"=>true]);
foreach($groups as $group) {
// Si pas d'erreur on doit avoir à présent le projet dans only rattaché à un groupe ninegate
// On va pouvoir s'occuper des membres du groupes
if($group->getIdonlyoffice()) {
// Liste des membres Ninegate
$membersNingate=[];
foreach($group->getUsers() as $member) {
$usergroups=$this->em->getRepository("CadolesCoreBundle:UserGroup")->findBy(["group"=>$group]);
foreach($usergroups as $member) {
array_push($membersNingate,$member->getUser()->getUsername());
}
@ -410,6 +450,8 @@ class OnlyCommand extends Command
array_push($membersNingate,"admin");
}
// Liste des membres Only
$membersOnly=[];
$respmember = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice().'/team',$headers);
@ -465,6 +507,48 @@ class OnlyCommand extends Command
}
}
}
$this->writeln('');
$this->writeln('== FERMER LES GROUPES FONCTIONNELS====================');
$groups=$this->em->getRepository("CadolesCoreBundle:Group")->findBy(["fgcanshare"=>false]);
foreach($groups as $group) {
if($group->getIdonlyoffice()) {
$grouptitle=$group->getLabel();
$groupdescription=$group->getDescription();
$groupowner=$group->getOwner();
// Si pas de propriétaire de projet on le rattache à admin
if(!$groupowner)
$groupowner=$this->em->getRepository("CadolesCoreBundle:User")->findOneBy(["username"=>"admin"]);
if($groupowner) {
// On recherche le propriétaire du groupe dans only
$respuser = \Unirest\Request::get($this->only_url.'/people/'.$groupowner->getUsername(),$headers);
if(!$this->koresponse($respuser)) {
$respgroup = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice(),$headers);
if(!$this->koresponse($respgroup)) {
if($respgroup->body->response->status!=1) {
$this->writeln("Fermer le groupe dans Only. Group = ".$group->getLabel());
if(!$simulate) {
// On ferme le projet
$query = array(
'title' => $grouptitle,
'description' => $groupdescription,
'responsibleId' => $respuser->body->response->id,
'participants' => $respgroup->body->response->participants,
'private' => $groupisprivate,
'status' => 1,
'notify' => true
);
$body = \Unirest\Request\Body::json($query);
$respupdate = \Unirest\Request::put($this->only_url.'/project/'.$group->getIdonlyoffice(),$headers,$body);
}
}
}
}
}
}
}
}
$this->writeln('');

View File

@ -158,7 +158,6 @@ class Group
*/
protected $blogs;
/**
* @var ArrayCollection $message
* @var Message
@ -167,6 +166,21 @@ class Group
*/
protected $messages;
// Champs temporaire
protected $nosynconly;
public function getNosynconly()
{
return $this->nosynconly;
}
public function setNosynconly($nosynconly)
{
$this->nosynconly = $nosynconly;
return $this;
}
// ATTENTION NE SURTOUT PAS REGEN TOTALEMENT LES SETTER
// Methode custom sur les Addxxx et Removexxx

View File

@ -18,7 +18,7 @@ class onlyService
protected $only_host;
protected $only_user;
protected $only_password;
protected $debug = true;
protected $debug = false;
protected $headers = [];
public function __construct($container, EntityManager $em)
@ -111,6 +111,8 @@ class onlyService
//==================================================================================================================================================================
public function syncGroup(Group $group, $oldid) {
if($group->getNosynconly()) return true;
$this->mydebug("==SYNC ONLY GROUP=========================================================");
// Authentification à Only
@ -147,21 +149,34 @@ class onlyService
$onlygroup=$respgroup->body->response;
// Si véritable modification
if($onlygroup->responsible->userName!=$groupowner->getUsername()||$onlygroup->title!=$grouptitle||$onlygroup->description!=$groupdescription||$onlygroup->isPrivate!=$groupisprivate) {
if($onlygroup->status!=0||$onlygroup->responsible->userName!=$groupowner->getUsername()||$onlygroup->title!=$grouptitle||$onlygroup->description!=$groupdescription||$onlygroup->isPrivate!=$groupisprivate) {
$this->mydebug("Lancer la modification");
$this->mydebug($respuser->body->response->userName." !=".$groupowner->getUsername());
$this->mydebug($onlygroup->title." !=".$grouptitle);
$this->mydebug($onlygroup->description." !=".$groupdescription);
$this->mydebug($onlygroup->isPrivate." !=".$groupisprivate);
$this->mydebug($respuser->body->response->userName." != ".$groupowner->getUsername());
$this->mydebug($onlygroup->title." != ".$grouptitle);
$this->mydebug($onlygroup->description." != ".$groupdescription);
$this->mydebug($onlygroup->isPrivate." != ".$groupisprivate);
$this->mydebug($onlygroup->status." != 0");
// Liste des membres Only
$membersOnly=[];
$respmember = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice().'/team',$this->headers);
if(!$this->koresponse($respmember)) {
foreach($respmember->body->response as $member) {
array_push($membersOnly,$member->id);
}
$query = array(
'title' => $grouptitle,
'description' => $groupdescription,
'responsibleId' => $respuser->body->response->id,
'private' => $groupisprivate
'participants' => $membersOnly,
'private' => $groupisprivate,
'status' => 0,
'notify' => true
);
$body = \Unirest\Request\Body::json($query);
$respupdate = \Unirest\Request::put($this->only_url.'/project/'.$onlygroup->id."/withSecurityInfo",$this->headers,$body);
$respupdate = \Unirest\Request::put($this->only_url.'/project/'.$onlygroup->id,$this->headers,$body);
}
}
}
@ -198,17 +213,60 @@ class onlyService
}
}
// Si non groupe de travail mais avec un id Only
// Si non groupe de travail mais avec un id Only, on supprime le groupe only
elseif($group->getIdonlyoffice()) {
$this->mydebug("Groupe lié à only mais qui n'est plus un groupe de travail");
$this->delGroup($group);
}
}
return true;
}
public function delGroup(Group $group) {
// Si groupe associé à un groupe only
if($group->getIdonlyoffice()) {
$grouptitle=$group->getLabel();
$groupdescription=$group->getDescription();
$groupowner=$group->getOwner();
$groupisprivate=true;
// On recherche le groupe eportail
// Si pas de propriétaire de projet on le rattache à admin
if(!$groupowner)
$groupowner=$this->em->getRepository("CadolesCoreBundle:User")->findOneBy(["username"=>"admin"]);
// Si existe suppression
if($groupowner&&$this->authOnly()) {
// On recherche le propriétaire du groupe dans only
$respuser = \Unirest\Request::get($this->only_url.'/people/'.$groupowner->getUsername(),$this->headers);
if(!$this->koresponse($respuser)) {
$respgroup = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice(),$this->headers);
if(!$this->koresponse($respgroup)) {
$this->mydebug("Fermer le groupe ".$group->getLabel()." ".$group->getIdonlyoffice());
$membersOnly=[];
$respmember = \Unirest\Request::get($this->only_url.'/project/'.$group->getIdonlyoffice().'/team',$this->headers);
if(!$this->koresponse($respmember)) {
foreach($respmember->body->response as $member) {
array_push($membersOnly,$member->id);
}
// On ferme le projet
$query = array(
'title' => $grouptitle,
'description' => $groupdescription,
'responsibleId' => $respuser->body->response->id,
'participants' => $membersOnly,
'private' => $groupisprivate,
'status' => 1,
'notify' => true
);
$body = \Unirest\Request\Body::json($query);
$respupdate = \Unirest\Request::put($this->only_url.'/project/'.$group->getIdonlyoffice(),$this->headers,$body);
}
}
}
}
}
return true;
}
@ -218,25 +276,31 @@ class onlyService
//==================================================================================================================================================================
public function delUserGroup(UserGroup $usergroup) {
// Recherche de l'utilisateur eportail
// s'il existe
// Recherche du groupe
// si le groupe existe
// Suppression du rattachement
// Si groupe lié à only
if($usergroup->getGroup()->getIdonlyoffice()) {
if($this->authOnly()) {
$respuser = \Unirest\Request::get($this->only_url.'/people/'.$usergroup->getUser()->getUsername(),$this->headers);
if(!$this->koresponse($respuser)) {
$query = array('userId' => $respuser->body->response->id);
$body = \Unirest\Request\Body::json($query);
$respsubmit = \Unirest\Request::delete($this->only_url.'/project/'.$usergroup->getGroup()->getIdonlyoffice().'/team',$this->headers,$body);
}
}
}
}
public function addUserGroup(UserGroup $usergroup) {
// Recherche de l'utilisateur eportail
// s'il existe
// Recherche du groupe
// si le groupe existe
// Création du rattachement
// Si groupe lié à only
if($usergroup->getGroup()->getIdonlyoffice()) {
if($this->authOnly()) {
$respuser = \Unirest\Request::get($this->only_url.'/people/'.$usergroup->getUser()->getUsername(),$this->headers);
if(!$this->koresponse($respuser)) {
$query = array('userId' => $respuser->body->response->id);
$body = \Unirest\Request\Body::json($query);
$respsubmit = \Unirest\Request::post($this->only_url.'/project/'.$usergroup->getGroup()->getIdonlyoffice().'/team',$this->headers,$body);
}
}
}
}