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 {
136 // Get the selected release and store it in a session variable
137 // to allow the configFilter to access it and display the
138 // packages and items.
139 $path = $this->selectedContainer.$this->selectedItem;
140 $item = $this->dataModel->getItemByPath($path);
141 session::set('CONFIG_ITEM', $item);
142 $this->listing->setListingTypes($this->getListingTypes());
144 return($this->listing->renderList());
145 }
148 /*! \brief Returns a simply list of all releases of the CURRENT distribution.
149 * This list will then be used to generate the entries of the
150 * ItemSelectors in the listing class.
151 */
152 function getItemList()
153 {
154 $data = $this->dataModel->getItemByPath($this->selectedContainer);
155 $res = array(""=>"/");
156 if($data['type'] != 'Release'){
157 }else{
158 $res = array_merge($res,$this->__recurseItem($data, array('Component'),$this->selectedContainer));
159 }
160 return($res);
161 }
164 /*! \brief Returns a simply list of all distributions.
165 * This list will then be used to generate the entries of the
166 * ItemSelectors in the listing class.
167 */
168 function getDistList()
169 {
170 $data = $this->dataModel->getItemByPath('/root');
171 $res["/root"] = "/";
172 $res = array_merge($res,$this->__recurseItem($data, array('Distribution','Release')));
173 return($res);
174 }
177 function __recurseItem($item, $types, $parent = "")
178 {
179 $res = array();
180 if(in_array($item['type'], $types)){
181 $path = preg_replace("/".preg_quote($parent,'/')."/","",$item['path']);
182 $res[$path] = $item['name'];
183 }
184 if(count($item['children'])){
185 foreach($item['children'] as $child){
186 $res = array_merge($res, $this->__recurseItem($child, $types, $parent));
187 }
188 }
189 return($res);
190 }
194 function remove_lock()
195 {
196 }
199 /*! \brief Intializes this plugin
200 * All available installation methods will be loaded
201 */
202 function loadInstallationMethods()
203 {
204 // Reset erros
205 $this->rpcError = $this->initFailed = FALSE;
207 // Load configuration via rpc.
208 $rpc = $this->config->getRpcHandle();
210 // Populate install methods on success.
211 $res = $rpc->getSupportedInstallMethods();
212 if(!$rpc->success()){
213 $this->rpcError = TRUE;
214 $this->errorMessage = $rpc->get_error();;
215 return;
216 }
217 $this->installationMethods = $res;
218 if(!count($this->installationMethods)){
219 $this->errorMessage = _("No selectable install methods returned!");
220 msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
221 $this->initFailed = TRUE;
222 return;
223 }
224 }
227 function getListingTypes()
228 {
229 $types= array();
230 $types['Distribution']['objectClass'] = 'Distribution';
231 $types['Distribution']['label'] = _('Distribution');
232 $types['Distribution']['image'] = 'images/lists/edit.png';
233 $types['Distribution']['category'] = 'Device';
234 $types['Distribution']['class'] = 'Device';
236 $types['Release']['objectClass'] = 'Release';
237 $types['Release']['label'] = _('Release');
238 $types['Release']['image'] = 'images/lists/edit.png';
239 $types['Release']['category'] = 'Device';
240 $types['Release']['class'] = 'Device';
241 return($types);
242 }
245 public static function plInfo()
246 {
247 return (array(
248 "plShortName" => _("Config management"),
249 "plDescription" => _("Config management"),
250 "plSelfModify" => FALSE,
251 "plDepends" => array(),
252 "plPriority" => 0,
253 "plSection" => array("administration"),
254 "plCategory" => array(
255 "newConfigManagement" => array("description" => _("Config management"),
256 "objectClass" => "FAKE_OC_newConfigManagement")),
257 "plProvidedAcls"=> array()
258 ));
259 }
260 }
261 ?>