Skip to content

Commit 8f9f828

Browse files
committed
Full semver support, small improvements and fixes
1 parent 88242e9 commit 8f9f828

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2143
-525
lines changed

Controllers/Admin/AbstractController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2424
{
2525
// Set class settings
2626
$this->conf = $paramConf;
27-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
27+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
2828
$this->lang = $paramLang;
2929
// Set database settings
3030
$this->dbSets = new SettingsObserver($this->conf, $this->lang);
3131
$this->dbSets->setAll();
3232

3333
// Message handler - should always be at the begging of method
34-
$printDebugMessage = StaticValidator::inWPDebug() ? StaticSession::getHTMLOnce('admin_debug_message') : '';
34+
$printDebugMessage = StaticValidator::inWP_Debug() ? StaticSession::getHTMLOnce('admin_debug_message') : '';
3535
$printErrorMessage = StaticSession::getValueOnce('admin_error_message');
3636
$printOkayMessage = StaticSession::getValueOnce('admin_okay_message');
3737

Controllers/Admin/AssetController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2424
{
2525
// Set class settings
2626
$this->conf = $paramConf;
27-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
27+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
2828
$this->lang = $paramLang;
2929
}
3030

Controllers/Admin/InstallController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2626
{
2727
// Set class settings
2828
$this->conf = $paramConf;
29-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
29+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
3030
$this->lang = $paramLang;
3131

3232
$this->blogId = intval($paramBlogId);
@@ -41,7 +41,7 @@ public function setTables()
4141
$objSingleSiteStatus = new SingleStatus($this->conf, $this->lang, $this->blogId);
4242

4343
// @Note - even if this is multisite or 2nd or later extension install, tables will be created only once for the main site only (with blog_id = '0' or '1')
44-
if ($objSingleSiteStatus->checkPluginDBStructExists($this->conf->getOldestCompatiblePluginVersion()) === FALSE)
44+
if ($objSingleSiteStatus->checkPluginDB_StructExists($this->conf->getOldestCompatiblePluginSemver()) === FALSE)
4545
{
4646
// First - drop all tables if exists any to have a clean install as expected
4747
foreach(Install::getTableClasses() AS $tableClass)
@@ -85,7 +85,7 @@ public function setCustomCapabilities()
8585
$objAdministratorRole = new AdministratorRole($this->conf, $this->lang);
8686

8787
// Note - the section below is extension-independent, which means that it runs only once per install of first extension, despite how many extensions there are
88-
if($objSingleSiteStatus->checkPluginDataExists($this->conf->getOldestCompatiblePluginVersion()) === FALSE)
88+
if($objSingleSiteStatus->checkPluginDataExists($this->conf->getOldestCompatiblePluginSemver()) === FALSE)
8989
{
9090
// First - remove, if exists
9191
$objAdministratorRole->removeCapabilities();
@@ -104,7 +104,7 @@ public function setContent()
104104
$objSingleSiteStatus = new SingleStatus($this->conf, $this->lang, $this->blogId);
105105
$objSingleSiteInstall = new Install($this->conf, $this->lang, $this->blogId);
106106

107-
if($objSingleSiteStatus->checkPluginDataExists($this->conf->getOldestCompatiblePluginVersion()) === FALSE)
107+
if($objSingleSiteStatus->checkPluginDataExists($this->conf->getOldestCompatiblePluginSemver()) === FALSE)
108108
{
109109
// Delete any old table content if exists
110110
foreach(Install::getTableClasses() AS $tableClass)
@@ -252,7 +252,7 @@ protected function processDebug(array $paramDebugMessages)
252252
$debugMessagesToAdd[] = wp_kses_post($paramDebugMessage);
253253
}
254254

255-
if(StaticValidator::inWPDebug() && sizeof($debugMessagesToAdd) > 0)
255+
if(StaticValidator::inWP_Debug() && sizeof($debugMessagesToAdd) > 0)
256256
{
257257
echo '<br />'.implode('<br />', $debugMessagesToAdd);
258258
}

Controllers/Admin/NetworkMenuController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2323
{
2424
// Set class settings
2525
$this->conf = $paramConf;
26-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
26+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
2727
$this->lang = $paramLang;
2828
}
2929

@@ -71,7 +71,7 @@ public function printNetworkStatus()
7171
*/
7272
private function processError($paramName, $paramErrorMessage)
7373
{
74-
if(StaticValidator::inWPDebug())
74+
if(StaticValidator::inWP_Debug())
7575
{
7676
$sanitizedName = sanitize_text_field($paramName);
7777
$sanitizedErrorMessage = sanitize_text_field($paramErrorMessage);
@@ -82,7 +82,7 @@ private function processError($paramName, $paramErrorMessage)
8282

8383
// Works
8484
$sanitizedErrorMessage = '<div id="message" class="error"><p>'.$sanitizedErrorMessage.'</p></div>';
85-
_doing_it_wrong($sanitizedName, $sanitizedErrorMessage, $this->conf->getPluginVersion());
85+
_doing_it_wrong($sanitizedName, $sanitizedErrorMessage, $this->conf->getPluginSemver());
8686
}
8787
}
8888
}

Controllers/Admin/SingleMenuController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
3030
{
3131
// Set class settings
3232
$this->conf = $paramConf;
33-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
33+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
3434
$this->lang = $paramLang;
3535
}
3636

@@ -247,7 +247,7 @@ public function printSingleStatus()
247247
*/
248248
private function processError($paramName, $paramErrorMessage)
249249
{
250-
if(StaticValidator::inWPDebug())
250+
if(StaticValidator::inWP_Debug())
251251
{
252252
$sanitizedName = sanitize_text_field($paramName);
253253
$sanitizedErrorMessage = sanitize_text_field($paramErrorMessage);
@@ -258,7 +258,7 @@ private function processError($paramName, $paramErrorMessage)
258258

259259
// Works
260260
$sanitizedErrorMessage = '<div id="message" class="error"><p>'.$sanitizedErrorMessage.'</p></div>';
261-
_doing_it_wrong($sanitizedName, $sanitizedErrorMessage, $this->conf->getPluginVersion());
261+
_doing_it_wrong($sanitizedName, $sanitizedErrorMessage, $this->conf->getPluginSemver());
262262
}
263263
}
264264
}

Controllers/Admin/Status/NetworkController.php

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use ExpandableFAQ\Models\Language\LanguageInterface;
1515
use ExpandableFAQ\Models\Cache\StaticSession;
1616
use ExpandableFAQ\Models\Status\NetworkStatus;
17+
use ExpandableFAQ\Models\Status\SingleStatus;
18+
use ExpandableFAQ\Models\Update\Database60Z;
1719
use ExpandableFAQ\Models\Validation\StaticValidator;
1820
use 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';

Controllers/Admin/Status/SingleController.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ExpandableFAQ\Models\Language\LanguageInterface;
1414
use ExpandableFAQ\Models\Cache\StaticSession;
1515
use ExpandableFAQ\Models\Status\SingleStatus;
16+
use ExpandableFAQ\Models\Update\Database60Z;
1617
use ExpandableFAQ\Models\Validation\StaticValidator;
1718
use ExpandableFAQ\Views\PageView;
1819

@@ -26,7 +27,7 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
2627
{
2728
// Set class settings
2829
$this->conf = $paramConf;
29-
// Already sanitized before in it's constructor. Too much sanitation will kill the system speed
30+
// Already sanitized before in it's constructor. Too much sanitization will kill the system speed
3031
$this->lang = $paramLang;
3132
}
3233

@@ -44,13 +45,14 @@ public function processPopulateData()
4445
$objStatus = new SingleStatus($this->conf, $this->lang, $this->conf->getBlogId());
4546

4647
// We only allow to populate the data if the newest plugin database struct exists
47-
if ($objStatus->checkPluginDBStructExists($this->conf->getPluginVersion()))
48+
if ($objStatus->checkPluginDB_StructExists($this->conf->getPluginSemver()))
4849
{
4950
$objInstaller = new InstallController($this->conf, $this->lang, $this->conf->getBlogId());
5051

5152
// Populate the data (without table creation)
5253
// INFO: This plugin do not use custom roles
5354
$objInstaller->setCustomCapabilities();
55+
// INFO: This plugin do not use REST API
5456
// INFO: This plugin do not use custom post types
5557
$objInstaller->setContent();
5658
$objInstaller->replaceResettableContent();
@@ -95,16 +97,31 @@ private function processUpdate()
9597

9698
// 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
9799
$updated = FALSE;
98-
$pluginVersionInDatabase = $objStatus->getPluginVersionInDatabase();
100+
$pluginSemverInDatabase = $objStatus->getPluginSemverInDatabase();
101+
$latestSemver = $this->conf->getPluginSemver();
99102

100103
// ----------------------------------------
101104
// NOTE: PLACE FOR UPDATE CODE
102105
// ----------------------------------------
103106

104-
if($this->conf->isNetworkEnabled() === FALSE && $pluginVersionInDatabase == 6.0)
107+
if($this->conf->isNetworkEnabled() === FALSE)
105108
{
106-
// It's a last version
107-
$updated = TRUE;
109+
if(version_compare($pluginSemverInDatabase, $latestSemver, '=='))
110+
{
111+
// It's a last version
112+
$updated = TRUE;
113+
}
114+
115+
// Run patches
116+
if(version_compare($pluginSemverInDatabase, '6.0.0', '>=') && version_compare($pluginSemverInDatabase, '6.1.0', '<'))
117+
{
118+
$objDBUpdate = new Database60Z($this->conf, $this->lang, $this->conf->getBlogId());
119+
$patched = $objDBUpdate->patchData();
120+
if($patched)
121+
{
122+
$updated = $objDBUpdate->updateDatabaseSemver();
123+
}
124+
}
108125
}
109126

110127
// Check if plugin is up-to-date
@@ -129,7 +146,7 @@ private function processUpdate()
129146
public function printContent()
130147
{
131148
// Message handler - should always be at the begging of method (in the very first line)
132-
$printDebugMessage = StaticValidator::inWPDebug() ? StaticSession::getHTMLOnce('admin_debug_message') : '';
149+
$printDebugMessage = StaticValidator::inWP_Debug() ? StaticSession::getHTMLOnce('admin_debug_message') : '';
133150
$printErrorMessage = StaticSession::getValueOnce('admin_error_message');
134151
$printOkayMessage = StaticSession::getValueOnce('admin_okay_message');
135152

@@ -160,13 +177,15 @@ public function printContent()
160177
$objView->isNetworkEnabled = $this->conf->isNetworkEnabled();
161178
$objView->networkEnabled = $this->conf->isNetworkEnabled() ? $this->lang->getPrint('LANG_YES_TEXT') : $this->lang->getPrint('LANG_NO_TEXT');
162179
$objView->goToNetworkAdmin = $this->conf->isNetworkEnabled() ? TRUE : FALSE;
180+
$objView->updateExists = $objStatus->checkPluginUpdateExists();
163181
$objView->updateAvailable = $objStatus->canUpdatePluginDataInDatabase();
164182
$objView->majorUpgradeAvailable = $objStatus->canMajorlyUpgradePluginDataInDatabase();
165183
$objView->canUpdate = $objStatus->canUpdatePluginDataInDatabase();
166184
$objView->canMajorlyUpgrade = $objStatus->canMajorlyUpgradePluginDataInDatabase();
167-
$objView->databaseMatchesCodeVersion = $objStatus->isPluginDataUpToDateInDatabase();
168-
$objView->databaseVersion = number_format_i18n($objStatus->getPluginVersionInDatabase(), 1);
169-
$objView->newestVersionAvailable = number_format_i18n($this->conf->getPluginVersion(), 1);
185+
$objView->databaseMatchesCodeSemver = $objStatus->isPluginDataUpToDateInDatabase();
186+
$objView->databaseSemver = $objStatus->getPrintPluginSemverInDatabase();
187+
$objView->newestExistingSemver = $this->conf->getPrintPluginSemver();
188+
$objView->newestSemverAvailable = $this->conf->getPrintPluginSemver();
170189

171190
// Print the template
172191
$templateRelPathAndFileName = 'Status'.DIRECTORY_SEPARATOR.'SingleTabs.php';

0 commit comments

Comments
 (0)