1 <?php
3 class newConfigManagement extends plugin
4 {
5 var $initTime;
6 var $plHeadline = "Config management";
7 var $plDescription = "Config management";
9 var $selectedDistribution;
10 var $selectedRelease;
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);
46 // Load the releases for the current distribution
47 $releases = $rpc->getReleases($dist);
48 if(!$rpc->success()){
49 msg_dialog::display(_("Error"), sprintf(_("Failed to load releases, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
50 return(NULL);
51 }
52 foreach($releases as $release){
53 $this->dataModel->addItem('Release',"/root/{$dist}", $release);
55 // Load packages
56 $packages = $rpc->getPackages($release);
57 if(!$rpc->success()){
58 msg_dialog::display(_("Error"), sprintf(_("Failed to load packages, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
59 return(NULL);
60 }
61 foreach($packages as $package){
62 $this->dataModel->addItem('Package',"/root/{$dist}/{$release}", $package['name'], $package);
63 }
65 // Load items
66 $items = $rpc->listConfigItems($release);
67 if(!$rpc->success()){
68 msg_dialog::display(_("Error"), sprintf(_("Failed to load items, error was '%s'!"), $rpc->get_error()),ERROR_DIALOG);
69 return(NULL);
70 }
71 foreach($items as $package){
72 $this->dataModel->addItem('Item',"/root/{$dist}/{$release}", $package['name'], $package);
73 }
74 }
75 }
77 }
80 /*! \brief Keep track of posted values and populate those
81 * which are interesting for us.
82 * Inspects the _POST and _GET values.
83 */
84 function save_object()
85 {
86 // Update the listing class, this is necessary to get post
87 // actions from it.
88 $this->listing->save_object();
90 // Get the selected distribution and release from the listing widget.
91 $this->selectedDistribution = $this->listing->getSelectedDistribution();
92 $this->selectedRelease = $this->listing->getSelectedRelease();
94 // Get a list of all available distributions and releases.
95 $distList = $this->getDistList();
96 $releaseList = $this->getReleaseList();
98 // Ensure that we've valid values selected.
99 if(!isset($releaseList[$this->selectedRelease])){
100 if(count($releaseList)){
101 $this->selectedRelease = key($releaseList);
102 }else{
103 $this->selectedRelease = "";
104 }
105 }
107 // Transfer checked values back to the listing class.
108 $this->listing->setDistribution($this->selectedDistribution);
109 $this->listing->setRelease($this->selectedRelease);
110 $this->listing->setDistributions($this->getDistList());
111 $this->listing->setReleases($this->getReleaseList());
112 }
115 /*! \brief Generate the HTML content for this plugin.
116 * Actually renders the listing widget..
117 */
118 function execute()
119 {
120 // Get the selected release and store it in a session variable
121 // to allow the configFilter to access it and display the
122 // packages and items.
123 $item = $this->dataModel->getItemByPath($this->selectedRelease);
124 print_a($item);
126 return($this->listing->renderList());
127 }
130 /*! \brief Returns a simply list of all releases of the CURRENT distribution.
131 * This list will then be used to generate the entries of the
132 * ItemSelectors in the listing class.
133 */
134 function getReleaseList()
135 {
136 $res = array();
137 $dist = $this->selectedDistribution;
138 $list = $this->dataModel->getItemsByType('Release');
139 foreach($list as $base => $entry){
140 if($entry['parentPath'] != $dist) continue;
141 $res[$entry['path']] = $entry['name'];
142 }
143 return($res);
144 }
147 /*! \brief Returns a simply list of all distributions.
148 * This list will then be used to generate the entries of the
149 * ItemSelectors in the listing class.
150 */
151 function getDistList()
152 {
153 $list = $this->dataModel->getItemsByType('Distribution');
154 $res = array();
155 foreach($list as $base => $entry){
156 $res[$entry['path']] = $entry['name'];
157 }
158 return($res);
159 }
162 function remove_lock()
163 {
164 }
167 /*! \brief Intializes this plugin
168 * All available installation methods will be loaded
169 */
170 function loadInstallationMethods()
171 {
172 // Reset erros
173 $this->rpcError = $this->initFailed = FALSE;
175 // Load configuration via rpc.
176 $rpc = $this->config->getRpcHandle();
178 // Populate install methods on success.
179 $res = $rpc->getSupportedInstallMethods();
180 if(!$rpc->success()){
181 $this->rpcError = TRUE;
182 $this->errorMessage = $rpc->get_error();;
183 return;
184 }
185 $this->installationMethods = $res;
186 if(!count($this->installationMethods)){
187 $this->errorMessage = _("No selectable install methods returned!");
188 msg_dialog::display(_("Setup"), $this->errorMessage , ERROR_DIALOG);
189 $this->initFailed = TRUE;
190 return;
191 }
192 }
195 public static function plInfo()
196 {
197 return (array(
198 "plShortName" => _("Config management"),
199 "plDescription" => _("Config management"),
200 "plSelfModify" => FALSE,
201 "plDepends" => array(),
202 "plPriority" => 0,
203 "plSection" => array("administration"),
204 "plCategory" => array(
205 "newConfigManagement" => array("description" => _("Config management"),
206 "objectClass" => "FAKE_OC_newConfigManagement")),
207 "plProvidedAcls"=> array()
208 ));
209 }
210 }
211 ?>