Skip to content

Commit da8209a

Browse files
committed
Improve database updater
This should fix the bug reported in #7
1 parent 5856353 commit da8209a

File tree

2 files changed

+94
-66
lines changed

2 files changed

+94
-66
lines changed

1_Base_Files/YOUR_ADMIN/includes/init_includes/init_so_config.php

+27-21
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,31 @@
77
* @copyright (c) 2014-2019, Zen4All
88
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
99
*/
10-
if (!defined('IS_ADMIN_FLAG')) {
11-
die('Illegal access');
12-
}
13-
14-
$module_constant = 'SO_VERSION';
15-
$module_installer_directory = DIR_FS_ADMIN . 'includes/installers/super_orders';
16-
$module_name = 'Super Orders';
17-
$module_file_for_version_check = '';
18-
$zencart_com_plugin_id = 155;
19-
20-
$configuration_group_id = '';
21-
if (defined($module_constant)) {
22-
$current_version = constant($module_constant);
23-
} else {
24-
$current_version = '0.0.0';
25-
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION_GROUP . " (configuration_group_title, configuration_group_description, sort_order, visible)
26-
VALUES ('" . $module_name . "', '" . $module_name . " Settings', '1', '1');");
27-
$configuration_group_id = $db->Insert_ID();
10+
if (!defined('IS_ADMIN_FLAG')) {
11+
die('Illegal Access');
12+
}
2813

14+
$module_constant = 'SO_VERSION';
15+
$module_installer_directory = DIR_FS_ADMIN . 'includes/installers/super_orders';
16+
$module_name = 'Super Orders';
17+
$zencart_com_plugin_id = 155;
18+
19+
$configuration_group_id = '';
20+
if (defined($module_constant)) {
21+
$current_version = constant($module_constant);
22+
} else {
23+
$current_version = '0.0.0';
24+
// Checking for old Existing Super Orders installtions in database
25+
$check = $db->Execute("SELECT configuration_group_id
26+
FROM " . TABLE_CONFIGURATION_GROUP . "
27+
WHERE configuration_group_title = '" . $module_name . "'");
28+
if ($check->RecordCount() < 0) {
29+
$db->Execute("INSERT INTO " . TABLE_CONFIGURATION_GROUP . " (configuration_group_title, configuration_group_description, sort_order, visible)
30+
VALUES ('" . $module_name . "', '" . $module_name . " Settings', '1', '1');");
31+
$configuration_group_id = $db->Insert_ID();
32+
} else {
33+
$configuration_group_id = $check->fields['configuration_group_id'];
34+
}
2935
$db->Execute("UPDATE " . TABLE_CONFIGURATION_GROUP . "
3036
SET sort_order = " . $configuration_group_id . "
3137
WHERE configuration_group_id = " . $configuration_group_id . ";");
@@ -42,14 +48,14 @@
4248
$installers = scandir($module_installer_directory, 1);
4349

4450
$newest_version = $installers[0];
45-
$newest_version = substr($newest_version, 0 - 4);
51+
$newest_version = substr($newest_version, 0, -4);
4652

4753
sort($installers);
4854
if (version_compare($newest_version, $current_version) > 0) {
4955
foreach ($installers as $installer) {
50-
if (version_compare($newest_version, substr($installer, 0, - 4)) >= 0 && version_compare($current_version, substr($installer, 0, - 4)) < 0) {
56+
if (version_compare($newest_version, substr($installer, 0, -4)) >= 0 && version_compare($current_version, substr($installer, 0, -4)) < 0) {
5157
include($module_installer_directory . '/' . $installer);
52-
$current_version = str_replace('_', '.', substr($installer, 0, - 4));
58+
$current_version = str_replace('_', '.', substr($installer, 0, -4));
5359
$db->Execute("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = '" . $current_version . "' WHERE configuration_key = '" . $module_constant . "' LIMIT 1;");
5460
$messageStack->add("Installed " . $module_name . " v" . $current_version, 'success');
5561
}

0 commit comments

Comments
 (0)