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 foreach($res as $itemPath => $type){
115 // Make names dataModel conform
116 $itemPath = $path.preg_replace("/^\//","/root", $itemPath);
117 $name = preg_replace("/^.*\//","",$itemPath);
119 $itemPath = preg_replace("/\/[^\/]*$/","", $itemPath);
121 print_a(array($type, $itemPath, $name));
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 $item = $this->dataModel->getItemByPath($this->selectedItem);
140 session::set('CONFIG_ITEM', $item);
142 return($this->listing->renderList());
143 }
146 /*! \brief Returns a simply list of all releases of the CURRENT distribution.
147 * This list will then be used to generate the entries of the
148 * ItemSelectors in the listing class.
149 */
150 function getItemList()
151 {
152 $data = $this->dataModel->getItemByPath('/root');
153 return($this->__recurseItem($data));
154 $res = array();
155 $dist = $this->selectedContainer;
156 $list = $this->dataModel->getItemsByType('Release');
157 foreach($list as $base => $entry){
158 if($entry['parentPath'] != $dist) continue;
159 $res[$entry['path']] = $entry['name'];
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 return($this->__recurseItem($data));
175 $list = $this->dataModel->getItemsByType('Distribution');
176 $res = array();
177 foreach($list as $base => $entry){
178 $res[$entry['path']] = $entry['name'];
179 }
180 return($res);
181 }
184 function __recurseItem($item)
185 {
186 $res = array();
187 $res[$item['path']] = $item['type'];
188 if(count($item['children'])){
189 foreach($item['children'] as $child){
190 $res = array_merge($res, $this->__recurseItem($child));
191 }
192 }
193 return($res);
194 }
198 function remove_lock()
199 {
200 }
203 /*! \brief Intializes this plugin
204 * All available installation methods will be loaded
205 */
206 function loadInstallationMethods()
207 {
208 // Reset erros
209 $this->rpcError = $this->initFailed = FALSE;
211 // Load configuration via rpc.
212 $rpc = $this->config->getRpcHandle();
214 // Populate install methods on success.
215 $res = $rpc->getSupportedInstallMethods();
216 if(!$rpc->success()){
217 $this->rpcError = TRUE;
218 $this->errorMessage = $rpc->get_error();;
219 return;
220 }
221 $this->installationMethods = $res;
222 if(!count($this->installationMethods)){
223 $this->errorMessage = _("No selectable install methods returned!");
224 msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
225 $this->initFailed = TRUE;
226 return;
227 }
228 }
231 public static function plInfo()
232 {
233 return (array(
234 "plShortName" => _("Config management"),
235 "plDescription" => _("Config management"),
236 "plSelfModify" => FALSE,
237 "plDepends" => array(),
238 "plPriority" => 0,
239 "plSection" => array("administration"),
240 "plCategory" => array(
241 "newConfigManagement" => array("description" => _("Config management"),
242 "objectClass" => "FAKE_OC_newConfigManagement")),
243 "plProvidedAcls"=> array()
244 ));
245 }
246 }
247 ?>