00001 <?php
00002
00003
00012 function update_manual_status() {
00013 if (_update_refresh()) {
00014 drupal_set_message(t('Fetched information about all available new releases and updates.'));
00015 }
00016 else {
00017 drupal_set_message(t('Unable to fetch any information about available new releases and updates.'), 'error');
00018 }
00019 drupal_goto('admin/reports/updates');
00020 }
00021
00025 function _update_refresh() {
00026 global $base_url;
00027 module_load_include('inc', 'update', 'update.compare');
00028
00029
00030
00031
00032
00033
00034 update_invalidate_cache();
00035
00036 $available = array();
00037 $data = array();
00038 $site_key = md5($base_url . drupal_get_private_key());
00039 $projects = update_get_projects();
00040
00041 foreach ($projects as $key => $project) {
00042 $url = _update_build_fetch_url($project, $site_key);
00043 $xml = drupal_http_request($url);
00044 if (isset($xml->data)) {
00045 $data[] = $xml->data;
00046 }
00047 }
00048
00049 if ($data) {
00050 $parser = new update_xml_parser;
00051 $available = $parser->parse($data);
00052 }
00053 if (!empty($available) && is_array($available)) {
00054 $frequency = variable_get('update_check_frequency', 1);
00055 cache_set('update_info', $available, 'cache_update', time() + (60 * 60 * 24 * $frequency));
00056 variable_set('update_last_check', time());
00057 watchdog('update', 'Fetched information about all available new releases and updates.', array(), WATCHDOG_NOTICE, l(t('view'), 'admin/reports/updates'));
00058 }
00059 else {
00060 module_invoke('system', 'check_http_request');
00061 watchdog('update', 'Unable to fetch any information about available new releases and updates.', array(), WATCHDOG_ERROR, l(t('view'), 'admin/reports/updates'));
00062 }
00063 return $available;
00064 }
00065
00081 function _update_build_fetch_url($project, $site_key = '') {
00082 $default_url = variable_get('update_fetch_url', UPDATE_DEFAULT_URL);
00083 if (!isset($project['info']['project status url'])) {
00084 $project['info']['project status url'] = $default_url;
00085 }
00086 $name = $project['name'];
00087 $url = $project['info']['project status url'];
00088 $url .= '/' . $name . '/' . DRUPAL_CORE_COMPATIBILITY;
00089 if (!empty($site_key)) {
00090 $url .= (strpos($url, '?') === TRUE) ? '&' : '?';
00091 $url .= 'site_key=';
00092 $url .= drupal_urlencode($site_key);
00093 if (!empty($project['info']['version'])) {
00094 $url .= '&version=';
00095 $url .= drupal_urlencode($project['info']['version']);
00096 }
00097 }
00098 return $url;
00099 }
00100
00110 function _update_cron_notify() {
00111 include_once './includes/install.inc';
00112 $status = update_requirements('runtime');
00113 $params = array();
00114 foreach (array('core', 'contrib') as $report_type) {
00115 $type = 'update_' . $report_type;
00116 if (isset($status[$type]['severity'])
00117 && $status[$type]['severity'] == REQUIREMENT_ERROR) {
00118 $params[$report_type] = $status[$type]['reason'];
00119 }
00120 }
00121 if (!empty($params)) {
00122 $notify_list = variable_get('update_notify_emails', '');
00123 if (!empty($notify_list)) {
00124 $default_language = language_default();
00125 foreach ($notify_list as $target) {
00126 if ($target_user = user_load(array('mail' => $target))) {
00127 $target_language = user_preferred_language($target_user);
00128 }
00129 else {
00130 $target_language = $default_language;
00131 }
00132 drupal_mail('update', 'status_notify', $target, $target_language, $params);
00133 }
00134 }
00135 }
00136 }
00137
00142 class update_xml_parser {
00143 var $projects = array();
00144 var $current_project;
00145 var $current_release;
00146 var $current_term;
00147 var $current_tag;
00148 var $current_object;
00149
00153 function parse($data) {
00154 foreach ($data as $datum) {
00155 $parser = xml_parser_create();
00156 xml_set_object($parser, $this);
00157 xml_set_element_handler($parser, 'start', 'end');
00158 xml_set_character_data_handler($parser, "data");
00159 xml_parse($parser, $datum);
00160 xml_parser_free($parser);
00161 }
00162 return $this->projects;
00163 }
00164
00165 function start($parser, $name, $attr) {
00166 $this->current_tag = $name;
00167 switch ($name) {
00168 case 'PROJECT':
00169 unset($this->current_object);
00170 $this->current_project = array();
00171 $this->current_object = &$this->current_project;
00172 break;
00173 case 'RELEASE':
00174 unset($this->current_object);
00175 $this->current_release = array();
00176 $this->current_object = &$this->current_release;
00177 break;
00178 case 'TERM':
00179 unset($this->current_object);
00180 $this->current_term = array();
00181 $this->current_object = &$this->current_term;
00182 break;
00183 }
00184 }
00185
00186 function end($parser, $name) {
00187 switch ($name) {
00188 case 'PROJECT':
00189 unset($this->current_object);
00190 $this->projects[$this->current_project['short_name']] = $this->current_project;
00191 $this->current_project = array();
00192 break;
00193 case 'RELEASE':
00194 unset($this->current_object);
00195 $this->current_project['releases'][$this->current_release['version']] = $this->current_release;
00196 break;
00197 case 'RELEASES':
00198 $this->current_object = &$this->current_project;
00199 break;
00200 case 'TERM':
00201 unset($this->current_object);
00202 $term_name = $this->current_term['name'];
00203 if (!isset($this->current_release['terms'])) {
00204 $this->current_release['terms'] = array();
00205 }
00206 if (!isset($this->current_release['terms'][$term_name])) {
00207 $this->current_release['terms'][$term_name] = array();
00208 }
00209 $this->current_release['terms'][$term_name][] = $this->current_term['value'];
00210 break;
00211 case 'TERMS':
00212 $this->current_object = &$this->current_release;
00213 break;
00214 default:
00215 $this->current_object[strtolower($this->current_tag)] = trim($this->current_object[strtolower($this->current_tag)]);
00216 $this->current_tag = '';
00217 }
00218 }
00219
00220 function data($parser, $data) {
00221 if ($this->current_tag && !in_array($this->current_tag, array('PROJECT', 'RELEASE', 'RELEASES', 'TERM', 'TERMS'))) {
00222 $tag = strtolower($this->current_tag);
00223 if (isset($this->current_object[$tag])) {
00224 $this->current_object[$tag] .= $data;
00225 }
00226 else {
00227 $this->current_object[$tag] = $data;
00228 }
00229 }
00230 }
00231 }