demo: simplify demoreload.sh
[racktables-contribs] / mh_autofill_object_values.php
CommitLineData
d0cbb3cd
JV
1<?php
2// NOTE: Requires RackTables v0.20.14 or greater
3
4registerHook ('commitUpdateObjectAfter_hook', 'demo_commitUpdateObjectAfter_hook');
5
6function demo_commitUpdateObjectAfter_hook ($object_id)
7{
8 static $in_function;
9 if ($in_function)
10 {
11 return; // Prevent endless recursion
12 }
13 $in_function = true;
14 $object = spotEntity ('object', $object_id, true);
15 if
16 (
17 4 == $object['objtype_id'] && // 4 = Server
18 !empty ($object['name'])
19 )
20 {
21 if ( empty($attrs[3]['value']) ) // 3 = FQDN
22 {
23 commitUpdateAttrValue
24 (
25 $object_id,
26 3,
27 strtolower($object['name']).'.example.com'
28 );
29 }
30 if ( empty ($object['asset_no']) )
31 {
32 $object['asset_no'] = $object['name'];
33 commitUpdateObject // Recursion
34 (
35 $object['id'],
36 $object['name'],
37 $object['label'],
38 $object['has_problems'],
39 $object['asset_no'],
40 $object['comment']
41 );
42 }
43 }
44 $in_function = false;
45}