Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
175 lines (156 loc) · 6.42 KB
/
Copy pathsetup.php
File metadata and controls
175 lines (156 loc) · 6.42 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* -------------------------------------------------------------------------
* Assetmove plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Assetmove.
*
* Assetmove is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Assetmove is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Assetmove. If not, see <https://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
*/
use GlpiPlugin\Assetmove\ApprovalStep;
use GlpiPlugin\Assetmove\Config;
use GlpiPlugin\Assetmove\DocType;
use GlpiPlugin\Assetmove\Document_Item;
use GlpiPlugin\Assetmove\Engine\AssetTypes;
use GlpiPlugin\Assetmove\Hook\OrderListener;
use GlpiPlugin\Assetmove\Movement;
use GlpiPlugin\Assetmove\Profile;
use GlpiPlugin\Assetmove\Validation;
use GlpiPlugin\Assetmove\Warehouse;
use GlpiPlugin\Assetmove\Writeoff;
define('PLUGIN_ASSETMOVE_VERSION', '0.1.0');
// Minimal GLPI version, inclusive
define('PLUGIN_ASSETMOVE_MIN_GLPI', '11.0.0');
// Maximum GLPI version, exclusive
define('PLUGIN_ASSETMOVE_MAX_GLPI', '11.0.99');
/**
* Init hooks of the plugin.
* REQUIRED
*
* @return void
*/
function plugin_init_assetmove()
{
/** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;
/** @var array $CFG_GLPI */
global $CFG_GLPI;
$PLUGIN_HOOKS['csrf_compliant']['assetmove'] = true;
if (!Plugin::isPluginActive('assetmove')) {
return;
}
// DbUtils::getItemTypeForTable() guesses the itemtype back from a table
// name by singularizing it with a fixed set of regex rules that has no
// notion of "warehouse" (its `uses$ -> us` rule, meant for
// status/es-like words, wrongly strips "warehouses" down to "warehous")
// -- the same class of problem the core `releases` marketplace plugin
// hits and fixes the same way (see its own setup.php). Without this,
// Search::show() on Warehouse's list (front/warehouse.php) fatals in
// Glpi\Search\Provider\SQLProvider::giveItem() trying to call a method
// on a null itemtype for the "itemlink" name column.
// `movements_items` (Document_Item, a relation table, not a plain
// pluralized class name) hits the same gap for the same reason.
$CFG_GLPI['glpiitemtypetables']['glpi_plugin_assetmove_warehouses'] = Warehouse::class;
$CFG_GLPI['glpiitemtypetables']['glpi_plugin_assetmove_movements_items'] = Document_Item::class;
$PLUGIN_HOOKS['change_profile']['assetmove'] = [Profile::class, 'changeProfile'];
$PLUGIN_HOOKS['config_page']['assetmove'] = 'front/config.form.php';
Plugin::registerClass(Profile::class, ['addtabon' => ['Profile']]);
Plugin::registerClass(ApprovalStep::class, ['addtabon' => [DocType::class]]);
// TZ 12.3 (items tab on the document itself) and TZ 12.4 (history tab on
// the asset it references) are the same tab class, branching on which
// side it is shown on -- see Document_Item::getTabNameForItem().
Plugin::registerClass(Document_Item::class, [
'addtabon' => array_merge([Movement::class, Writeoff::class], AssetTypes::getMovableTypes()),
]);
Plugin::registerClass(Validation::class, ['addtabon' => [Movement::class, Writeoff::class]]);
$PLUGIN_HOOKS['menu_toadd']['assetmove'] = [
'config' => [DocType::class, Warehouse::class, Config::class],
'management' => [Movement::class, Writeoff::class],
];
$PLUGIN_HOOKS['use_massive_action']['assetmove'] = 1;
// TZ 10.2: only wired when Order is actually active, and every further
// read of Order's data goes through Integration\OrderAdapter -- never
// a `use PluginOrder...;` here or in OrderListener -- so disabling
// Order can never fatal this plugin.
if (Plugin::isPluginActive('order') && class_exists('PluginOrderOrder_Item')) {
$PLUGIN_HOOKS['item_update']['assetmove']['PluginOrderOrder_Item'] = [OrderListener::class, 'onOrderItemUpdate'];
$PLUGIN_HOOKS['pre_item_purge']['assetmove']['PluginOrderOrder_Item'] = [OrderListener::class, 'onOrderItemPurge'];
}
// TZ 10.7: opt-in fallback (Config::is_infocom_fallback_active, off by
// default) for sites that record a supplier on Infocom without using
// Order at all. Registered unconditionally -- Infocom is core -- the
// config flag is what actually gates it.
$PLUGIN_HOOKS['item_add']['assetmove']['Infocom'] = [OrderListener::class, 'onInfocomChange'];
$PLUGIN_HOOKS['item_update']['assetmove']['Infocom'] = [OrderListener::class, 'onInfocomChange'];
// No registration needed for plugin_assetmove_addDefaultWhere(): core
// calls it automatically for any itemtype belonging to this plugin
// (Glpi\Search\Provider\SQLProvider::getDefaultWhereCriteria() ->
// Plugin::doOneHook($plugin, Hooks::AUTO_ADD_DEFAULT_WHERE, $itemtype),
// unconditionally, not gated by a $PLUGIN_HOOKS entry).
}
/**
* Get the name and the version of the plugin.
* REQUIRED
*
* @return array
*/
function plugin_version_assetmove()
{
return [
'name' => __('Asset movements', 'assetmove'),
'version' => PLUGIN_ASSETMOVE_VERSION,
'author' => 'Assetmove authors',
'license' => 'GPL-3.0-only',
'homepage' => '',
'requirements' => [
'glpi' => [
'min' => PLUGIN_ASSETMOVE_MIN_GLPI,
'max' => PLUGIN_ASSETMOVE_MAX_GLPI,
],
'php' => [
'min' => '8.2',
],
],
];
}
/**
* Check pre-requisites before install.
* OPTIONAL
*
* @return boolean
*/
function plugin_assetmove_check_prerequisites()
{
if (version_compare(PHP_VERSION, '8.2', '<')) {
echo 'This plugin requires PHP >= 8.2';
return false;
}
return true;
}
/**
* Check configuration process.
* OPTIONAL
*
* @param boolean $verbose Whether to display message on failure
*
* @return boolean
*/
function plugin_assetmove_check_config($verbose = false)
{
return true;
}