-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.combodo-views.php
More file actions
122 lines (110 loc) · 2.86 KB
/
module.combodo-views.php
File metadata and controls
122 lines (110 loc) · 2.86 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
<?php
//
// iTop module definition file
//
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'combodo-views/1.0.1',
array(
// Identification
//
'label' => 'Views management',
'category' => 'business',
// Setup
//
'dependencies' => array(
),
'mandatory' => false,
'visible' => true,
'installer' => 'CombodoViewsInstaller',
// Components
//
'datamodel' => array(
),
'webservice' => array(
),
'data.struct' => array(
// add your 'structure' definition XML files here,
),
'data.sample' => array(
// add your sample data XML files here,
),
// Documentation
//
'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
'doc.more_information' => '', // hyperlink to more information, if any
// Default settings
//
'settings' => array(
// Module specific settings go here, if any
),
)
);
if (!class_exists('CombodoViewsInstaller'))
{
// Module installation handler
//
class CombodoViewsInstaller extends ModuleInstallerAPI
{
public static function AfterDatabaseSetup(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
{
SetupLog::Info("Create default views");
$aMessages = array();
$aSugFix = array();
// Reporting views (must be created after any other table)
//
foreach (MetaModel::GetClasses('bizmodel') as $sClass)
{
$sView = MetaModel::DBGetView($sClass);
// Create the view
//
$oFilter = new DBObjectSearch($sClass, '');
$oFilter->AllowAllData();
$sSQL = $oFilter->MakeSelectQuery();
// N°3431 - Need to remove class name from attribute alias to conform with 2.6 style
$aSQL = preg_split("@\n@", $sSQL);
$aResult = [];
$sState = 'start';
foreach ($aSQL as $sLine) {
$sLine = trim($sLine);
switch ($sState) {
case 'start':
if ($sLine == 'SELECT') {
$aResult[] = $sLine;
$sState = 'select';
}
break;
case 'select':
if ($sLine == 'FROM') {
$aResult[] = $sLine;
$sState = 'end';
} else {
if (preg_match("@^(?<left>.*) AS `{$sClass}(?<right>.*)`(?<sep>,?)$@", $sLine, $aMatches)) {
$sOldStyle = $aMatches['left'].' AS `'.$aMatches['right'].'`'.$aMatches['sep'];
$aResult[] = $sOldStyle;
} else {
$aResult[] = $sLine;
}
}
break;
case 'end':
$aResult[] = $sLine;
break;
}
}
$sSQL = implode(" ", $aResult);
$aMessages[$sClass] = "Creating view for class: $sClass";
$aSugFix[$sClass][] = "DROP VIEW IF EXISTS `$sView`";
$aSugFix[$sClass][] = "CREATE VIEW `$sView` AS $sSQL";
}
foreach ($aSugFix as $sClass => $aQueries)
{
SetupLog::Info($aMessages[$sClass]);
foreach ($aQueries as $sQuery)
{
CMDBSource::Query($sQuery);
}
}
}
}
}