giteaservice = $giteaservice; $this->session = $session; } public function findByUser($user) { if($user->hasRole("ROLE_MASTER") || $user->hasRole("ROLE_MODO") || $user->hasRole("ROLE_ADMIN")) return $this->_em->getRepository("App:Scrum")->findBy([],["name"=>"ASC"]); else { $scrums=$this ->createQueryBuilder('s') ->from('App:User','u') ->Where('u.id = :id') ->andWhere('u MEMBER OF s.users') ->setParameter('id',$user->getId()) ->orderBy('s.name') ->getQuery()->getResult(); return $scrums; } } public function getGitea($scrum,&$giteaassignees,&$giteacolumns,&$giteamilestones,&$giteateams,&$giteaprioritys,&$giteatypes,&$gitealabels, $forcereload=false) { $viewclosed = $this->session->get("viewclosed"); // Récupérer les labels de gitea $gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); if(!is_array($gitealabels)) die("Probleme de connexion avec gitea veuillez vous reconnecter"); // S'assurer que nos colonnes existes toujours $scrumcolumns=$scrum->getScrumcolumns(); foreach($scrumcolumns as $scrumcolumn) { $gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumcolumn->getGiteaid()); if(!$gitealabel) { $this->_em->remove($scrumcolumn); $this->_em->flush(); } } // S'assurer que nos teams existes toujours $scrumteams=$scrum->getScrumteams(); foreach($scrumteams as $scrumteam) { $gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumteam->getGiteaid()); if(!$gitealabel) { $this->_em->remove($scrumteam); $this->_em->flush(); } } // S'assurer que nos prioritys existes toujours $scrumprioritys=$scrum->getScrumprioritys(); foreach($scrumprioritys as $scrumpriority) { $gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumpriority->getGiteaid()); if(!$gitealabel) { $this->_em->remove($scrumpriority); $this->_em->flush(); } } // S'assurer que nos types existes toujours $scrumtypes=$scrum->getScrumtypes(); foreach($scrumtypes as $scrumtype) { $gitealabel=$this->giteaservice->getLabel($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumtype->getGiteaid()); if(!$gitealabel) { $this->_em->remove($scrumtype); $this->_em->flush(); } } // S'assurer que nos sprint sont toujours lié à un jalon existant $scrumsprints=$scrum->getScrumsprints(); foreach($scrumsprints as $scrumsprint) { $giteamilestone=$this->giteaservice->getMilestone($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumsprint->getGiteamilestone()); if(!$giteamilestone) { $this->_em->remove($scrumsprint); $this->_em->flush(); } } // Récupérer le dernier order $last = $this->_em->getRepository('App:Scrumissue')->findOneBy(["scrum"=>$scrum], ['rowid' => 'DESC']); if(!$last) $lastrowid=-1; else $lastrowid=$last->getRowid(); // Récupérer la premier column scrum $this->firstcolumn=$this->_em->getRepository('App:Scrumcolumn')->findOneBy(["scrum"=>$scrum], ['rowid' => 'ASC']); if(!$this->firstcolumn) return $this->redirectToRoute($this->route."_update",["id"=>$scrum->getId()]); // Récupérer la premier column scrum $columns=$this->_em->getRepository('App:Scrumcolumn')->findBy(["scrum"=>$scrum], ['rowid' => 'ASC']); $giteacolumns=[]; foreach($columns as $column) { array_push($giteacolumns,$column->getGiteaid()); } // Récupérer les teams $teams=$this->_em->getRepository('App:Scrumteam')->findBy(["scrum"=>$scrum], ['rowid' => 'ASC']); $giteateams=[]; foreach($teams as $team) { array_push($giteateams,$team->getGiteaid()); } // Récupérer les prioritys $prioritys=$this->_em->getRepository('App:Scrumpriority')->findBy(["scrum"=>$scrum], ['rowid' => 'ASC']); $giteaprioritys=[]; foreach($prioritys as $priority) { array_push($giteaprioritys,$priority->getGiteaid()); } // Récupérer les types $types=$this->_em->getRepository('App:Scrumtype')->findBy(["scrum"=>$scrum], ['rowid' => 'ASC']); $giteatypes=[]; foreach($types as $type) { array_push($giteatypes,$type->getGiteaid()); } // Récupérer la orga de gitea if(!empty($scrum->getGiteajson()["owner"]["email"])) $giteaassignees=[$scrum->getGiteajson()["owner"]]; else $giteaassignees=[]; $giteacollaborators=$this->giteaservice->getOrgateams($scrum->getGiteajson()["owner"]["login"]); if($giteacollaborators&&is_array($giteacollaborators)) { foreach($giteacollaborators as $team) { $giteamembers=$this->giteaservice->getTeammembers($team->id); if($giteamembers&&is_array($giteamembers)) { foreach($giteamembers as $giteamember) { if(!in_array($giteamember,$giteaassignees)) array_push($giteaassignees,$giteamember); } } } } $giteacollaborators=$this->giteaservice->getCollaborators($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); if(!is_array($giteacollaborators)) die("Probleme de connexion avec gitea veuillez vous reconnecter"); foreach($giteacollaborators as $giteacollaborator) { if(!in_array($giteacollaborator,$giteaassignees)) array_push($giteaassignees,$giteacollaborator); } // Récupérer les milestones de gitea $giteamilestones=$this->giteaservice->getMilestones($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open")); if(!is_array($giteamilestones)) die("Probleme de connexion avec gitea veuillez vous reconnecter"); $keysort = array_column($giteamilestones, 'title'); array_multisort($keysort, SORT_DESC, $giteamilestones); // Récupérer les labels de gitea $gitealabels=$this->giteaservice->getLabels($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"]); // Formatter les labels non colomn/team/priority/type foreach($gitealabels as $key => $gitealabel) { if(in_array($gitealabel->id,$giteacolumns)||in_array($gitealabel->id,$giteateams)||in_array($gitealabel->id,$giteaprioritys)||in_array($gitealabel->id,$giteatypes)) unset($gitealabels[$key]); } // Récupérer les issues de gitea $giteaissues=$this->giteaservice->getIssues($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],"?state=".($viewclosed=="true"?"all":"open")); if(!is_array($giteaissues)) die("Probleme de connexion avec gitea veuillez vous reconnecter"); // Génération des issues $tbgiteaissues=[]; $fgscrumupdate=false; $this->datescrumupdate=new \DateTime(); foreach($giteaissues as $giteaissue) { $scrumissue=$this->_em->getRepository("App:Scrumissue")->findOneBy(["scrum"=>$scrum,"giteaid"=>$giteaissue->id]); if(!$scrumissue) { $lastrowid++; $scrumissue=new Scrumissue(); $scrumissue->setScrum($scrum); $scrumissue->setRowid($lastrowid); $scrumissue->setGiteaid($giteaissue->id); $this->majissue($scrumissue,$giteaissue,true); } else { $fgissueupdated=false; if($scrumissue->getGiteajson()["updated_at"]!=json_decode(json_encode($giteaissue), true)["updated_at"]) $fgissueupdated=true; if($scrumissue->getGiteajson()["closed_at"]!=json_decode(json_encode($giteaissue), true)["closed_at"]) $fgissueupdated=true; if($giteaissue->milestone&&$scrumissue->getGiteamilestonename()!=$giteaissue->milestone->title) $fgissueupdated=true; if(!$giteaissue->milestone&&!is_null($scrumissue->getGiteamilestone())) $fgissueupdated=true; if($forcereload) { $fgissueupdated=true; } if($fgissueupdated) { $fgscrumupdate=true; $this->majissue($scrumissue,$giteaissue,false); } } array_push($tbgiteaissues,$giteaissue->number); } // Placer à closed l'ensemble des issues vu comme open mais qui ne le sont plus if($viewclosed=="false") { $scrumissues=$scrum->getScrumissues(); foreach($scrumissues as $scrumissue) { if($scrumissue->getGiteastate()=="open"&&!in_array($scrumissue->getGiteanumber(),$tbgiteaissues)) { $giteaissue=$this->giteaservice->getIssue($scrum->getGiteajson()["owner"]["login"],$scrum->getGiteajson()["name"],$scrumissue->getGiteanumber()); $fgscrumupdate=true; // S'il ne trouve pas d'issue c'est qu'elle n'existe plus if(!$giteaissue) { // Faudrait supprimer mais pour l'instant pas touche //dump("netrouvepasissue alors"); //dump($scrumissue->getGiteanumber()); } // Sinon mise else $this->majissue($scrumissue,$giteaissue,false); } } } if($fgscrumupdate) { $scrum->setUpdatedate($this->datescrumupdate); $this->_em->persist($scrum); $this->_em->flush(); } } function majissue($scrumissue,$giteaissue,$issubmit) { $scrumissue->setGiteanumber($giteaissue->number); $scrumissue->setGiteastate($giteaissue->state); $scrumissue->setGiteatitle($giteaissue->title); if($giteaissue->milestone) { $scrumissue->setGiteamilestone($giteaissue->milestone->id); $scrumissue->setGiteamilestonename($giteaissue->milestone->title); } else { $scrumissue->setGiteamilestone(null); $scrumissue->setGiteamilestonename(null); } $scrumissue->setGiteajson(json_decode(json_encode($giteaissue), true)); $this->_em->persist($scrumissue); $this->_em->flush(); $havecolumn=false; foreach($giteaissue->labels as $gitealabel) { $scrumcolumn=$this->_em->getRepository('App:Scrumcolumn')->findOneBy(["scrum"=>$scrumissue->getScrum(),"giteaid"=>$gitealabel->id]); if($scrumcolumn) { $havecolumn=true; $scrumissue->setScrumcolumn($scrumcolumn); break; } } if(!$havecolumn) { $scrumissue->setScrumcolumn($this->firstcolumn); // Affecter le label backlog en tant que gitealabel $backlog=array($this->firstcolumn->getGiteaid()); $this->giteaservice->putIssuelabels($scrumissue->getScrum()->getGiteajson()["owner"]["login"],$scrumissue->getScrum()->getGiteajson()["name"],$scrumissue->getGiteanumber(),$backlog); } // Sauvegarde de l'issue $this->_em->persist($scrumissue); $this->_em->flush(); } }