mirror of
https://github.com/itflow-org/itflow
synced 2026-11-12 23:47:23 +00:00
Vendor templates stage 1: Admin > Vendor Templates rebuilt on the standard list with Active and Archived tabs, support line, hours and SLA, how many clients have a vendor from each, last used and changed by, sortable and searchable including by support line; new template page with what a vendor starts with, the clients with it and their account numbers, the license templates that use it, made and changed by, and history; shared New/Edit window on the vendor window's tabs with per-field push to the vendors made from it, each logged on the vendor; copy, archive, restore and delete with vendors and license templates unlinked on delete; Make a template from a client's vendor, linking the vendor to it, and the vendor page linking its template for admins; Delete offered to every admin role, not only the built-in Administrator; the admin handler no longer includes the agent vendor handler; database 3.3.4 adds vendor_template_created_by and vendor_template_updated_by, backfilled from the audit log
This commit is contained in:
56
admin/database_updates/3.3.3.php
Normal file
56
admin/database_updates/3.3.3.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 3.3.3 (from 3.3.2)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// App logs, retention and forwarding (functions/app_log.php, functions/log_forward.php).
|
||||
//
|
||||
// Each step checks first, so it can run again.
|
||||
$itflow_has_column = function ($column) use ($mysqli) {
|
||||
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'settings' AND COLUMN_NAME = '" . mysqli_real_escape_string($mysqli, $column) . "' LIMIT 1");
|
||||
return $result && mysqli_num_rows($result) > 0;
|
||||
};
|
||||
|
||||
// 1. The app logs are kept for their own number of days, starting from
|
||||
// what the audit log keeps, as both were kept for that until now. For
|
||||
// both, 0 is now keep forever.
|
||||
if (!$itflow_has_column('config_app_log_retention')) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` ADD COLUMN `config_app_log_retention` int(11) NOT NULL DEFAULT 90");
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_app_log_retention` = `config_log_retention`");
|
||||
}
|
||||
|
||||
// 2. Sending log entries on to a syslog server or SIEM as they are
|
||||
// written: on or off, where to (host, port, and UDP, TCP or TLS), how
|
||||
// (JSON, CEF or plain text), what (the audit log, and the app logs from
|
||||
// a level up - '' for none) and, over TLS, whether the server's
|
||||
// certificate is checked.
|
||||
$itflow_columns = [
|
||||
'config_log_forward_enabled' => "tinyint(1) NOT NULL DEFAULT 0",
|
||||
'config_log_forward_host' => "varchar(200) DEFAULT NULL",
|
||||
'config_log_forward_port' => "int(11) NOT NULL DEFAULT 514",
|
||||
'config_log_forward_protocol' => "varchar(10) NOT NULL DEFAULT 'udp'",
|
||||
'config_log_forward_format' => "varchar(10) NOT NULL DEFAULT 'json'",
|
||||
'config_log_forward_audit' => "tinyint(1) NOT NULL DEFAULT 1",
|
||||
'config_log_forward_app_level' => "varchar(10) NOT NULL DEFAULT 'warning'",
|
||||
'config_log_forward_tls_verify' => "tinyint(1) NOT NULL DEFAULT 1",
|
||||
];
|
||||
foreach ($itflow_columns as $itflow_column => $itflow_definition) {
|
||||
if (!$itflow_has_column($itflow_column)) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `settings` ADD COLUMN `$itflow_column` $itflow_definition");
|
||||
}
|
||||
}
|
||||
|
||||
// 3. The app logs are listed and cleared by date, and nightly deletes the
|
||||
// old ones by date - a key on it.
|
||||
$itflow_index = mysqli_query($mysqli, "SELECT 1 FROM information_schema.STATISTICS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'app_logs' AND INDEX_NAME = 'app_log_created_at' LIMIT 1");
|
||||
if (!$itflow_index || mysqli_num_rows($itflow_index) === 0) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `app_logs` ADD KEY `app_log_created_at` (`app_log_created_at`)");
|
||||
}
|
||||
|
||||
unset($itflow_has_column, $itflow_columns, $itflow_column, $itflow_definition, $itflow_index);
|
||||
37
admin/database_updates/3.3.4.php
Normal file
37
admin/database_updates/3.3.4.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 3.3.4 (from 3.3.3)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// Vendor templates (functions/vendor_template.php).
|
||||
//
|
||||
// 1. Who made a vendor template and who last changed it. Checked first, so
|
||||
// the step can run again.
|
||||
$itflow_column = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'vendor_templates' AND COLUMN_NAME = 'vendor_template_created_by' LIMIT 1");
|
||||
if (!$itflow_column || mysqli_num_rows($itflow_column) === 0) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `vendor_templates`
|
||||
ADD `vendor_template_created_by` int(11) NOT NULL DEFAULT 0 AFTER `vendor_template_archived_at`,
|
||||
ADD `vendor_template_updated_by` int(11) NOT NULL DEFAULT 0 AFTER `vendor_template_created_by`");
|
||||
}
|
||||
|
||||
// 2. ...taken from the audit log where it has a record of it - the first
|
||||
// Create on the template and the latest Edit. Not counted as a change.
|
||||
mysqli_query($mysqli, "UPDATE `vendor_templates` JOIN (
|
||||
SELECT `log_entity_id`, SUBSTRING_INDEX(GROUP_CONCAT(`log_user_id` ORDER BY `log_id` ASC), ',', 1) AS `user_id`
|
||||
FROM `logs` WHERE `log_type` = 'Vendor Template' AND `log_action` = 'Create' AND `log_entity_id` > 0 AND `log_user_id` > 0 GROUP BY `log_entity_id`
|
||||
) AS `made` ON `made`.`log_entity_id` = `vendor_templates`.`vendor_template_id`
|
||||
SET `vendor_template_created_by` = `made`.`user_id`, `vendor_template_updated_at` = `vendor_template_updated_at`
|
||||
WHERE `vendor_template_created_by` = 0");
|
||||
mysqli_query($mysqli, "UPDATE `vendor_templates` JOIN (
|
||||
SELECT `log_entity_id`, SUBSTRING_INDEX(GROUP_CONCAT(`log_user_id` ORDER BY `log_id` DESC), ',', 1) AS `user_id`
|
||||
FROM `logs` WHERE `log_type` = 'Vendor Template' AND `log_action` = 'Edit' AND `log_entity_id` > 0 AND `log_user_id` > 0 GROUP BY `log_entity_id`
|
||||
) AS `changed` ON `changed`.`log_entity_id` = `vendor_templates`.`vendor_template_id`
|
||||
SET `vendor_template_updated_by` = `changed`.`user_id`, `vendor_template_updated_at` = `vendor_template_updated_at`
|
||||
WHERE `vendor_template_updated_by` = 0 AND `vendor_template_updated_at` IS NOT NULL");
|
||||
|
||||
unset($itflow_column);
|
||||
Reference in New Issue
Block a user