| | 478 | /** Set base of core and framework to the main release and make sure enabled |
|---|
| | 479 | * |
|---|
| | 480 | * TODO: CHANGE THIS, SET BASE VERSION BASED ON WHAT IS PACKAGED SINCE SVN INSTALLS WILL BE DIFFERENT |
|---|
| | 481 | */ |
|---|
| | 482 | function set_base_version() { |
|---|
| | 483 | global $dryrun; |
|---|
| | 484 | |
|---|
| | 485 | outn("Checking framework.. "); |
|---|
| | 486 | if (!$dryrun) { |
|---|
| | 487 | out(set_module_version('framework')); |
|---|
| | 488 | } else { |
|---|
| | 489 | out("Dry Run Not Updated"); |
|---|
| | 490 | } |
|---|
| | 491 | |
|---|
| | 492 | outn("Checking core.. "); |
|---|
| | 493 | if (!$dryrun) { |
|---|
| | 494 | out(set_module_version('core')); |
|---|
| | 495 | } else { |
|---|
| | 496 | out("Dry Run Not Updated"); |
|---|
| | 497 | } |
|---|
| | 498 | |
|---|
| | 499 | } |
|---|
| | 500 | |
|---|
| | 501 | /** Set the module version number to the packaged version and enable |
|---|
| | 502 | * module must require not install.php or install.sql script |
|---|
| | 503 | * this is primarily to package core and framework with freepbx tarballs |
|---|
| | 504 | * |
|---|
| | 505 | */ |
|---|
| | 506 | function set_module_version($module) { |
|---|
| | 507 | global $db; |
|---|
| | 508 | |
|---|
| | 509 | $module_dir = dirname(__FILE__)."/amp_conf/htdocs/admin/modules/"; |
|---|
| | 510 | $file_path = $module_dir.$module."/module.xml"; |
|---|
| | 511 | if (file_exists($file_path)) { |
|---|
| | 512 | // TODO: this is bad, there are other version tags (depends on) but this |
|---|
| | 513 | // is equivalnet to what publish.pl does, so it expects this to be |
|---|
| | 514 | // at the top. |
|---|
| | 515 | // |
|---|
| | 516 | $module_xml = file_get_contents($file_path); |
|---|
| | 517 | if (preg_match('/<version>(.+)<\/version>/', $module_xml, $matches)) { |
|---|
| | 518 | $version = $matches[1]; |
|---|
| | 519 | } else { |
|---|
| | 520 | die("ERROR: $file_path found but no verison information"); |
|---|
| | 521 | } |
|---|
| | 522 | } else { |
|---|
| | 523 | return "not packaged, no updating needed"; |
|---|
| | 524 | } |
|---|
| | 525 | |
|---|
| | 526 | // If we didn't return above, then we found the package as part of the install |
|---|
| | 527 | // tarball and want to update the version info since this might be overwriting |
|---|
| | 528 | // and existing install that has a newever version. |
|---|
| | 529 | // |
|---|
| | 530 | $sql = "SELECT version FROM modules WHERE modulename = '$module'"; |
|---|
| | 531 | $result = $db->getCol($sql); |
|---|
| | 532 | if(DB::IsError($result)) { |
|---|
| | 533 | die($result->getMessage()); |
|---|
| | 534 | } |
|---|
| | 535 | $sql = ""; |
|---|
| | 536 | if (count($result) == 0) { |
|---|
| | 537 | $sql = "INSERT INTO modules (modulename, version, enabled) VALUES ('$module', '$version', 1)"; |
|---|
| | 538 | } else if ($result[0] != $version) { |
|---|
| | 539 | $sql = "UPDATE modules SET version = '$version', enabled = 1 WHERE modulename = '$module'"; |
|---|
| | 540 | } |
|---|
| | 541 | if ($sql) { |
|---|
| | 542 | debug($sql); |
|---|
| | 543 | $result = $db->query($sql); |
|---|
| | 544 | if(DB::IsError($result)) { |
|---|
| | 545 | die($result->getMessage()); |
|---|
| | 546 | } |
|---|
| | 547 | } |
|---|
| | 548 | return "updated to $version"; |
|---|
| | 549 | } |
|---|
| | 550 | |
|---|