| | 92 | function doReload() { |
|---|
| | 93 | $result = do_reload(); |
|---|
| | 94 | |
|---|
| | 95 | if ($result['status'] != true) { |
|---|
| | 96 | out("Error(s) have occured, the following is the retrieve_conf output:"); |
|---|
| | 97 | $retrieve_array = explode('<br/>',$result['retrieve_conf']); |
|---|
| | 98 | foreach ($retrieve_array as $line) { |
|---|
| | 99 | out($line); |
|---|
| | 100 | }; |
|---|
| | 101 | } else { |
|---|
| | 102 | out($result['message']); |
|---|
| | 103 | } |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | function doDisable($modulename, $force) { |
|---|
| | 107 | getIncludes(); |
|---|
| | 108 | if (is_array($errors = module_disable($modulename, $force))) { |
|---|
| | 109 | out("The following error(s) occured:"); |
|---|
| | 110 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 111 | exit(2); |
|---|
| | 112 | } else { |
|---|
| | 113 | out("Module ".$modulename." successfully disabled"); |
|---|
| | 114 | } |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | function doEnable($modulename, $force) { |
|---|
| | 118 | getIncludes(); |
|---|
| | 119 | if (is_array($errors = module_enable($modulename, $force))) { |
|---|
| | 120 | out("The following error(s) occured:"); |
|---|
| | 121 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 122 | exit(2); |
|---|
| | 123 | } else { |
|---|
| | 124 | out("Module ".$modulename." successfully enabled"); |
|---|
| | 125 | } |
|---|
| | 126 | } |
|---|
| | 127 | |
|---|
| | 128 | function doInstall($modulename, $force) { |
|---|
| | 129 | getIncludes(); |
|---|
| | 130 | if (is_array($errors = module_install($modulename, $force))) { |
|---|
| | 131 | out("The following error(s) occured:"); |
|---|
| | 132 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 133 | exit(2); |
|---|
| | 134 | } else { |
|---|
| | 135 | out("Module ".$modulename." successfully installed"); |
|---|
| | 136 | } |
|---|
| | 137 | } |
|---|
| | 138 | |
|---|
| | 139 | function doDelete($modulename, $force) { |
|---|
| | 140 | getIncludes(); |
|---|
| | 141 | if (is_array($errors = module_delete($modulename, $force))) { |
|---|
| | 142 | out("The following error(s) occured:"); |
|---|
| | 143 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 144 | exit(2); |
|---|
| | 145 | } else { |
|---|
| | 146 | out("Module ".$modulename." successfully deleted"); |
|---|
| | 147 | } |
|---|
| | 148 | } |
|---|
| | 149 | |
|---|
| | 150 | function doDeleteAll($force=true) { |
|---|
| | 151 | getIncludes(); //get functions from other modules, in case we need them here |
|---|
| | 152 | $modules = module_getinfo(false, false, true); |
|---|
| | 153 | unset($modules['builtin']);//builtin never gets deleted, so remove it from the list |
|---|
| | 154 | $temp = array(); |
|---|
| | 155 | if (isset($modules['core'])){ //move core to the end |
|---|
| | 156 | $temp['core']=$modules['core']; |
|---|
| | 157 | unset($modules['core']); |
|---|
| | 158 | $modules['core']=$temp['core']; |
|---|
| | 159 | } |
|---|
| | 160 | unset($temp); |
|---|
| | 161 | foreach ($modules as $module){ |
|---|
| | 162 | if (is_array($errors = module_delete($module['rawname'], true))) { |
|---|
| | 163 | out("The following error(s) occured:"); |
|---|
| | 164 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 165 | //exit(2); |
|---|
| | 166 | } else { |
|---|
| | 167 | out("Module ".$module['rawname']." successfully deleted"); |
|---|
| | 168 | } |
|---|
| | 169 | } |
|---|
| | 170 | out('All modules successfully removed'); |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | function doDownload($modulename, $force) { |
|---|
| | 174 | |
|---|
| | 175 | global $modulexml_path; |
|---|
| | 176 | global $modulerepository_path; |
|---|
| | 177 | |
|---|
| | 178 | if (is_array($errors = module_download($modulename, $force, 'download_progress', $modulerepository_path, $modulexml_path))) { |
|---|
| | 179 | out("The following error(s) occured:"); |
|---|
| | 180 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 181 | exit(2); |
|---|
| | 182 | } else { |
|---|
| | 183 | out("Module ".$modulename." successfully downloaded"); |
|---|
| | 184 | } |
|---|
| | 185 | } |
|---|
| | 186 | |
|---|
| | 187 | |
|---|
| | 188 | function download_progress($action, $params) { |
|---|
| | 189 | switch ($action) { |
|---|
| | 190 | case 'untar': |
|---|
| | 191 | outn("\nUntaring.."); |
|---|
| | 192 | break; |
|---|
| | 193 | case 'downloading': |
|---|
| | 194 | outn("\rDownloading ".$params['read'].' of '.$params['total'].' ('.($params['total'] ? round($params['read']/$params['total']*100) : '0').'%) '); |
|---|
| | 195 | if ($params['read'] == $params['total']) { |
|---|
| | 196 | out(''); |
|---|
| | 197 | } |
|---|
| | 198 | break; |
|---|
| | 199 | case 'done'; |
|---|
| | 200 | out('Done'); |
|---|
| | 201 | break; |
|---|
| | 202 | } |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | function doUninstall($modulename, $force) { |
|---|
| | 206 | getIncludes(); |
|---|
| | 207 | if (is_array($errors = module_uninstall($modulename, $force))) { |
|---|
| | 208 | out("The following error(s) occured:"); |
|---|
| | 209 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 210 | exit(2); |
|---|
| | 211 | } else { |
|---|
| | 212 | out("Module ".$modulename." successfully uninstalled"); |
|---|
| | 213 | } |
|---|
| | 214 | } |
|---|
| | 215 | |
|---|
| | 216 | function doUpgrade($modulename, $force) { |
|---|
| | 217 | // either will exit() if there's a problem |
|---|
| | 218 | doDownload($modulename, $force); |
|---|
| | 219 | doInstall($modulename, $force); |
|---|
| | 220 | } |
|---|
| | 221 | |
|---|
| | 222 | function doInstallAll($force) { |
|---|
| | 223 | doUpgradeAll(true); |
|---|
| | 224 | $modules = getInstallableModules(); |
|---|
| | 225 | if (in_array('core', $modules)){ |
|---|
| | 226 | out("Installing core..."); |
|---|
| | 227 | doDownload('core', $force); |
|---|
| | 228 | doInstall('core', $force); |
|---|
| | 229 | } |
|---|
| | 230 | if (count($modules) > 0) { |
|---|
| | 231 | out("Installing: ".implode(', ',$modules)); |
|---|
| | 232 | sleep(1); // a bit of time to ^C abort.. |
|---|
| | 233 | foreach ($modules as $module => $name) { |
|---|
| | 234 | if (($name != 'core')){//we dont want to reinstall core |
|---|
| | 235 | getIncludes(); //get functions from other modules, in case we need them here |
|---|
| | 236 | out("Installing $name..."); |
|---|
| | 237 | doDownload($name, $force); |
|---|
| | 238 | doInstall($name, $force); |
|---|
| | 239 | } |
|---|
| | 240 | } |
|---|
| | 241 | out("Done. All modules installed."); |
|---|
| | 242 | } else { |
|---|
| | 243 | out("All modules up to date."); |
|---|
| | 244 | } |
|---|
| | 245 | } |
|---|
| | 246 | |
|---|
| | 247 | function getIncludes(){ |
|---|
| | 248 | $active_modules = module_getinfo(false, MODULE_STATUS_ENABLED); |
|---|
| | 249 | if(is_array($active_modules)){ |
|---|
| | 250 | foreach($active_modules as $key => $module) { |
|---|
| | 251 | //include module functions |
|---|
| | 252 | if (is_file("modules/{$key}/functions.inc.php")) { |
|---|
| | 253 | require_once("modules/{$key}/functions.inc.php"); |
|---|
| | 254 | } |
|---|
| | 255 | } |
|---|
| | 256 | } |
|---|
| | 257 | } |
|---|
| | 258 | |
|---|
| | 259 | /** |
|---|
| | 260 | * @param bool Controls if a simple (names only) or extended (array of name,versions) array is returned |
|---|
| | 261 | */ |
|---|
| | 262 | function getInstallableModules($extarray = false) { |
|---|
| | 263 | $modules_online = module_getonlinexml(); |
|---|
| | 264 | $module_info=module_getinfo(false); |
|---|
| | 265 | $modules_installable = array(); |
|---|
| | 266 | |
|---|
| | 267 | foreach ($modules_online as $name) { |
|---|
| | 268 | if ((!isset($module_info[$name['rawname']]['status'])) || ($module_info[$name['rawname']]['status'] == MODULE_STATUS_NEEDUPGRADE)){ |
|---|
| | 269 | $modules_installable[]=$name['rawname']; |
|---|
| | 270 | } |
|---|
| | 271 | } |
|---|
| | 272 | return $modules_installable; |
|---|
| | 273 | } |
|---|
| | 274 | |
|---|
| | 275 | /** |
|---|
| | 276 | * @param bool Controls if a simple (names only) or extended (array of name,versions) array is returned |
|---|
| | 277 | */ |
|---|
| | 278 | function getUpgradableModules($extarray = false) { |
|---|
| | 279 | $modules_local = module_getinfo(false, MODULE_STATUS_ENABLED); |
|---|
| | 280 | $modules_online = module_getonlinexml(); |
|---|
| | 281 | $modules_upgradable = array(); |
|---|
| | 282 | |
|---|
| | 283 | foreach (array_keys($modules_local) as $name) { |
|---|
| | 284 | if (isset($modules_online[$name])) { |
|---|
| | 285 | if (version_compare_freepbx($modules_local[$name]['version'], $modules_online[$name]['version']) < 0) { |
|---|
| | 286 | if ($extarray) { |
|---|
| | 287 | $modules_upgradable[] = array( |
|---|
| | 288 | 'name' => $name, |
|---|
| | 289 | 'local_version' => $modules_local[$name]['version'], |
|---|
| | 290 | 'online_version' => $modules_online[$name]['version'], |
|---|
| | 291 | ); |
|---|
| | 292 | } else { |
|---|
| | 293 | $modules_upgradable[] = $name; |
|---|
| | 294 | } |
|---|
| | 295 | } |
|---|
| | 296 | } |
|---|
| | 297 | } |
|---|
| | 298 | return $modules_upgradable; |
|---|
| | 299 | } |
|---|
| | 300 | |
|---|
| | 301 | function doUpgradeAll($force) { |
|---|
| | 302 | $modules = getUpgradableModules(); |
|---|
| | 303 | if (count($modules) > 0) { |
|---|
| | 304 | out("Upgrading: ".implode(', ',$modules)); |
|---|
| | 305 | sleep(1); // a bit of time to ^C abort.. |
|---|
| | 306 | foreach ($modules as $modulename) { |
|---|
| | 307 | out("Upgrading $modulename.."); |
|---|
| | 308 | doUpgrade($modulename, $force); |
|---|
| | 309 | } |
|---|
| | 310 | out("All upgrades done!"); |
|---|
| | 311 | } else { |
|---|
| | 312 | out("Up to date."); |
|---|
| | 313 | } |
|---|
| | 314 | } |
|---|
| | 315 | |
|---|
| | 316 | function mirrorrepo(){ |
|---|
| | 317 | doInstallAll(true); |
|---|
| | 318 | $modules_online = module_getonlinexml(); |
|---|
| | 319 | $modules_local = module_getinfo(); |
|---|
| | 320 | unset($modules_local['builtin']); //builtin never gets deleted, so remove it from the list |
|---|
| | 321 | foreach ($modules_local as $localmod){ |
|---|
| | 322 | if (!module_getonlinexml($localmod['rawname'])){ |
|---|
| | 323 | doDelete($localmod['rawname'],1); |
|---|
| | 324 | } |
|---|
| | 325 | } |
|---|
| | 326 | } |
|---|
| | 327 | |
|---|
| | 328 | function showi18n($modulename) { |
|---|
| | 329 | $modules = module_getinfo($modulename); |
|---|
| | 330 | if (!isset($modules[$modulename])) { |
|---|
| | 331 | fatal($modulename.' not found'); |
|---|
| | 332 | } |
|---|
| | 333 | |
|---|
| | 334 | if (isset($modules[$modulename]['name'])) { |
|---|
| | 335 | echo "# name:\n_(\"".$modules[$modulename]['name']."\")\n"; |
|---|
| | 336 | } |
|---|
| | 337 | if (isset($modules[$modulename]['category'])) { |
|---|
| | 338 | echo "# category:\n_(\"".$modules[$modulename]['category']."\")\n"; |
|---|
| | 339 | } |
|---|
| | 340 | if (isset($modules[$modulename]['description'])) { |
|---|
| | 341 | echo "# description:\n_(\"".trim(str_replace("\n","",$modules[$modulename]['description']))."\")\n"; |
|---|
| | 342 | } |
|---|
| | 343 | if (isset($modules[$modulename]['menuitems'])) { |
|---|
| | 344 | foreach ($modules[$modulename]['menuitems'] as $key => $menuitem) { |
|---|
| | 345 | echo "# $key:\n_(\"$menuitem\")\n"; |
|---|
| | 346 | } |
|---|
| | 347 | } |
|---|
| | 348 | } |
|---|
| | 349 | |
|---|
| | 350 | function showCheckDepends($modulename) { |
|---|
| | 351 | $modules = module_getinfo($modulename); |
|---|
| | 352 | if (!isset($modules[$modulename])) { |
|---|
| | 353 | fatal($modulename.' not found'); |
|---|
| | 354 | } |
|---|
| | 355 | if (($errors = module_checkdepends($modules[$modulename])) !== true) { |
|---|
| | 356 | out("The following dependencies are not met:"); |
|---|
| | 357 | out(' - '.implode("\n - ",$errors)); |
|---|
| | 358 | exit(1); |
|---|
| | 359 | } else { |
|---|
| | 360 | out("All dependencies met for module ".$modulename); |
|---|
| | 361 | } |
|---|
| | 362 | } |
|---|
| | 363 | |
|---|
| | 364 | function showEngine() { |
|---|
| | 365 | $engine = engine_getinfo(); |
|---|
| | 366 | foreach ($engine as $key=>$value) { |
|---|
| | 367 | out(str_pad($key,15,' ',STR_PAD_LEFT).': '.$value); |
|---|
| | 368 | } |
|---|
| | 369 | } |
|---|
| | 370 | |
|---|
| 218 | | function showCheckDepends($modulename) { |
|---|
| 219 | | $modules = module_getinfo($modulename); |
|---|
| 220 | | if (!isset($modules[$modulename])) { |
|---|
| 221 | | fatal($modulename.' not found'); |
|---|
| 222 | | } |
|---|
| 223 | | if (($errors = module_checkdepends($modules[$modulename])) !== true) { |
|---|
| 224 | | out("The following dependencies are not met:"); |
|---|
| 225 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 226 | | exit(1); |
|---|
| 227 | | } else { |
|---|
| 228 | | out("All dependencies met for this module."); |
|---|
| 229 | | } |
|---|
| 230 | | } |
|---|
| 231 | | |
|---|
| 232 | | function showInfo($modulename) { |
|---|
| 233 | | function recursive_print($array, $parentkey = '', $level=0) { |
|---|
| 234 | | foreach ($array as $key => $value) { |
|---|
| 235 | | if (is_array($value)) { |
|---|
| 236 | | // check if there is a numeric key in the sub-array, if so, we don't print the title |
|---|
| 237 | | if (!isset($value[0])) { |
|---|
| 238 | | out(str_pad($key,15+($level * 3),' ',STR_PAD_LEFT).': '); |
|---|
| 239 | | } |
|---|
| 240 | | recursive_print($value, $key, $level + 1); |
|---|
| 241 | | } else { |
|---|
| 242 | | if (is_numeric($key)) { |
|---|
| 243 | | // its just multiple parent keys, so we don't indent, and print the parentkey instead |
|---|
| 244 | | out(str_pad($parentkey,15+(($level-1) * 3),' ',STR_PAD_LEFT).': '.$value); |
|---|
| 245 | | } else { |
|---|
| 246 | | if ($key == 'status') { |
|---|
| 247 | | switch ($value) { |
|---|
| 248 | | case MODULE_STATUS_NOTINSTALLED: $value = 'Not Installed'; break; |
|---|
| 249 | | case MODULE_STATUS_NEEDUPGRADE: $value = 'Disabled; Needs Upgrade'; break; |
|---|
| 250 | | case MODULE_STATUS_ENABLED: $value = 'Enabled'; break; |
|---|
| 251 | | case MODULE_STATUS_DISABLED: $value = 'Disabled'; break; |
|---|
| 252 | | case MODULE_STATUS_BROKEN: $value = 'Broken'; break; |
|---|
| 253 | | } |
|---|
| 254 | | } |
|---|
| 255 | | out(str_pad($key,15+($level * 3),' ',STR_PAD_LEFT).': '.$value); |
|---|
| 256 | | } |
|---|
| 257 | | } |
|---|
| 258 | | } |
|---|
| 259 | | } |
|---|
| 260 | | $modules = module_getinfo($modulename); |
|---|
| 261 | | if (!isset($modules[$modulename])) { |
|---|
| 262 | | fatal($modulename.' not found'); |
|---|
| 263 | | } |
|---|
| 264 | | |
|---|
| 265 | | recursive_print($modules[$modulename]); |
|---|
| 266 | | |
|---|
| 267 | | } |
|---|
| 268 | | |
|---|
| 269 | | function showi18n($modulename) { |
|---|
| 270 | | $modules = module_getinfo($modulename); |
|---|
| 271 | | if (!isset($modules[$modulename])) { |
|---|
| 272 | | fatal($modulename.' not found'); |
|---|
| 273 | | } |
|---|
| 274 | | |
|---|
| 275 | | if (isset($modules[$modulename]['name'])) { |
|---|
| 276 | | echo "# name:\n_(\"".$modules[$modulename]['name']."\")\n"; |
|---|
| 277 | | } |
|---|
| 278 | | if (isset($modules[$modulename]['category'])) { |
|---|
| 279 | | echo "# category:\n_(\"".$modules[$modulename]['category']."\")\n"; |
|---|
| 280 | | } |
|---|
| 281 | | if (isset($modules[$modulename]['description'])) { |
|---|
| 282 | | echo "# description:\n_(\"".trim(str_replace("\n","",$modules[$modulename]['description']))."\")\n"; |
|---|
| 283 | | } |
|---|
| 284 | | if (isset($modules[$modulename]['menuitems'])) { |
|---|
| 285 | | foreach ($modules[$modulename]['menuitems'] as $key => $menuitem) { |
|---|
| 286 | | echo "# $key:\n_(\"$menuitem\")\n"; |
|---|
| 287 | | } |
|---|
| 288 | | } |
|---|
| 289 | | } |
|---|
| 290 | | |
|---|
| 291 | | function doReload() { |
|---|
| 292 | | $result = do_reload(); |
|---|
| 293 | | |
|---|
| 294 | | if ($result['status'] != true) { |
|---|
| 295 | | out("Error(s) have occured, the following is the retrieve_conf output:"); |
|---|
| 296 | | $retrieve_array = explode('<br/>',$result['retrieve_conf']); |
|---|
| 297 | | foreach ($retrieve_array as $line) { |
|---|
| 298 | | out($line); |
|---|
| 299 | | }; |
|---|
| 300 | | } else { |
|---|
| 301 | | out($result['message']); |
|---|
| 302 | | } |
|---|
| 303 | | } |
|---|
| 304 | | |
|---|
| 305 | | function doDisable($modulename, $force) { |
|---|
| 306 | | if (is_array($errors = module_disable($modulename, $force))) { |
|---|
| 307 | | out("The following error(s) occured:"); |
|---|
| 308 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 309 | | exit(2); |
|---|
| 310 | | } else { |
|---|
| 311 | | out("Module successfully disabled"); |
|---|
| 312 | | } |
|---|
| 313 | | } |
|---|
| 314 | | |
|---|
| 315 | | function doEnable($modulename, $force) { |
|---|
| 316 | | if (is_array($errors = module_enable($modulename, $force))) { |
|---|
| 317 | | out("The following error(s) occured:"); |
|---|
| 318 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 319 | | exit(2); |
|---|
| 320 | | } else { |
|---|
| 321 | | out("Module successfully enabled"); |
|---|
| 322 | | } |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | function doInstall($modulename, $force) { |
|---|
| 326 | | if (is_array($errors = module_install($modulename, $force))) { |
|---|
| 327 | | out("The following error(s) occured:"); |
|---|
| 328 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 329 | | exit(2); |
|---|
| 330 | | } else { |
|---|
| 331 | | out("Module successfully installed"); |
|---|
| 332 | | } |
|---|
| 333 | | } |
|---|
| 334 | | |
|---|
| 335 | | function doUninstall($modulename, $force) { |
|---|
| 336 | | if (is_array($errors = module_uninstall($modulename, $force))) { |
|---|
| 337 | | out("The following error(s) occured:"); |
|---|
| 338 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 339 | | exit(2); |
|---|
| 340 | | } else { |
|---|
| 341 | | out("Module successfully uninstalled"); |
|---|
| 342 | | } |
|---|
| 343 | | } |
|---|
| 344 | | |
|---|
| 345 | | function doDelete($modulename, $force) { |
|---|
| 346 | | if (is_array($errors = module_delete($modulename, $force))) { |
|---|
| 347 | | out("The following error(s) occured:"); |
|---|
| 348 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 349 | | exit(2); |
|---|
| 350 | | } else { |
|---|
| 351 | | out("Module successfully deleted"); |
|---|
| 352 | | } |
|---|
| 353 | | } |
|---|
| 354 | | |
|---|
| 355 | | function doDownload($modulename, $force) { |
|---|
| 356 | | |
|---|
| 357 | | global $modulexml_path; |
|---|
| 358 | | global $modulerepository_path; |
|---|
| 359 | | |
|---|
| 360 | | if (is_array($errors = module_download($modulename, $force, 'download_progress', $modulerepository_path, $modulexml_path))) { |
|---|
| 361 | | out("The following error(s) occured:"); |
|---|
| 362 | | out(' - '.implode("\n - ",$errors)); |
|---|
| 363 | | exit(2); |
|---|
| 364 | | } else { |
|---|
| 365 | | out("Module successfully downloaded"); |
|---|
| 366 | | } |
|---|
| 367 | | } |
|---|
| 368 | | |
|---|
| 369 | | function download_progress($action, $params) { |
|---|
| 370 | | switch ($action) { |
|---|
| 371 | | case 'untar': |
|---|
| 372 | | outn("\nUntaring.."); |
|---|
| 373 | | break; |
|---|
| 374 | | case 'downloading': |
|---|
| 375 | | outn("\rDownloading ".$params['read'].' of '.$params['total'].' ('.($params['total'] ? round($params['read']/$params['total']*100) : '0').'%) '); |
|---|
| 376 | | if ($params['read'] == $params['total']) { |
|---|
| 377 | | out(''); |
|---|
| 378 | | } |
|---|
| 379 | | break; |
|---|
| 380 | | case 'done'; |
|---|
| 381 | | out('Done'); |
|---|
| 382 | | break; |
|---|
| 383 | | } |
|---|
| 384 | | } |
|---|
| 385 | | |
|---|
| 386 | | |
|---|
| 387 | | function doUpgrade($modulename, $force) { |
|---|
| 388 | | // either will exit() if there's a problem |
|---|
| 389 | | doDownload($modulename, $force); |
|---|
| 390 | | doInstall($modulename, $force); |
|---|
| 391 | | } |
|---|
| 392 | | |
|---|
| 393 | | /** |
|---|
| 394 | | * @param bool Controls if a simple (names only) or extended (array of name,versions) array is returned |
|---|
| 395 | | */ |
|---|
| 396 | | function getUpgradableModules($extarray = false) { |
|---|
| 397 | | $modules_local = module_getinfo(false, MODULE_STATUS_ENABLED); |
|---|
| 398 | | $modules_online = module_getonlinexml(); |
|---|
| 399 | | $modules_upgradable = array(); |
|---|
| 400 | | |
|---|
| 401 | | foreach (array_keys($modules_local) as $name) { |
|---|
| 402 | | if (isset($modules_online[$name])) { |
|---|
| 403 | | if (version_compare_freepbx($modules_local[$name]['version'], $modules_online[$name]['version']) < 0) { |
|---|
| 404 | | if ($extarray) { |
|---|
| 405 | | $modules_upgradable[] = array( |
|---|
| 406 | | 'name' => $name, |
|---|
| 407 | | 'local_version' => $modules_local[$name]['version'], |
|---|
| 408 | | 'online_version' => $modules_online[$name]['version'], |
|---|
| 409 | | ); |
|---|
| 410 | | } else { |
|---|
| 411 | | $modules_upgradable[] = $name; |
|---|
| 412 | | } |
|---|
| 413 | | } |
|---|
| 414 | | } |
|---|
| 415 | | } |
|---|
| 416 | | return $modules_upgradable; |
|---|
| 417 | | } |
|---|
| 418 | | |
|---|
| 419 | | function doUpgradeAll($force) { |
|---|
| 420 | | $modules = getUpgradableModules(); |
|---|
| 421 | | if (count($modules) > 0) { |
|---|
| 422 | | out("Upgrading: ".implode(', ',$modules)); |
|---|
| 423 | | sleep(1); // a bit of time to ^C abort.. |
|---|
| 424 | | foreach ($modules as $modulename) { |
|---|
| 425 | | out("Upgrading $modulename.."); |
|---|
| 426 | | doUpgrade($modulename, $force); |
|---|
| 427 | | } |
|---|
| 428 | | out("Done all upgrades."); |
|---|
| 429 | | } else { |
|---|
| 430 | | out("Up to date."); |
|---|
| 431 | | } |
|---|
| 432 | | } |
|---|