@@ -80,12 +80,13 @@ public static function getSubscribedEvents(): array
8080 * @param string $location The URI for the site
8181 * @param boolean $enabled If this site is enabled
8282 * @param string $extraQuery Any additional request query to use when updating
83+ * @param int $total The total of update sites
8384 *
8485 * @return void
8586 *
8687 * @since 1.6
8788 */
88- private function addUpdateSite ($ name , $ type , $ location , $ enabled , $ extraQuery = '' )
89+ private function addUpdateSite ($ name , $ type , $ location , $ enabled , $ extraQuery = '' , int $ total = 1 )
8990 {
9091 // Look if the location is used already; doesn't matter what type you can't have two types at the same address, doesn't make sense
9192 $ db = $ this ->getDatabase ();
@@ -100,7 +101,32 @@ private function addUpdateSite($name, $type, $location, $enabled, $extraQuery =
100101
101102 $ update_site_id = (int ) $ db ->loadResult ();
102103
103- // If it doesn't exist, add it!
104+ // If it doesn't exist and there is an extension, use that site
105+ if (!$ update_site_id && $ this ->eid && $ total === 1 ) {
106+ $ query ->clear ();
107+ $ query ->select ($ db ->quoteName ('update_site_id ' ))
108+ ->from ($ db ->quoteName ('#__update_sites_extensions ' ))
109+ ->where ($ db ->quoteName ('extension_id ' ) . ' = :extension_id ' )
110+ ->bind (':extension_id ' , $ this ->eid , ParameterType::INTEGER );
111+
112+ $ db ->setQuery ($ query );
113+
114+ // When there is an existing update site, update the location and return
115+ if ($ id = $ db ->loadResult ()) {
116+ $ query ->clear ()
117+ ->update ($ db ->quoteName ('#__update_sites ' ))
118+ ->set ($ db ->quoteName ('location ' ) . ' = :location ' )
119+ ->where ($ db ->quoteName ('update_site_id ' ) . ' = :update_site_id ' )
120+ ->bind (':location ' , $ location )
121+ ->bind (':update_site_id ' , $ id , ParameterType::INTEGER );
122+
123+ $ db ->setQuery ($ query );
124+ $ db ->execute ();
125+
126+ return ;
127+ }
128+ }
129+
104130 if (!$ update_site_id ) {
105131 $ enabled = (int ) $ enabled ;
106132 $ query ->clear ()
@@ -302,7 +328,7 @@ private function processUpdateSites()
302328 if (\count ($ children )) {
303329 foreach ($ children as $ child ) {
304330 $ attrs = $ child ->attributes ();
305- $ this ->addUpdateSite ((string ) $ attrs ['name ' ], (string ) $ attrs ['type ' ], trim ($ child ), true , $ this ->installer ->extraQuery );
331+ $ this ->addUpdateSite ((string ) $ attrs ['name ' ], (string ) $ attrs ['type ' ], trim ($ child ), true , $ this ->installer ->extraQuery , \count ( $ children ) );
306332 }
307333 } else {
308334 $ data = trim ((string ) $ updateservers );
0 commit comments