em = $em; } public function getSubscribedEvents(): array { return [ Events::postPersist, Events::postUpdate, ]; } public function postPersist(LifecycleEventArgs $args): void { $this->upinsertUser($args); } public function postUpdate(LifecycleEventArgs $args): void { $this->upinsertUser($args); } private function upinsertUser(LifecycleEventArgs $args): void { $this->user = $args->getObject(); if (!$this->user instanceof User) { return; } // On s'assure que le user a au moins une category d'illustration $this->insertCategory(); // On initialise l'ensemble des config customizable $this->insertConfig(); } private function insertCategory(): void { $user=$this->user; $category=$entity = $this->em->getRepository('App:Category')->findOneBy(["user"=>$this->user]); if(!$category) { $category = new Category; $category->setOrder(1); $category->setName("Illustrations"); $category->setUsecategoryconfig(false); $category->setAppthumbfilter(false); $category->setAppthumbheight(0); $category->setAppthumbwidth(0); $category->setAppthumbfilter(false); $category->setAppthumbfiltergrayscale(100); $category->setAppthumbfilteropacity(100); $category->setAppthumbfiltersepia(0); $category->setUser($this->user); $this->em->persist($category); $this->em->flush(); $this->user=$user; } dump($this->user); } private function insertConfig(): void { $user=$this->user; $configs=$entity = $this->em->getRepository('App:Config')->findBy(["user"=>null,"customizable"=>true]); foreach($configs as $config) { $custo=$this->em->getRepository('App:Config')->findBy(["user"=>$user,"keyid"=>$config->getKeyid()]); if(!$custo) { $custo=new Config; $custo->setKeyid($config->getKeyid()); $custo->setValue(null); $custo->setDefvalue(null); $custo->setCategory($config->getCategory()); $custo->setOrder($config->getOrder()); $custo->setTitle($config->getTitle()); $custo->setType($config->getType()); $custo->setVisible($config->getVisible()); $custo->setChangeable($config->getChangeable()); $custo->setRequired($config->getRequired()); $custo->setGrouped($config->getGrouped()); $custo->setHelp($config->getHelp()); $custo->setCustomizable($config->getCustomizable()); $custo->setUser($user); $this->em->persist($custo); $this->em->flush(); $this->user=$user; } } } }