update_status.module

  1. 6.x modules/update_status/update_status.module
  2. 4.x modules/update_status/update_status.module
  3. 5.x modules/update_status/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.

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. $response = fp_url_get_contents($url);
  41. // Response must contain the text "FLIGHTPATH_SUCCESS" for us to believe it is successful.
  42. if (!strstr($response, "FLIGHTPATH_SUCCESS")) {
  43. watchdog("update_status", "Checking update status failed. URL: $url. Response: " . print_r($response, TRUE), array(), WATCHDOG_ERROR);
  44. fp_add_message(t("Checking update status failed. Perhaps FlightPath cannot access external sites?"));
  45. return;
  46. }
  47. // If we are here then we got back a valid response.
  48. // Parse result and set variables where needed.
  49. $res_array = array();
  50. parse_str($response, $res_array);
  51. // The modules which have different versions than what we have installed
  52. // are in $res_array["modules"] and ["release_types"]
  53. variable_set("update_status_need_updates_modules", $res_array["modules"]);
  54. variable_set("update_status_need_updates_release_types", $res_array["release_types"]);
  55. variable_set("update_status_last_run", time());
  56. fp_add_message(t("Check of update status successful."));
  57. }
  58. /**
  59. * Implementation of hook_cron()
  60. *
  61. * We only want to check every few days that cron runs. Check with getflightpath.com,
  62. * and, if updates are available, store that information in our variables table.
  63. */
  64. function update_status_cron() {
  65. $check_if_older_than = strtotime("-7 DAY");
  66. // When was the last time we ran this check?
  67. // (we only want to run once every few days)
  68. $last_run = variable_get("update_status_last_run", 0);
  69. if ($last_run > $check_if_older_than) {
  70. // We have run this recently, harmlessly return
  71. // Comment out to have this run every time (good for development)
  72. return;
  73. }
  74. // If we are here, it means we should run our check.
  75. update_status_perform_check();
  76. }
  77. /**
  78. * Implementation of hook_status.
  79. */
  80. function update_status_status() {
  81. $rtn = array();
  82. fp_add_css(fp_get_module_path("update_status") . "/css/update_status.css");
  83. $status = "";
  84. // Check the data we have for modules, to see if any of them could use an update.
  85. $updates = variable_get("update_status_need_updates_modules", array());
  86. $releases = variable_get("update_status_need_updates_release_types", array());
  87. if (!is_array($updates)) {
  88. $updates = array(); // just set to empty array if for some reason its null.
  89. }
  90. if (!is_array($releases)) {
  91. $releases = array();
  92. }
  93. $release_desc = array(
  94. "other" => "Other",
  95. "bug_features" => "Bug fixes & new features",
  96. "new_features" => "New features",
  97. "bug_fixes" => "Bug fixes",
  98. "security" => "Security - High Priority!",
  99. );
  100. ksort($updates);
  101. if (count($updates)) {
  102. $status .= t("The following packages have available updates:");
  103. $status .= "<table border='0' cellpadding='3' width='100%' class='update-status-status-table'>
  104. <tr>
  105. <th>" . t("Package") . "</th>
  106. <th>" . t("Your Version") . "</th>
  107. <th>" . t("Latest Version") . "</th>
  108. <th>" . t("Release type") . "</th>
  109. </tr>";
  110. foreach ($updates as $module => $version) {
  111. $release_type = fp_get_machine_readable($releases[$module]);
  112. $display_name = $module;
  113. $module_details = fp_get_module_details($module);
  114. if ($module_details["info"]["name"] != "") {
  115. $display_name = $module_details["info"]["name"];
  116. }
  117. $your_version = $module_details["version"];
  118. if ($your_version == "%FP_VERSION%") {
  119. // This means you are using a version not downloaded from getflightpath.com. Probably directly from a git repository.
  120. $your_version = "GitRepo";
  121. }
  122. $status .= "<tr class='release-row release-row-$release_type'>
  123. <td valign='top' class='update-status-status-module'>
  124. <a href='http://getflightpath.com/project/$module' target='_blank'>$display_name</a></td>
  125. <td valign='top' class='update-status-status-your-version'>$your_version</td>
  126. <td valign='top' class='update-status-status-version'>$version</td>
  127. <td valign='top' class='update-status-status-type'>{$release_desc[$releases[$module]]}</td>
  128. </tr>";
  129. }
  130. $status .= "</table>";
  131. }
  132. else {
  133. $status .= t("All modules are up to date.");
  134. }
  135. $check_link = "";
  136. if (user_has_permission("run_cron")) {
  137. $check_link = l(t("Check now?"), "update-status-check-now");
  138. }
  139. $last_run = variable_get("update_status_last_run", 0);
  140. if ($last_run > 0) {
  141. $status .= "<p>" . t("Last check on %date.", array("%date" => format_date($last_run))) . " $check_link</p>";
  142. }
  143. else {
  144. $status .= "<p><b><span style='color:red;'>*</span>
  145. </b>" . t("Module status has never been checked. Please make sure you have a correctly configured cron job.") . " $check_link</p>";
  146. }
  147. $rtn["status"] = $status;
  148. return $rtn;
  149. }
  150. /**
  151. * Returns a URL containing install statuses for all installed modules on this site.
  152. */
  153. function update_status_get_install_status_url() {
  154. $rtn = "";
  155. $domain = "getflightpath.com";
  156. $rtn .= "https://$domain/check-update-status?pa=cv&st=" . urlencode(fp_token());
  157. $rtn .= "&u=" . urlencode($GLOBALS["fp_system_settings"]["base_url"]);
  158. $rtn .= "&c=" . FLIGHTPATH_CORE;
  159. // These core modules do not have version numbers, so we will skip them.
  160. $ignore_core_modules = array(
  161. "admin", "advise", "announcements", "blank_degrees", "blocks", "comments", "content", "course_search", "stats",
  162. "student_search", "system", "update_status", "tinymce", "user",
  163. );
  164. foreach ($GLOBALS["fp_system_settings"]["modules"] as $module => $details) {
  165. if (in_array($module, $ignore_core_modules)) continue;
  166. $rtn .= "&" . "modules[" . urlencode($module) . "]=" . urlencode($details["version"]);
  167. }
  168. // Add FP version string.
  169. $rtn .= "&" . "modules[" . urlencode("flightpath") . "]=" . urlencode(FLIGHTPATH_CORE . '-' . FLIGHTPATH_VERSION);
  170. return $rtn;
  171. }

Functions

Namesort descending Description
update_status_check_now This will force a re-check of modules for this update_status module.
update_status_cron Implementation of hook_cron()
update_status_get_install_status_url Returns a URL containing install statuses for all installed modules on this site.
update_status_menu Implementation of hook_menu
update_status_perform_check This function actually performs the update status check with getflightpath.com
update_status_status Implementation of hook_status.