Skip to content

Commit

Permalink
Records the (emulated?) SMF version that a package was installed for
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Jul 3, 2024
1 parent 32b1fba commit 4106f7a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 12 deletions.
55 changes: 43 additions & 12 deletions Sources/PackageManager/PackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,12 @@ public function install(): void
Db::$db->query(
'',
'UPDATE {db_prefix}log_packages
SET install_state = {int:not_installed}, member_removed = {string:member_name},
id_member_removed = {int:current_member}, time_removed = {int:current_time}, sha256_hash = {string:package_hash}
SET
install_state = {int:not_installed},
member_removed = {string:member_name},
id_member_removed = {int:current_member},
time_removed = {int:current_time},
sha256_hash = {string:package_hash}
WHERE package_id = {string:package_id}
AND id_install = {int:install_id}',
[
Expand All @@ -1253,8 +1257,12 @@ public function install(): void
Db::$db->query(
'',
'UPDATE {db_prefix}log_packages
SET install_state = {int:not_installed}, member_removed = {string:member_name},
id_member_removed = {int:current_member}, time_removed = {int:current_time}, sha256_hash = {string:package_hash}
SET
install_state = {int:not_installed},
member_removed = {string:member_name},
id_member_removed = {int:current_member},
time_removed = {int:current_time},
sha256_hash = {string:package_hash}
WHERE package_id = {string:package_id}
AND version = {string:old_version}',
[
Expand Down Expand Up @@ -1322,21 +1330,44 @@ public function install(): void

// Credits tag?
$credits_tag = (empty($credits_tag)) ? '' : Utils::jsonEncode($credits_tag);

// Log that we installed it.
Db::$db->insert(
'',
'{db_prefix}log_packages',
[
'filename' => 'string', 'name' => 'string', 'package_id' => 'string', 'version' => 'string',
'id_member_installed' => 'int', 'member_installed' => 'string', 'time_installed' => 'int',
'install_state' => 'int', 'failed_steps' => 'string', 'themes_installed' => 'string',
'member_removed' => 'int', 'db_changes' => 'string', 'credits' => 'string',
'filename' => 'string',
'name' => 'string',
'package_id' => 'string',
'version' => 'string',
'id_member_installed' => 'int',
'member_installed' => 'string',
'time_installed' => 'int',
'install_state' => 'int',
'failed_steps' => 'string',
'themes_installed' => 'string',
'member_removed' => 'int',
'db_changes' => 'string',
'credits' => 'string',
'sha256_hash' => 'string',
'smf_version' => 'string',
],
[
$package_filename, $package_name, $package_id, $package_version,
User::$me->id, User::$me->name, time(),
$is_upgrade ? 2 : 1, $failed_step_insert, $themes_installed,
0, $db_changes, $credits_tag, Utils::$context['package_sha256_hash'],
$package_filename,
$package_name,
$package_id,
$package_version,
User::$me->id,
User::$me->name,
time(),
$is_upgrade ? 2 : 1,
$failed_step_insert,
$themes_installed,
0,
$db_changes,
$credits_tag,
Utils::$context['package_sha256_hash'],
Utils::$context['smf_version'],
],
['id_install'],
);
Expand Down
3 changes: 3 additions & 0 deletions Sources/PackageManager/SubsPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ public static function parsePackageInfo(XmlArray &$packageXML, bool $testing_onl
return [];
}

// Keep track of what version of SMF we are emulating (if any).
Utils::$context['smf_version'] = preg_replace('/^(\d+\.\d+).*/', '$1', $the_version);

// Find all the actions in this method - in theory, these should only be allowed actions. (* means all.)
$actions = $script->set('*');
$return = [];
Expand Down
1 change: 1 addition & 0 deletions other/install_3-0_MySQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ CREATE TABLE {$db_prefix}log_packages (
db_changes TEXT NOT NULL,
credits TEXT NOT NULL,
sha256_hash TEXT,
smf_version VARCHAR(16) NOT NULL DEFAULT '',
PRIMARY KEY (id_install),
INDEX idx_filename (filename(15))
) ENGINE={$engine};
Expand Down
1 change: 1 addition & 0 deletions other/install_3-0_PostgreSQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ CREATE TABLE {$db_prefix}log_packages (
db_changes text NOT NULL,
credits text NOT NULL,
sha256_hash TEXT,
smf_version varchar(16) NOT NULL DEFAULT '',
PRIMARY KEY (id_install)
);

Expand Down
9 changes: 9 additions & 0 deletions other/upgrade_3-0_MySQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -968,4 +968,13 @@ Db::$db->add_index(

---# Adding new "spoofdetector_censor" setting
INSERT IGNORE INTO {$db_prefix}settings (variable, value) VALUES ('spoofdetector_censor', '1');
---#

/******************************************************************************/
--- Adding SMF version information to log_packages
/******************************************************************************/

---# Adding a new column "smf_version" to log_packages table
ALTER TABLE {$db_prefix}log_packages
ADD COLUMN smf_version VARCHAR(16) NOT NULL DEFAULT '';
---#
9 changes: 9 additions & 0 deletions other/upgrade_3-0_PostgreSQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,13 @@ CREATE INDEX {$db_prefix}idx_spoofdetector_name_id ON {$db_prefix}members (spoof

---# Adding new "spoofdetector_censor" setting
INSERT INTO {$db_prefix}settings (variable, value) VALUES ('spoofdetector_censor', '1') ON CONFLICT DO NOTHING;
---#

/******************************************************************************/
--- Adding SMF version information to log_packages
/******************************************************************************/

---# Adding a new column "smf_version" to log_packages table
ALTER TABLE {$db_prefix}log_packages
ADD COLUMN IF NOT EXISTS smf_version VARCHAR(16) NOT NULL DEFAULT '';
---#

0 comments on commit 4106f7a

Please sign in to comment.