1 <?php
3 class newConfigManagement extends plugin
4 {
5 var $initTime;
6 var $plHeadline = "Config management";
7 var $plDescription = "Config management";
9 var $selectedContainer;
10 var $selectedItem;
12 var $dataModel = NULL;
13 var $listing = NULL;
16 /*! \brief Initialize the plugin and finally update the data model.
17 */
18 function __construct($config, $dn)
19 {
20 $this->config = &$config;
21 $this->listing = new ConfigManagementListing($this->config, get_userinfo());
23 // Request an update of the data model
24 $this->updateDataModel();
25 }
28 /*! \brief Updates all distributions, releases, packages and items in the dataModel
29 * Load information from the backend.
30 */
31 function updateDataModel()
32 {
33 // Recreate the data model, to have a clean and fresh instance.
34 $this->dataModel = new ConfigManagementDataModel();
36 // Load distributions
37 $rpc = $this->config->getRpcHandle();
38 $res = $rpc->getDistributions();
39 if(!$rpc->success()){
40 msg_dialog::display(_("Error"), sprintf(_("Failed to load distributions, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
41 return(NULL);
42 }
43 foreach($res as $dist){
44 $this->dataModel->addItem('Distribution','/root', $dist['name'], $dist);
45 foreach($dist['releases'] as $release){
46 $distPath = "/root/{$dist['name']}";
47 $this->dataModel->addItem('Release',$distPath, $release['name'], $release);
49 foreach($dist['components'] as $component){
50 $comPath = "{$distPath}/{$release['name']}";
51 $this->dataModel->addItem('Component',$comPath, $component['name'], $component);
52 }
53 }
54 }
55 }
58 /*! \brief Keep track of posted values and populate those
59 * which are interesting for us.
60 * Inspects the _POST and _GET values.
61 */
62 function save_object()
63 {
64 // Update the listing class, this is necessary to get post
65 // actions from it.
66 $this->listing->save_object();
68 // Get the selected distribution and release from the listing widget.
69 $this->selectedContainer = $this->listing->getSelectedContainer();
70 $this->selectedItem = $this->listing->getSelectedItem();
72 // Get a list of all available distributions and releases.
73 $distList = $this->getDistList();
74 $releaseList = $this->getItemList();
76 // Ensure that we've valid values selected.
77 if(!isset($releaseList[$this->selectedItem])){
78 if(count($releaseList)){
79 $this->selectedItem = key($releaseList);
80 }else{
81 $this->selectedItem = "";
82 }
83 }
85 // Update list of items within the selected container.
86 $this->updateItemList($this->selectedContainer);
88 // Transfer checked values back to the listing class.
89 $this->listing->setContainer($this->selectedContainer);
90 $this->listing->setItem($this->selectedItem);
91 $this->listing->setContainers($this->getDistList());
92 $this->listing->setItems($this->getItemList());
93 }
96 function updateItemList($path)
97 {
98 // Fist get Item and check if it is an release
99 if($this->dataModel->itemExistsByPath($path)){
100 $data = $this->dataModel->getItemByPath($path);
102 // Only releases can contain config-items.
103 if($data['type'] == 'Release' && $data['status'] != "fetched"){
105 $rpc = $this->config->getRpcHandle();
106 $res = $rpc->listConfigItems($data['name']);
107 if(!$rpc->success()){
108 msg_dialog::display(_("Error"),
109 sprintf(_("Failed to load distributions, error was '%s'!"),
110 $rpc->get_error()),ERROR_DIALOG);
111 }else{
112 $this->dataModel->setItemStatus($path, 'käse');
113 $rpc = $this->config->getRpcHandle();
114 $res = $rpc->getPackages($data['name']);
116 return;
117 foreach($res as $itemPath => $type){
119 // Make names dataModel conform
120 $itemPath = $path.'/'.preg_replace("/^\//","/root", $itemPath);
121 $name = preg_replace("/^.*\//","",$itemPath);
122 $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
123 $this->dataModel->addItem($type, $itemPath, $name);
124 }
125 }
126 }
127 }
128 }
131 /*! \brief Generate the HTML content for this plugin.
132 * Actually renders the listing widget..
133 */
134 function execute()
135 {
137 // Get the selected release and store it in a session variable
138 // to allow the configFilter to access it and display the
139 // packages and items.
140 $path = $this->selectedContainer.$this->selectedItem;
141 $item = $this->dataModel->getItemByPath($path);
142 session::set('CONFIG_ITEM', $item);
143 $this->listing->setListingTypes($this->getListingTypes());
145 return($this->listing->execute());
146 }
149 /*! \brief Returns a simply list of all releases of the CURRENT distribution.
150 * This list will then be used to generate the entries of the
151 * ItemSelectors in the listing class.
152 */
153 function getItemList()
154 {
155 $data = $this->dataModel->getItemByPath($this->selectedContainer);
156 $res = array(""=>"/");
157 if($data['type'] != 'Release'){
158 }else{
159 $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
160 }
161 return($res);
162 }
165 /*! \brief Returns a simply list of all distributions.
166 * This list will then be used to generate the entries of the
167 * ItemSelectors in the listing class.
168 */
169 function getDistList()
170 {
171 $data = $this->dataModel->getItemByPath('/root');
172 $res["/root"] = "/";
173 $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
174 return($res);
175 }
178 function __recurseItem($item, $types, $parent = "")
179 {
180 $res = array();
181 if(in_array($item['type'], $types)){
182 $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
183 $res[$path] = $item['name'];
184 }
185 if(count($item['children'])){
186 foreach($item['children'] as $child){
187 $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
188 }
189 }
190 return($res);
191 }
195 function remove_lock()
196 {
197 }
200 /*! \brief Intializes this plugin
201 * All available installation methods will be loaded
202 */
203 function loadInstallationMethods()
204 {
205 // Reset erros
206 $this->rpcError = $this->initFailed = FALSE;
208 // Load configuration via rpc.
209 $rpc = $this->config->getRpcHandle();
211 // Populate install methods on success.
212 $res = $rpc->getSupportedInstallMethods();
213 if(!$rpc->success()){
214 $this->rpcError = TRUE;
215 $this->errorMessage = $rpc->get_error();;
216 return;
217 }
218 $this->installationMethods = $res;
219 if(!count($this->installationMethods)){
220 $this->errorMessage = _("No selectable install methods returned!");
221 msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
222 $this->initFailed = TRUE;
223 return;
224 }
225 }
228 function getListingTypes()
229 {
230 $types= array();
231 $types['Distribution']['objectClass'] = 'Distribution';
232 $types['Distribution']['label'] = _('Distribution');
233 $types['Distribution']['image'] = 'images/lists/edit.png';
234 $types['Distribution']['category'] = 'Device';
235 $types['Distribution']['class'] = 'Device';
237 $types['Release']['objectClass'] = 'Release';
238 $types['Release']['label'] = _('Release');
239 $types['Release']['image'] = 'images/lists/delete.png';
240 $types['Release']['category'] = 'Device';
241 $types['Release']['class'] = 'Device';
243 $types['Component']['objectClass'] = 'Component';
244 $types['Component']['label'] = _('Component');
245 $types['Component']['image'] = 'images/lists/edit.png';
246 $types['Component']['category'] = 'Device';
247 $types['Component']['class'] = 'Device';
248 return($types);
249 }
252 public static function plInfo()
253 {
254 return (array(
255 "plShortName" => _("Config management"),
256 "plDescription" => _("Config management"),
257 "plSelfModify" => FALSE,
258 "plDepends" => array(),
259 "plPriority" => 0,
260 "plSection" => array("administration"),
261 "plCategory" => array(
262 "newConfigManagement" => array("description" => _("Config management"),
263 "objectClass" => "FAKE_OC_newConfigManagement")),
264 "plProvidedAcls"=> array()
265 ));
266 }
267 }
268 ?>