3333use Joomla \CMS \Uri \Uri ;
3434use Joomla \CMS \User \UserHelper ;
3535use Joomla \CMS \Version ;
36+ use Joomla \Component \Joomlaupdate \Administrator \Enum \AutoupdateRegisterResultState ;
3637use Joomla \Component \Joomlaupdate \Administrator \Enum \AutoupdateRegisterState ;
3738use Joomla \Database \ParameterType ;
3839use Joomla \Filesystem \Exception \FilesystemException ;
@@ -548,17 +549,18 @@ public function prepareAutoUpdate(string $targetVersion): array
548549 return [
549550 'password ' => $ app ->getUserState ('com_joomlaupdate.password ' ),
550551 'filesize ' => $ app ->getUserState ('com_joomlaupdate.filesize ' ),
552+ 'filename ' => $ app ->getUserState ('com_joomlaupdate.file ' ),
551553 ];
552554 }
553555
554556 /**
555557 * Change the registration state of a site in the update service
556558 *
557- * @return bool
559+ * @return AutoupdateRegisterResultState
558560 *
559561 * @since 5.4.0
560562 */
561- public function changeAutoUpdateRegistration (AutoupdateRegisterState $ targetState )
563+ public function changeAutoUpdateRegistration (AutoupdateRegisterState $ targetState ): AutoupdateRegisterResultState
562564 {
563565 // Purge cache - this makes sure that the changed status will already be available if the health check is performed
564566 $ this ->cleanCache ('_system ' );
@@ -583,47 +585,82 @@ public function changeAutoUpdateRegistration(AutoupdateRegisterState $targetStat
583585 } catch (\RuntimeException $ e ) {
584586 Factory::getApplication ()->enqueueMessage ($ e ->getMessage (), 'error ' );
585587
586- return false ;
588+ return AutoupdateRegisterResultState::Failed ;
587589 }
588590
589591 // Decode response
590592 $ result = json_decode ((string )$ response ->getBody (), true );
591593
592- // Handle non-success response
594+ // Handle validation issue
595+ if ($ response ->getStatusCode () === 422 ) {
596+ // Append message
597+ Factory::getApplication ()->enqueueMessage (
598+ Text::sprintf (
599+ 'COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_UNAVAILABLE ' ,
600+ ),
601+ 'warning '
602+ );
603+
604+ $ this ->updateAutoUpdateParams (
605+ AutoupdateRegisterState::Unsubscribed,
606+ false
607+ );
608+
609+ return AutoupdateRegisterResultState::Unavailable;
610+ }
611+
612+ // Handle other non-success response
593613 if ($ response ->getStatusCode () !== 200 ) {
594614 Factory::getApplication ()->enqueueMessage (
595615 Text::sprintf (
596616 'COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_ERROR ' ,
597- $ result ['message ' ],
598- $ result ['status ' ]
617+ $ result ['message ' ] ?: '' ,
618+ $ result ['status ' ] ?: ''
599619 ),
600620 'error '
601621 );
602622
603- return false ;
623+ $ this ->updateAutoUpdateParams (
624+ AutoupdateRegisterState::Unsubscribed,
625+ false
626+ );
627+
628+ return AutoupdateRegisterResultState::Failed;
604629 }
605630
631+ $ this ->updateAutoUpdateParams (
632+ ($ targetState === AutoupdateRegisterState::Subscribe)
633+ ? AutoupdateRegisterState::Subscribed
634+ : AutoupdateRegisterState::Unsubscribed,
635+ ($ targetState === AutoupdateRegisterState::Unsubscribed)
636+ );
637+
638+ return AutoupdateRegisterResultState::Success;
639+ }
640+
641+ /**
642+ * Update the autoupdate activation and registration states
643+ *
644+ * @since __DEPLOY_VERSION__
645+ */
646+ protected function updateAutoUpdateParams (AutoupdateRegisterState $ registrationState , bool $ enableUpdate ): void
647+ {
606648 // Get extension row
607649 $ extension = new Extension ($ this ->getDatabase ());
608650 $ extensionId = $ extension ->find (['element ' => 'com_joomlaupdate ' ]);
609651 $ extension ->load ($ extensionId );
610652
611653 // Set new update registration state
612654 $ params = new Registry ($ extension ->params );
613- $ params ->set (
614- 'autoupdate_status ' ,
615- ($ targetState === AutoupdateRegisterState::Subscribe)
616- ? AutoupdateRegisterState::Subscribed->value
617- : AutoupdateRegisterState::Unsubscribed->value
618- );
655+
656+ $ params ->set ('autoupdate_status ' , $ registrationState ->value );
657+ $ params ->set ('autoupdate ' , (int ) $ enableUpdate );
619658
620659 $ extension ->params = $ params ->toString ();
621660
622661 if (!$ extension ->store ()) {
623662 throw new \RuntimeException ($ extension ->getError ());
624663 }
625-
626- return true ;
627664 }
628665
629666 /**
@@ -1347,15 +1384,36 @@ public function getPhpOptions()
13471384 $ options [] = $ option ;
13481385 $ updateInformation = $ this ->getUpdateInformation ();
13491386
1350- // Check if configured database is compatible with the next major version of Joomla
1351- $ nextMajorVersion = Version::MAJOR_VERSION + 1 ;
1352-
1353- if (version_compare ($ updateInformation ['latest ' ], (string ) $ nextMajorVersion , '>= ' )) {
1387+ // Extra checks when updating to the next major version of Joomla
1388+ if (version_compare ($ updateInformation ['latest ' ], (string ) Version::MAJOR_VERSION + 1 , '>= ' )) {
1389+ // Check if configured database is compatible with the next major version of Joomla
13541390 $ option = new \stdClass ();
13551391 $ option ->label = Text::sprintf ('INSTL_DATABASE_SUPPORTED ' , $ this ->getConfiguredDatabaseType ());
13561392 $ option ->state = $ this ->isDatabaseTypeSupported ();
13571393 $ option ->notice = null ;
13581394 $ options [] = $ option ;
1395+
1396+ // Check if the Joomla 5 backwards compatibility plugin is disabled
1397+ $ plugin = ExtensionHelper::getExtensionRecord ('compat ' , 'plugin ' , 0 , 'behaviour ' );
1398+
1399+ $ this ->translateExtensionName ($ plugin );
1400+
1401+ $ option = new \stdClass ();
1402+ $ option ->label = Text::sprintf ('COM_JOOMLAUPDATE_VIEW_DEFAULT_PLUGIN_DISABLED_TITLE ' , $ plugin ->name );
1403+ $ option ->state = !PluginHelper::isEnabled ('behaviour ' , 'compat ' );
1404+ $ option ->notice = $ option ->state ? null : Text::sprintf ('COM_JOOMLAUPDATE_VIEW_DEFAULT_PLUGIN_DISABLED_NOTICE ' , $ plugin ->folder , $ plugin ->element );
1405+ $ options [] = $ option ;
1406+
1407+ // Check if the Joomla 6 backwards compatibility plugin is enabled
1408+ $ plugin = ExtensionHelper::getExtensionRecord ('compat6 ' , 'plugin ' , 0 , 'behaviour ' );
1409+
1410+ $ this ->translateExtensionName ($ plugin );
1411+
1412+ $ option = new \stdClass ();
1413+ $ option ->label = Text::sprintf ('COM_JOOMLAUPDATE_VIEW_DEFAULT_PLUGIN_ENABLED_TITLE ' , $ plugin ->name );
1414+ $ option ->state = PluginHelper::isEnabled ('behaviour ' , 'compat6 ' );
1415+ $ option ->notice = $ option ->state ? null : Text::sprintf ('COM_JOOMLAUPDATE_VIEW_DEFAULT_PLUGIN_ENABLED_NOTICE ' , $ plugin ->folder , $ plugin ->element );
1416+ $ options [] = $ option ;
13591417 }
13601418
13611419 // Check if database structure is up to date
0 commit comments