-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhook.php
122 lines (103 loc) · 4.64 KB
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* @package encryptfile
* @author Charlene Auger
* @copyright Copyright (c) 2015-2023 FactorFX
* @license AGPL License 3.0 or (at your option) any later version
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* @link https://www.factorfx.com
* @since 2023
*
* --------------------------------------------------------------------------
*/
/**
* plugin_encryptfile_install
*
* @return void
*/
function plugin_encryptfile_install() {
global $DB;
$migration = new Migration(100);
// Create configuration table
if(!$DB->tableExists("glpi_plugin_encryptfile_configs")) {
$query = "CREATE TABLE `glpi_plugin_encryptfile_configs` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`status` BOOLEAN NOT NULL DEFAULT 0,
`comment` VARCHAR(255) DEFAULT NULL,
`profiles_id` INT(11) NOT NULL DEFAULT 0,
`key` TEXT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "Create configuration table for Encrypted file plugin");
}
// Create profile table
if(!$DB->tableExists("glpi_plugin_encryptfile_profiles")) {
$query = "CREATE TABLE `glpi_plugin_encryptfile_profiles` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`keys_id` INT(11) NOT NULL DEFAULT 0,
`profiles_id` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "Create profile table for Encrypted file plugin");
}
// Create item table
if(!$DB->tableExists("glpi_plugin_encryptfile_items")) {
$query = "CREATE TABLE `glpi_plugin_encryptfile_items` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`keys_id` INT(11) NOT NULL DEFAULT 0,
`itemtype` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "Create item table for Encrypted file plugin");
}
if(!$DB->tableExists("glpi_plugin_encryptfile_documents")) {
$query = "CREATE TABLE `glpi_plugin_encryptfile_documents` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`keys_id` INT(11) NOT NULL DEFAULT 0,
`documents_id` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "Create item table for Encrypted file plugin");
}
if(!$DB->tableExists("glpi_plugin_encryptfile_formcreator")) {
$query = "CREATE TABLE `glpi_plugin_encryptfile_formcreator` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`keys_id` INT(11) NOT NULL DEFAULT 0,
`forms_id` INT(11) NOT NULL DEFAULT 0,
`sections_id` INT(11) NOT NULL DEFAULT 0,
`questions_id` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";
$DB->queryOrDie($query, "Create item table for Encrypted file plugin");
}
$migration->executeMigration();
return true;
}
/**
* plugin_encryptfile_uninstall
*
* @return void
*/
function plugin_encryptfile_uninstall() {
global $DB;
$pluginEncryptfileConfigs = new PluginEncryptfileConfig();
$associatedDocuments = $pluginEncryptfileConfigs->getAllAssociatedDocument(0, true, true);
if(empty($associatedDocuments)) {
$queries = [
"glpi_plugin_encryptfile_configs" => "DROP TABLE IF EXISTS `glpi_plugin_encryptfile_configs`;",
"glpi_plugin_encryptfile_profiles" => "DROP TABLE IF EXISTS `glpi_plugin_encryptfile_profiles`;",
"glpi_plugin_encryptfile_items" => "DROP TABLE IF EXISTS `glpi_plugin_encryptfile_items`;",
"glpi_plugin_encryptfile_documents" => "DROP TABLE IF EXISTS `glpi_plugin_encryptfile_documents`;",
"glpi_plugin_encryptfile_formcreator" => "DROP TABLE IF EXISTS `glpi_plugin_encryptfile_formcreator`;"
];
foreach($queries as $table => $query) $DB->queryOrDie($query, "Drop table ".$table);
return true;
} else {
// Disable all key
$query = "UPDATE `glpi_plugin_encryptfile_configs` SET `status` = 0 WHERE 1";
$DB->queryOrDie($query, "Disable all encrypt keys");
Session::addMessageAfterRedirect(__("Unable to drop encryptfile tables because there are still documents associated with the keys", "encryptfile"), true, ERROR);
return false;
}
}