Skip to content

Commit b97247c

Browse files
committed
[6.0.2] Updating and patching are now separated. FA now loaded by default after install. Populate/drop data url behaviour changed. Some minor improvements.
6.0.2 release Updating and patching are now separated. FA now loaded by default after install. Populate/drop data url behaviour changed. Some minor improvements.
1 parent 8f9f828 commit b97247c

37 files changed

+1137
-467
lines changed

Controllers/Admin/AssetController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ public function enqueueMandatoryPlainJS()
4444
$dataTablesLangFilename = 'English.json';
4545
}
4646

47-
$extVars = array(
47+
$pluginVars = array(
4848
'DATATABLES_LANG_URL' => $this->conf->getRouting()->get3rdPartyAssetsURL($dataTablesRelURL.$dataTablesLangFilename, TRUE),
4949
);
50-
$extLang = array(
50+
$pluginLang = array(
5151
'LANG_FAQ_DELETING_DIALOG_TEXT' => $this->lang->getPrint('LANG_FAQ_DELETING_DIALOG_TEXT'),
5252
);
5353

@@ -60,8 +60,8 @@ public function enqueueMandatoryPlainJS()
6060
<?php
6161
}
6262
?>
63-
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Vars = <?=json_encode($extVars, JSON_FORCE_OBJECT);?>;</script>
64-
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Lang = <?=json_encode($extLang, JSON_FORCE_OBJECT);?>;</script>
63+
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Vars = <?=json_encode($pluginVars, JSON_FORCE_OBJECT);?>;</script>
64+
<script type="text/javascript"><?=$this->conf->getPluginJS_ClassPrefix();?>Lang = <?=json_encode($pluginLang, JSON_FORCE_OBJECT);?>;</script>
6565
<?php
6666
}
6767

Controllers/Admin/InstallController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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->checkPluginDB_StructExists($this->conf->getOldestCompatiblePluginSemver()) === FALSE)
44+
if ($objSingleSiteStatus->checkPluginDB_StructExistsOf($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->getOldestCompatiblePluginSemver()) === FALSE)
88+
if($objSingleSiteStatus->checkPluginDataExistsOf($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->getOldestCompatiblePluginSemver()) === FALSE)
107+
if($objSingleSiteStatus->checkPluginDataExistsOf($this->conf->getOldestCompatiblePluginSemver()) === FALSE)
108108
{
109109
// Delete any old table content if exists
110110
foreach(Install::getTableClasses() AS $tableClass)

Controllers/Admin/NetworkMenuController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function addMenu($paramMenuPosition = 97)
3939
// For admins only - update_plugins are official WordPress role for updates
4040
add_menu_page(
4141
$this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'), $this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'),
42-
"update_plugins", "{$URLPrefix}network-menu", array(&$this, "printNetworkStatus"), $iconURL, $validMenuPosition
42+
"update_plugins", "{$URLPrefix}network-menu", array($this, "printNetworkStatus"), $iconURL, $validMenuPosition
4343
);
4444
add_submenu_page(
4545
"{$URLPrefix}network-menu", $this->lang->getPrint('LANG_STATUS_NETWORK_TEXT'), $this->lang->getPrint('LANG_STATUS_NETWORK_TEXT'),
46-
"update_plugins", "{$URLPrefix}network-status", array(&$this, "printNetworkStatus")
46+
"update_plugins", "{$URLPrefix}network-status", array($this, "printNetworkStatus")
4747
);
4848
remove_submenu_page("{$URLPrefix}network-menu", "{$URLPrefix}network-menu");
4949
}

Controllers/Admin/SingleMenuController.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function addStatusMenu($paramMenuPosition = 97)
5151
// For those, who have 'update_plugins' rights - update_plugins are official WordPress role for updates
5252
add_menu_page(
5353
$this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'), $this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'),
54-
"update_plugins", "{$URLPrefix}single-menu", array(&$this, "printSingleStatus"), $iconURL, $validMenuPosition
54+
"update_plugins", "{$URLPrefix}single-menu", array($this, "printSingleStatus"), $iconURL, $validMenuPosition
5555
);
5656
add_submenu_page(
5757
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_STATUS_TEXT'), $this->lang->getPrint('LANG_STATUS_TEXT'),
58-
"update_plugins", "{$URLPrefix}single-status", array(&$this, "printSingleStatus")
58+
"update_plugins", "{$URLPrefix}single-status", array($this, "printSingleStatus")
5959
);
6060
remove_submenu_page("{$URLPrefix}single-menu", "{$URLPrefix}single-menu");
6161
}
@@ -73,48 +73,48 @@ public function addRegularMenu($paramMenuPosition = 97)
7373
// For those, who have 'view_{$pluginPrefix}partner_earnings' rights
7474
add_menu_page(
7575
$this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'), $this->lang->getPrint('LANG_MENU_ACCORDION_FAQ_TEXT'),
76-
"view_{$pluginPrefix}all_faqs", "{$URLPrefix}single-menu", array(&$this, "printFAQManager"), $iconURL, $validMenuPosition
76+
"view_{$pluginPrefix}all_faqs", "{$URLPrefix}single-menu", array($this, "printFAQManager"), $iconURL, $validMenuPosition
7777
);
7878
// For those, who have 'view_{$pluginPrefix}all_faqs' or 'manage_{$pluginPrefix}all_faqs' rights
7979
add_submenu_page(
8080
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_FAQ_MANAGER_TEXT'), $this->lang->getPrint('LANG_FAQ_MANAGER_TEXT'),
81-
"view_{$pluginPrefix}all_faqs", "{$URLPrefix}faq-manager", array(&$this, "printFAQManager")
81+
"view_{$pluginPrefix}all_faqs", "{$URLPrefix}faq-manager", array($this, "printFAQManager")
8282
);
8383
add_submenu_page(
8484
"{$URLPrefix}faq-manager", $this->lang->getPrint('LANG_FAQ_ADD_EDIT_TEXT'), $this->lang->getPrint('LANG_FAQ_ADD_EDIT_TEXT'),
85-
"manage_{$pluginPrefix}all_faqs", "{$URLPrefix}add-edit-faq", array(&$this, "printFAQAddEdit")
85+
"manage_{$pluginPrefix}all_faqs", "{$URLPrefix}add-edit-faq", array($this, "printFAQAddEdit")
8686
);
8787

8888
// For those, who have 'manage_{$pluginPrefix}all_settings' rights
8989
add_submenu_page(
9090
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_DEMOS_TEXT'), $this->lang->getPrint('LANG_DEMOS_TEXT'),
91-
"manage_{$pluginPrefix}all_settings","{$URLPrefix}demos", array(&$this, "printDemos")
91+
"manage_{$pluginPrefix}all_settings","{$URLPrefix}demos", array($this, "printDemos")
9292
);
9393
add_submenu_page(
9494
"{$URLPrefix}demo", $this->lang->getPrint('LANG_DEMO_IMPORT_TEXT'), $this->lang->getPrint('LANG_DEMO_IMPORT_TEXT'),
95-
"manage_{$pluginPrefix}all_settings","{$URLPrefix}import-demo", array(&$this, "printImportDemo")
95+
"manage_{$pluginPrefix}all_settings","{$URLPrefix}import-demo", array($this, "printImportDemo")
9696
);
9797

9898
// For those, who have 'edit_pages' rights
9999
// We allow to see shortcodes for those who have rights to edit pages (including item description pages)
100100
add_submenu_page(
101101
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_MANUAL_TEXT'), $this->lang->getPrint('LANG_MANUAL_TEXT'),
102-
"edit_pages","{$URLPrefix}manual", array(&$this, "printManual")
102+
"edit_pages","{$URLPrefix}manual", array($this, "printManual")
103103
);
104104

105105
// For those, who have 'view_{$pluginPrefix}all_settings' or 'manage_{$pluginPrefix}all_settings' rights
106106
add_submenu_page(
107107
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_SETTINGS_TEXT'), $this->lang->getPrint('LANG_SETTINGS_TEXT'),
108-
"view_{$pluginPrefix}all_settings","{$URLPrefix}settings", array(&$this, "printSettings")
108+
"view_{$pluginPrefix}all_settings","{$URLPrefix}settings", array($this, "printSettings")
109109
);
110110
add_submenu_page(
111111
"{$URLPrefix}settings", $this->lang->getPrint('LANG_SETTINGS_CHANGE_GLOBAL_SETTINGS_TEXT'), $this->lang->getPrint('LANG_SETTINGS_CHANGE_GLOBAL_SETTINGS_TEXT'),
112-
"manage_{$pluginPrefix}all_settings","{$URLPrefix}change-global-settings", array(&$this, "printChangeGlobalSettings")
112+
"manage_{$pluginPrefix}all_settings","{$URLPrefix}change-global-settings", array($this, "printChangeGlobalSettings")
113113
);
114114

115115
add_submenu_page(
116116
"{$URLPrefix}single-menu", $this->lang->getPrint('LANG_STATUS_TEXT'), $this->lang->getPrint('LANG_STATUS_TEXT'),
117-
"update_plugins", "{$URLPrefix}single-status", array(&$this, "printSingleStatus")
117+
"update_plugins", "{$URLPrefix}single-status", array($this, "printSingleStatus")
118118
);
119119
remove_submenu_page("{$URLPrefix}single-menu", "{$URLPrefix}single-menu");
120120
}

Controllers/Admin/Status/NetworkController.php

Lines changed: 20 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
/**
3+
* NOTE: As this is non-extension based plugin, there is no data network-populate / network-drop data links if the plugin is network-enabled
34
* @package ExpandableFAQ
45
* @author KestutisIT
56
* @copyright KestutisIT
@@ -14,8 +15,8 @@
1415
use ExpandableFAQ\Models\Language\LanguageInterface;
1516
use ExpandableFAQ\Models\Cache\StaticSession;
1617
use ExpandableFAQ\Models\Status\NetworkStatus;
17-
use ExpandableFAQ\Models\Status\SingleStatus;
18-
use ExpandableFAQ\Models\Update\Database60Z;
18+
use ExpandableFAQ\Models\Update\NetworkPatchesObserver;
19+
use ExpandableFAQ\Models\Update\NetworkUpdatesObserver;
1920
use ExpandableFAQ\Models\Validation\StaticValidator;
2021
use ExpandableFAQ\Views\PageView;
2122

@@ -33,149 +34,18 @@ public function __construct(ConfigurationInterface &$paramConf, LanguageInterfac
3334
$this->lang = $paramLang;
3435
}
3536

36-
/**
37-
* Activate (enable+install or enable only) plugin for across the whole network
38-
* @note - 'get_sites' function requires WordPress 4.6 or newer!
39-
* @throws \Exception
40-
*/
41-
public function processPopulateData()
42-
{
43-
// Create mandatory instances
44-
$objNetworkStatus = new NetworkStatus($this->conf, $this->lang);
45-
46-
// We only allow to populate the data if the newest plugin database struct exists
47-
if ($objNetworkStatus->checkPluginDB_StructExists($this->conf->getPluginSemver()))
48-
{
49-
// Save original locale
50-
$orgLang = $this->lang;
51-
52-
$sites = get_sites();
53-
foreach ($sites AS $site)
54-
{
55-
$blogId = $site->blog_id;
56-
switch_to_blog($blogId);
57-
58-
$lang = new Language(
59-
$this->conf->getTextDomain(), $this->conf->getGlobalLangPath(), $this->conf->getLocalLangPath(), $this->conf->getBlogLocale($blogId), FALSE
60-
);
61-
$objInstaller = new InstallController($this->conf, $lang, $blogId);
62-
63-
// Populate the data (without table creation)
64-
// INFO: This plugin do not use custom roles
65-
$objInstaller->setCustomCapabilities();
66-
// INFO: This plugin do not use REST API
67-
// INFO: This plugin do not use custom post types
68-
$objInstaller->setContent();
69-
$objInstaller->replaceResettableContent();
70-
$objInstaller->registerAllForTranslation();
71-
}
72-
// Switch back to current blog id. Restore current blog won't work here, as it would just restore to previous blog of the long loop
73-
switch_to_blog($this->conf->getBlogId());
74-
// Restore original locale
75-
$this->lang = $orgLang;
76-
}
77-
}
78-
79-
/**
80-
* Note: for data drop, we do not drop the roles, to protect from issues to happen on other extensions
81-
*/
82-
public function processDropData()
83-
{
84-
$sites = get_sites();
85-
foreach ($sites AS $site)
86-
{
87-
$blogId = $site->blog_id;
88-
switch_to_blog($blogId);
89-
90-
// Delete any old table content if exists
91-
foreach(Install::getTableClasses() AS $tableClass)
92-
{
93-
if(class_exists($tableClass))
94-
{
95-
$objTable = new $tableClass($this->conf, $this->lang, $blogId);
96-
if(method_exists($objTable, 'deleteContent') && method_exists($objTable, 'getDebugMessages') && method_exists($objTable, 'getErrorMessages'))
97-
{
98-
$objTable->deleteContent();
99-
StaticSession::cacheHTMLArray('admin_debug_message', $objTable->getDebugMessages());
100-
// We don't process okay messages here
101-
StaticSession::cacheValueArray('admin_error_message', $objTable->getErrorMessages());
102-
}
103-
}
104-
}
105-
// Delete any old WordPress posts if exists
106-
// INFO: NOTHING for plugin - it does not use any custom post types
107-
// NOTE: To void a errors on WordPress page deletion error, we skip exception raising for them
108-
}
109-
}
110-
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-
16937
/**
17038
* @throws \Exception
17139
*/
17240
private function processUpdate()
17341
{
17442
// Create mandatory instances
17543
$objStatus = new NetworkStatus($this->conf, $this->lang);
44+
$objUpdatesObserver = new NetworkUpdatesObserver($this->conf, $this->lang);
45+
$objPatchesObserver = new NetworkPatchesObserver($this->conf, $this->lang);
17646

17747
// 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
178-
$allUpdatableSitesUpdated = FALSE;
48+
$allUpdatableSitesSemverUpdated = FALSE;
17949
$minPluginSemverInDatabase = $objStatus->getMinPluginSemverInDatabase();
18050
$maxPluginSemverInDatabase = $objStatus->getMaxPluginSemverInDatabase();
18151
$latestSemver = $this->conf->getPluginSemver();
@@ -189,20 +59,30 @@ private function processUpdate()
18959
if(version_compare($minPluginSemverInDatabase, $latestSemver, '=='))
19060
{
19161
// It's a last version
192-
$allUpdatableSitesUpdated = TRUE;
62+
$allUpdatableSitesSemverUpdated = TRUE;
19363
}
19464

195-
// Run patches
65+
// Process 6.0.Z patches
19666
if(version_compare($minPluginSemverInDatabase, '6.0.0', '>=') && version_compare($maxPluginSemverInDatabase, '6.1.0', '<'))
19767
{
198-
$allUpdatableSitesUpdated = $this->process60Z_Patches();
68+
$allUpdatableSitesSemverUpdated = $objPatchesObserver->doPatch(6, 0);
19969
}
70+
71+
// Cache update messages
72+
StaticSession::cacheHTMLArray('admin_debug_message', $objUpdatesObserver->getSavedDebugMessages());
73+
StaticSession::cacheValueArray('admin_okay_message', $objUpdatesObserver->getSavedOkayMessages());
74+
StaticSession::cacheValueArray('admin_error_message', $objUpdatesObserver->getSavedErrorMessages());
75+
76+
// Cache patch messages
77+
StaticSession::cacheHTMLArray('admin_debug_message', $objPatchesObserver->getSavedDebugMessages());
78+
StaticSession::cacheValueArray('admin_okay_message', $objPatchesObserver->getSavedOkayMessages());
79+
StaticSession::cacheValueArray('admin_error_message', $objPatchesObserver->getSavedErrorMessages());
20080
}
20181

20282
// Check if plugin is up-to-date
20383
$pluginUpToDate = $objStatus->isAllBlogsWithPluginDataUpToDate();
20484

205-
if($allUpdatableSitesUpdated === FALSE || $pluginUpToDate === FALSE)
85+
if($allUpdatableSitesSemverUpdated === FALSE || $pluginUpToDate === FALSE)
20686
{
20787
// Failed or if there is more updates to go
20888
wp_safe_redirect('admin.php?page='.$this->conf->getPluginURL_Prefix().'network-status&tab=status');
@@ -226,8 +106,6 @@ public function printContent()
226106
$printOkayMessage = StaticSession::getValueOnce('admin_okay_message');
227107

228108
// Both - _POST and _GET supported
229-
if(isset($_GET['populate_data']) || isset($_POST['populate_data'])) { $this->processPopulateData(); }
230-
if(isset($_GET['drop_data']) || isset($_POST['drop_data'])) { $this->processDropData(); }
231109
if(isset($_GET['update']) || isset($_POST['update'])) { $this->processUpdate(); }
232110

233111
// Create mandatory instances

0 commit comments

Comments
 (0)