@@ -106,32 +106,37 @@ public function syncFormModel()
106106 public function syncData (array $ data )
107107 {
108108 $ existingEntries = $ this ->entryManager ->search (['formsIds ' => [$ this ->config ['formId ' ]]]);
109- $ newYunohostUsers = array_udiff (array_keys ($ data ), array_keys ($ existingEntries ), 'strcasecmp ' );
110- $ removedYunohostUsers = array_udiff (array_keys ($ existingEntries ), array_keys ($ data ), 'strcasecmp ' );
109+ $ yunohostUserFunc = static function ($ entry1 , $ entry2 ) {
110+ $ value1 = isset ($ entry1 ['username ' ]) ? $ entry1 ['username ' ] : $ entry1 ['bf_titre ' ];
111+ $ value2 = isset ($ entry2 ['username ' ]) ? $ entry2 ['username ' ] : $ entry2 ['bf_titre ' ];
112+ return $ value1 <=> $ value2 ;
113+ };
114+ $ newYunohostUsers = array_udiff ($ data , $ existingEntries , $ yunohostUserFunc );
115+ $ removedYunohostUsers = array_udiff ($ existingEntries , $ data , $ yunohostUserFunc );
111116 foreach ($ newYunohostUsers as $ entry ) {
112- $ data [ $ entry] ['antispam ' ] = 1 ;
117+ $ entry ['antispam ' ] = 1 ;
113118 try {
114- $ this ->entryManager ->create ($ this ->config ['formId ' ], $ data [ $ entry] );
115- echo 'L \'utilisateur " ' .$ data [ $ entry] ['bf_titre ' ].'" créé. ' ."\n" ;
119+ $ this ->entryManager ->create ($ this ->config ['formId ' ], $ entry );
120+ echo 'L \'utilisateur " ' .$ entry ['bf_titre ' ].'" créé. ' ."\n" ;
116121 } catch (Exception $ ex ) {
117- echo 'Erreur lors de la création de la fiche utilisateur ' .$ data [ $ entry] ['bf_titre ' ].' : ' .$ ex ->getMessage ()."\n" ;
122+ echo 'Erreur lors de la création de la fiche utilisateur ' .$ entry ['bf_titre ' ].' : ' .$ ex ->getMessage ()."\n" ;
118123 }
119124 }
120125 foreach ($ removedYunohostUsers as $ entry ) {
121126 try {
122127 // TODO use this when 4.5 is released
123- // $this->entryManager->delete($existingEntries[$ entry] ['id_fiche']);
124- $ tag = $ existingEntries [ $ entry] ['id_fiche ' ];
128+ // $this->entryManager->delete($entry['id_fiche']);
129+ $ tag = $ entry ['id_fiche ' ];
125130 $ fiche = $ this ->entryManager ->getOne ($ tag , false , null , true );
126131 if (empty ($ fiche )) {
127132 throw new Exception ("Not existing entry : $ tag " );
128133 }
129134 $ this ->services ->get (PageManager::class)->deleteOrphaned ($ tag );
130135 $ this ->services ->get (TripleStore::class)->delete ($ tag , TripleStore::TYPE_URI , null , '' , '' );
131136 $ this ->services ->get (TripleStore::class)->delete ($ tag , TripleStore::SOURCE_URL_URI , null , '' , '' );
132- echo 'L \'utilisateur " ' .$ existingEntries [ $ entry] ['bf_titre ' ].'" a été supprimé. ' ."\n" ;
137+ echo 'L \'utilisateur " ' .$ entry ['bf_titre ' ].'" a été supprimé. ' ."\n" ;
133138 } catch (Exception $ ex ) {
134- echo 'Erreur lors de la suppression de la fiche utilisateur ' .$ existingEntries [ $ entry] ['bf_titre ' ].' : ' .$ ex ->getMessage ()."\n" ;
139+ echo 'Erreur lors de la suppression de la fiche utilisateur ' .$ entry ['bf_titre ' ].' : ' .$ ex ->getMessage ()."\n" ;
135140 }
136141 }
137142 return ;
0 commit comments