1414use ExpandableFAQ \Models \Language \LanguageInterface ;
1515use ExpandableFAQ \Models \Cache \StaticSession ;
1616use ExpandableFAQ \Models \Status \NetworkStatus ;
17+ use ExpandableFAQ \Models \Status \SingleStatus ;
18+ use ExpandableFAQ \Models \Update \Database60Z ;
1719use ExpandableFAQ \Models \Validation \StaticValidator ;
1820use ExpandableFAQ \Views \PageView ;
1921
@@ -27,7 +29,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2729 {
2830 // Set class settings
2931 $ this ->conf = $ paramConf ;
30- // Already sanitized before in it's constructor. Too much sanitation will kill the system speed
32+ // Already sanitized before in it's constructor. Too much sanitization will kill the system speed
3133 $ this ->lang = $ paramLang ;
3234 }
3335
@@ -42,7 +44,7 @@ public function processPopulateData()
4244 $ objNetworkStatus = new NetworkStatus ($ this ->conf , $ this ->lang );
4345
4446 // We only allow to populate the data if the newest plugin database struct exists
45- if ($ objNetworkStatus ->checkPluginDBStructExists ($ this ->conf ->getPluginVersion ()))
47+ if ($ objNetworkStatus ->checkPluginDB_StructExists ($ this ->conf ->getPluginSemver ()))
4648 {
4749 // Save original locale
4850 $ orgLang = $ this ->lang ;
@@ -61,6 +63,7 @@ public function processPopulateData()
6163 // Populate the data (without table creation)
6264 // INFO: This plugin do not use custom roles
6365 $ objInstaller ->setCustomCapabilities ();
66+ // INFO: This plugin do not use REST API
6467 // INFO: This plugin do not use custom post types
6568 $ objInstaller ->setContent ();
6669 $ objInstaller ->replaceResettableContent ();
@@ -105,6 +108,64 @@ public function processDropData()
105108 }
106109 }
107110
111+ /**
112+ * For updating across multisite the network-enabled plugin from 5.0.0 to V6.0.Z
113+ * @note - Works only with WordPress 4.6+
114+ * @return bool
115+ * @throws \Exception
116+ */
117+ private function process60Z_Patches ()
118+ {
119+ // Create mandatory instances
120+ $ allSitesSemverUpdated = TRUE ;
121+
122+ // NOTE: Network site is one of the sites. So it will update network site id as well.
123+ $ sites = get_sites ();
124+ foreach ($ sites AS $ site )
125+ {
126+ $ blogId = $ site ->blog_id ;
127+ switch_to_blog ($ blogId );
128+
129+ $ lang = new Language (
130+ $ this ->conf ->getTextDomain (), $ this ->conf ->getGlobalLangPath (), $ this ->conf ->getLocalLangPath (), $ this ->conf ->getBlogLocale ($ blogId ), FALSE
131+ );
132+
133+ // Update the database data
134+ $ objSingleDB_Patch = new Database60Z ($ this ->conf , $ lang , $ blogId );
135+ $ objSingleStatus = new SingleStatus ($ this ->conf , $ lang , $ blogId );
136+ $ pluginSemverInDB = $ objSingleStatus ->getPluginSemverInDatabase ();
137+
138+ // Process ONLY if the current blog has populated extension data, network struct is already updated
139+ // and current site database was not yet updated
140+ if (
141+ $ objSingleStatus ->checkPluginDataExists ('6.0.0 ' )
142+ && version_compare ($ pluginSemverInDB , '6.0.0 ' , '>= ' ) && version_compare ($ pluginSemverInDB , '6.1.0 ' , '< ' )
143+ ) {
144+ $ dataPatched = $ objSingleDB_Patch ->patchData ();
145+ if ($ dataPatched === FALSE )
146+ {
147+ $ allSitesSemverUpdated = FALSE ;
148+ } else
149+ {
150+ // Update the current site database version to 6.0.0
151+ $ semverUpdated = $ objSingleDB_Patch ->updateDatabaseSemver ();
152+ if ($ semverUpdated == FALSE )
153+ {
154+ $ allSitesSemverUpdated = FALSE ;
155+ }
156+ }
157+ }
158+
159+ StaticSession::cacheHTMLArray ('admin_debug_message ' , $ objSingleDB_Patch ->getDebugMessages ());
160+ StaticSession::cacheValueArray ('admin_okay_message ' , $ objSingleDB_Patch ->getOkayMessages ());
161+ StaticSession::cacheValueArray ('admin_error_message ' , $ objSingleDB_Patch ->getErrorMessages ());
162+ }
163+ // Switch back to current network blog id. Restore current blog won't work here, as it would just restore to previous blog of the long loop
164+ switch_to_blog ($ this ->conf ->getBlogId ());
165+
166+ return $ allSitesSemverUpdated ;
167+ }
168+
108169 /**
109170 * @throws \Exception
110171 */
@@ -115,16 +176,27 @@ private function processUpdate()
115176
116177 // Allow only one update at-a-time per site refresh. We need that to save resources of server to not to get to timeout phase
117178 $ allUpdatableSitesUpdated = FALSE ;
118- $ minPluginVersionInDatabase = $ objStatus ->getMinPluginVersionInDatabase ();
179+ $ minPluginSemverInDatabase = $ objStatus ->getMinPluginSemverInDatabase ();
180+ $ maxPluginSemverInDatabase = $ objStatus ->getMaxPluginSemverInDatabase ();
181+ $ latestSemver = $ this ->conf ->getPluginSemver ();
119182
120- // -----------------------------------------------------------
121- // A PLACE FOR UPDATE CODE
122- // -----------------------------------------------------------
183+ // ----------------------------------------
184+ // NOTE: A PLACE FOR UPDATE CODE
185+ // ----------------------------------------
123186
124- if ($ this ->conf ->isNetworkEnabled () && $ minPluginVersionInDatabase == 6.0 )
187+ if ($ this ->conf ->isNetworkEnabled ())
125188 {
126- // It's a last version
127- $ allUpdatableSitesUpdated = TRUE ;
189+ if (version_compare ($ minPluginSemverInDatabase , $ latestSemver , '== ' ))
190+ {
191+ // It's a last version
192+ $ allUpdatableSitesUpdated = TRUE ;
193+ }
194+
195+ // Run patches
196+ if (version_compare ($ minPluginSemverInDatabase , '6.0.0 ' , '>= ' ) && version_compare ($ maxPluginSemverInDatabase , '6.1.0 ' , '< ' ))
197+ {
198+ $ allUpdatableSitesUpdated = $ this ->process60Z_Patches ();
199+ }
128200 }
129201
130202 // Check if plugin is up-to-date
@@ -149,7 +221,7 @@ private function processUpdate()
149221 public function printContent ()
150222 {
151223 // Message handler - should always be at the begging of method (in the very first line)
152- $ printDebugMessage = StaticValidator::inWPDebug () ? StaticSession::getHTMLOnce ('admin_debug_message ' ) : '' ;
224+ $ printDebugMessage = StaticValidator::inWP_Debug () ? StaticSession::getHTMLOnce ('admin_debug_message ' ) : '' ;
153225 $ printErrorMessage = StaticSession::getValueOnce ('admin_error_message ' );
154226 $ printOkayMessage = StaticSession::getValueOnce ('admin_okay_message ' );
155227
@@ -181,13 +253,15 @@ public function printContent()
181253 $ objView ->isNetworkEnabled = TRUE ;
182254 $ objView ->networkEnabled = $ this ->lang ->getPrint ('LANG_YES_TEXT ' );
183255 $ objView ->goToNetworkAdmin = FALSE ;
256+ $ objView ->updateExists = $ objStatus ->checkPluginUpdateExistsForSomeBlog ();
184257 $ objView ->updateAvailable = $ objStatus ->canUpdatePluginDataInSomeBlog ();
185258 $ objView ->majorUpgradeAvailable = $ objStatus ->canMajorlyUpgradePluginDataInSomeBlog ();
186259 $ objView ->canUpdate = $ objStatus ->canUpdatePluginDataInSomeBlog ();
187260 $ objView ->canMajorlyUpgrade = $ objStatus ->canMajorlyUpgradePluginDataInSomeBlog ();
188- $ objView ->databaseMatchesCodeVersion = $ objStatus ->isAllBlogsWithPluginDataUpToDate ();
189- $ objView ->databaseVersion = number_format_i18n ($ objStatus ->getMinPluginVersionInDatabase (), 1 );
190- $ objView ->newestVersionAvailable = number_format_i18n ($ this ->conf ->getPluginVersion (), 1 );
261+ $ objView ->databaseMatchesCodeSemver = $ objStatus ->isAllBlogsWithPluginDataUpToDate ();
262+ $ objView ->databaseSemver = $ objStatus ->getPrintMinPluginSemverInDatabase ();
263+ $ objView ->newestExistingSemver = $ this ->conf ->getPrintPluginSemver ();
264+ $ objView ->newestSemverAvailable = $ this ->conf ->getPrintPluginSemver ();
191265
192266 // Print the template
193267 $ templateRelPathAndFileName = 'Status ' .DIRECTORY_SEPARATOR .'NetworkTabs.php ' ;
0 commit comments