update_status.module

The update status module file.

This module is responsible for checking with getflightpath.com, to see if a new update is available for any of the installed modules or system.

Functions & methods

NameDescription
update_status_check_nowThis will force a re-check of modules for this update_status module.
update_status_cronImplementation of hook_cron()
update_status_get_install_status_urlReturns a URL containing install statuses for all installed modules on this site.
update_status_menuImplementation of hook_menu
update_status_perform_checkThis function actually performs the update status check with getflightpath.com
update_status_statusImplementation of hook_status.

File

modules/update_status/update_status.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * The update status module file.
  5. *
  6. * This module is responsible for checking with getflightpath.com, to see
  7. * if a new update is available for any of the installed modules or system.
  8. */
  9. /**
  10. * Implementation of hook_menu
  11. *
  12. */
  13. function update_status_menu() {
  14. $items = array();
  15. $items["update-status-check-now"] = array(
  16. "page_callback" => "update_status_check_now",
  17. "access_arguments" => array("run_cron"),
  18. "type" => MENU_TYPE_CALLBACK,
  19. );
  20. return $items;
  21. }
  22. /**
  23. * This will force a re-check of modules for this update_status module.
  24. *
  25. * Required permission is the same as Run Cron permission.
  26. *
  27. */
  28. function update_status_check_now() {
  29. update_status_perform_check();
  30. // Go back to the System status page...
  31. fp_goto("admin/config/status");
  32. }
  33. /**
  34. * This function actually performs the update status check with getflightpath.com
  35. *
  36. */
  37. function update_status_perform_check() {
  38. // Let's assemble our URL which should be fairly long.
  39. $url = update_status_get_install_status_url();
  40. $result = fp_http_request($url);
  41. // We expect the $result to look like an object, where
  42. // $result->data contains the returned HTML from the url,
  43. // and $result->code contains the response code.
  44. $response = trim($result->data);
  45. // Response must contain the text "FLIGHTPATH_SUCCESS" for us to believe it is successful.
  46. if (!strstr($response, "FLIGHTPATH_SUCCESS")) {
  47. watchdog("update_status", "Checking update status failed.", array(), WATCHDOG_ERROR);
  48. fp_add_message(t("Checking update status failed. Perhaps FlightPath cannot access external sites?"));
  49. return;
  50. }
  51. // If we are here then we got back a valid response.
  52. // Parse result and set variables where needed.
  53. $res_array = array();
  54. parse_str($response, $res_array);
  55. // The modules which have different versions than what we have installed
  56. // are in $res_array["modules"] and ["release_types"]
  57. variable_set("update_status_need_updates_modules", $res_array["modules"]);
  58. variable_set("update_status_need_updates_release_types", $res_array["release_types"]);
  59. variable_set("update_status_last_run", time());
  60. fp_add_message(t("Check of update status successful."));
  61. }
  62. /**
  63. * Implementation of hook_cron()
  64. *
  65. * We only want to check every few days that cron runs. Check with getflightpath.com,
  66. * and, if updates are available, store that information in our variables table.
  67. */
  68. function update_status_cron() {
  69. $check_if_older_than = strtotime("-3 DAY");
  70. // When was the last time we ran this check?
  71. // (we only want to run once every few days)
  72. $last_run = variable_get("update_status_last_run", 0);
  73. if ($last_run > $check_if_older_than) {
  74. // We have run this recently, harmlessly return
  75. // Comment out to have this run every time (good for development)
  76. return;
  77. }
  78. // If we are here, it means we should run our check.
  79. update_status_perform_check();
  80. }
  81. /**
  82. * Implementation of hook_status.
  83. */
  84. function update_status_status() {
  85. $rtn = array();
  86. fp_add_css(fp_get_module_path("update_status") . "/css/update_status.css");
  87. $status = "";
  88. // Check the data we have for modules, to see if any of them could use an update.
  89. $updates = variable_get("update_status_need_updates_modules", array());
  90. $releases = variable_get("update_status_need_updates_release_types", array());
  91. $release_desc = array(
  92. "other" => "Other",
  93. "bug_features" => "Bug fixes & new features",
  94. "new_features" => "New features",
  95. "bug_fixes" => "Bug fixes",
  96. "security" => "Security - High Priority!",
  97. );
  98. ksort($updates);
  99. if (count($updates)) {
  100. $status .= t("The following packages have available updates:");
  101. $status .= "<table border='0' cellpadding='3' width='100%' class='update-status-status-table'>
  102. <tr>
  103. <th>" . t("Package") . "</th>
  104. <th>" . t("Your Version") . "</th>
  105. <th>" . t("Latest Version") . "</th>
  106. <th>" . t("Release type") . "</th>
  107. </tr>";
  108. foreach ($updates as $module => $version) {
  109. $release_type = fp_get_machine_readable($releases[$module]);
  110. $display_name = $module;
  111. $module_details = fp_get_module_details($module);
  112. if ($module_details["info"]["name"] != "") {
  113. $display_name = $module_details["info"]["name"];
  114. }
  115. $your_version = $module_details["version"];
  116. $status .= "<tr class='release-row release-row-$release_type'>
  117. <td valign='top' class='update-status-status-module'>
  118. <a href='http://getflightpath.com/project/$module' target='_blank'>$display_name</a></td>
  119. <td valign='top' class='update-status-status-your-version'>$your_version</td>
  120. <td valign='top' class='update-status-status-version'>$version</td>
  121. <td valign='top' class='update-status-status-type'>{$release_desc[$releases[$module]]}</td>
  122. </tr>";
  123. }
  124. $status .= "</table>";
  125. }
  126. else {
  127. $status .= t("All modules are up to date.");
  128. }
  129. $check_link = "";
  130. if (user_has_permission("run_cron")) {
  131. $check_link = l(t("Check now?"), "update-status-check-now");
  132. }
  133. $last_run = variable_get("update_status_last_run", 0);
  134. if ($last_run > 0) {
  135. $status .= "<p>" . t("Last check on %date.", array("%date" => format_date($last_run))) . " $check_link</p>";
  136. }
  137. else {
  138. $status .= "<p><b><span style='color:red;'>*</span>
  139. </b>" . t("Module status has never been checked. Please make sure you have a correctly configured cron job.") . " $check_link</p>";
  140. }
  141. $rtn["status"] = $status;
  142. return $rtn;
  143. }
  144. /**
  145. * Returns a URL containing install statuses for all installed modules on this site.
  146. */
  147. function update_status_get_install_status_url() {
  148. $rtn = "";
  149. $domain = "getflightpath.com";
  150. $rtn .= "http://$domain/check-update-status?pa=cv&st=" . urlencode(fp_token());
  151. $rtn .= "&u=" . urlencode($GLOBALS["fp_system_settings"]["base_url"]);
  152. $rtn .= "&c=" . FLIGHTPATH_CORE;
  153. // These core modules do not have version numbers, so we will skip them.
  154. $ignore_core_modules = array(
  155. "admin", "advise", "announcements", "blank_degrees", "blocks", "comments", "content", "course_search", "stats",
  156. "student_search", "system", "update_status", "tinymce", "user",
  157. );
  158. foreach ($GLOBALS["fp_system_settings"]["modules"] as $module => $details) {
  159. if (in_array($module, $ignore_core_modules)) continue;
  160. $rtn .= "&" . "modules[" . urlencode($module) . "]=" . urlencode($details["version"]);
  161. }
  162. // Add FP version string.
  163. $rtn .= "&" . "modules[" . urlencode("flightpath") . "]=" . urlencode(FLIGHTPATH_CORE . '-' . FLIGHTPATH_VERSION);
  164. return $rtn;
  165. }