/** * [doFetchUpdates description] * @return [type] [description] */ public function doFetchUpdates() { // Pull Projects $projects = update_get_projects(); // Fetch Updates foreach ($projects as $project) { $res = _update_process_fetch_task($project); } }
/** * Obtains release info for all installed projects via update.module. * * @see update_get_available(). * @see update_manual_status(). */ protected function getAvailableReleases() { // Force to invalidate some caches that are only cleared // when visiting update status report page. This allow to detect changes in // .info files. _update_cache_clear('update_project_data'); _update_cache_clear('update_project_projects'); // From update_get_available(): Iterate all projects and create a fetch task // for those we have no information or is obsolete. $available = _update_get_cached_available_releases(); module_load_include('inc', 'update', 'update.compare'); $update_projects = update_get_projects(); foreach ($update_projects as $key => $project) { if (empty($available[$key])) { update_create_fetch_task($project); continue; } if ($project['info']['_info_file_ctime'] > $available[$key]['last_fetch']) { $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; } if (empty($available[$key]['releases'])) { $available[$key]['fetch_status'] = UPDATE_FETCH_PENDING; } if (!empty($available[$key]['fetch_status']) && $available[$key]['fetch_status'] == UPDATE_FETCH_PENDING) { update_create_fetch_task($project); } } // Set a batch to process all pending tasks. $batch = array('operations' => array(array('update_fetch_data_batch', array())), 'finished' => 'update_fetch_data_finished', 'file' => drupal_get_path('module', 'update') . '/update.fetch.inc'); batch_set($batch); drush_backend_batch_process(); // Clear any error set by a failed update fetch task. This avoid rollbacks. drush_clear_error(); // Calculate update status data. $available = _update_get_cached_available_releases(); return $available; }
/** * Tests updates with a hidden base theme. */ function testUpdateHiddenBaseTheme() { module_load_include('compare.inc', 'update'); // Enable the subtheme. theme_enable(array('update_test_subtheme')); // Add a project and initial state for base theme and subtheme. $system_info = array('update_test_basetheme' => array('project' => 'update_test_basetheme', 'hidden' => TRUE), 'update_test_subtheme' => array('project' => 'update_test_subtheme', 'hidden' => FALSE)); \Drupal::config('update_test.settings')->set('system_info', $system_info)->save(); $projects = update_get_projects(); $theme_data = system_rebuild_theme_data(); $project_info = new ProjectInfo(); $project_info->processInfoList($projects, $theme_data, 'theme', TRUE); $this->assertTrue(!empty($projects['update_test_basetheme']), 'Valid base theme (update_test_basetheme) was found.'); }
/** * @param string $extension * * @return array Context result generated by Drupal. * * @throws Oxygen_Exception * * @see update_authorize_run_update() */ public function updateExtension($extension) { module_load_include('inc', 'update', 'update.manager'); drupal_get_updaters(); $directory = _update_manager_extract_directory(); $projectLocation = $directory . '/' . $extension; $updater = Updater::factory($projectLocation); $projectRealLocation = drupal_realpath($projectLocation); // If the owner of the directory we extracted is the same as the // owner of our configuration directory (e.g. sites/default) where we're // trying to install the code, there's no need to prompt for FTP/SSH // credentials. Instead, we instantiate a FileTransferLocal and invoke // update_authorize_run_install() directly. if (fileowner($projectRealLocation) !== fileowner(DRUPAL_ROOT . '/' . conf_path())) { throw new Oxygen_Exception(Oxygen_Exception::PROJECT_MANAGER_FILE_SYSTEM_NOT_WRITABLE, array('projectOwner' => fileowner($projectRealLocation), 'siteOwner' => fileowner(conf_path()))); } module_load_include('inc', 'update', 'update.authorize'); // @TODO: Implement other file transfer types. $fileTransfer = new FileTransferLocal(DRUPAL_ROOT); update_authorize_batch_copy_project($extension, get_class($updater), $projectRealLocation, $fileTransfer, $context); // Reset the cache for this extension only, so we may immediately update the dashboard. // Hacky way to do it, but most efficient. module_load_include('inc', 'update', 'update.fetch'); module_load_include('inc', 'update', 'update.compare'); _update_cache_clear('update_project_projects'); _update_cache_clear('update_project_data'); $projects = update_get_projects(); _update_process_fetch_task($projects[$extension]); return $context; }
public function doInstallUpdate($update_row) { // Pull Projects $projects = update_get_projects(); // Pull Available Releases $packages = db_select('cache_update', 'cu')->fields('cu')->condition('cid', 'available_releases::%', 'LIKE')->execute()->fetchAllAssoc('cid'); // Find & Process Package foreach ($packages as $package) { // Unserialize Store $package->data = unserialize($package->data); $project = isset($projects[$package->data['short_name']]) ? $projects[$package->data['short_name']] : null; $package_update = reset($package->data['releases']); $package_uid = $project['project_type'] . ':' . $project['name'] . ':' . $package_update['version']; // Match Package if ($update_row->update_id == $package_uid) { // Type Switch switch ($update_row->type) { case 'core': $this->caller->out(' - Error: Core Updates Not Supported'); break; case 'module': case 'theme': // Download Package if (!($local_cache = update_manager_file_get($package_update['download_link']))) { $this->caller->out(' - Error: Failed to download ' . $project['name'] . ' from ' . $package_update['download_link']); return false; } // Extract it. $extract_directory = _update_manager_extract_directory(); try { update_manager_archive_extract($local_cache, $extract_directory); } catch (Exception $e) { $this->caller->out(' - Error: ' . $e->getMessage()); return false; } // Verify it. $archive_errors = update_manager_archive_verify($project['name'], $local_cache, $extract_directory); if (!empty($archive_errors)) { foreach ($archive_errors as $key => $error) { $this->caller->out(' - Error: ' . $error); } return false; } // Load Updater $project_folder = $extract_directory . '/' . $project['name']; try { $updater = Updater::factory($project_folder); } catch (Exception $e) { $this->caller->out(' - Error: ' . $e->getMessage()); return false; } $context = array('results' => array()); // Run Updater update_authorize_batch_copy_project($project['name'], get_class($updater), drupal_realpath($project_folder), new FileTransferLocal(DRUPAL_ROOT), $context); // Verify if (empty($context['finished'])) { $message = isset($context['results']['log'][$project['name']]) ? reset($context['results']['log'][$project['name']])['message'] : 'Unknown Installer Error'; $this->caller->out(' - Error: ' . $message); return false; } else { $this->caller->out(' - ' . ucfirst($update_row->type) . ' installed successfully'); } break; } } } // Return return true; }
public function content() { $config = \Drupal::config('nagios.settings'); // Disable cache \Drupal::service('page_cache_kill_switch')->trigger(); $args = func_get_args(); // Module to run checks for. $module = array_shift($args); // ID to run checks for. $id = array_shift($args); $codes = nagios_status(); // Check the unique ID string and access permissions first. $ua = $config->get('nagios.ua'); $request_code = $_SERVER['HTTP_USER_AGENT']; // Check if HTTP GET variable "unique_id" is used and the usage is allowed. if (isset($_GET['unique_id'])) { if ($config->get('nagios.statuspage.getparam') == TRUE) { $request_code = $_GET['unique_id']; } } if (\Drupal::currentUser()->hasPermission('administer site configuration') || $request_code == $ua) { // Authorized so calling other modules if ($module) { // A specific module has been requested. $nagios_data = array(); $nagios_data[$module] = \Drupal::moduleHandler()->invoke($module, 'nagios', $id); } else { $nagios_data = nagios_invoke_all('nagios'); } } else { // This is not an authorized unique id or uer, so just return this default status. $nagios_data = array('nagios' => array('DRUPAL' => array('status' => NAGIOS_STATUS_UNKNOWN, 'type' => 'state', 'text' => t('Unauthorized')))); } // Find the highest level to be the overall status $severity = NAGIOS_STATUS_OK; $min_severity = $config->get('nagios.min_report_severity'); foreach ($nagios_data as $module_name => $module_data) { foreach ($module_data as $key => $value) { if (is_array($value) && array_key_exists('status', $value) && $value['status'] >= $min_severity) { $severity = max($severity, $value['status']); } } } // Identifier that we check on the other side $output = "\n" . 'nagios=' . $codes[$severity] . ', '; $output_state = array(); $output_perf = array(); foreach ($nagios_data as $module_name => $module_data) { foreach ($module_data as $key => $value) { switch ($value['type']) { case 'state': // If status is larger then minimum severity if ($value['status'] >= $min_severity) { $tmp_state = $key . ':' . $codes[$value['status']]; } else { $tmp_state = $key . ':' . $codes[NAGIOS_STATUS_OK]; } if (!empty($value['text'])) { $tmp_state .= '=' . $value['text']; } if ($config->get('nagios.show_outdated_names') && $key == 'ADMIN' && $value['text'] == 'Module and theme update status') { $tmp_projects = update_calculate_project_data(update_get_projects()); $nagios_ignored_modules = $config->get('nagios.ignored_modules') ?: array(); $nagios_ignored_themes = $config->get('nagios.ignored_themes') ?: array(); $nagios_ignored_projects = $nagios_ignored_modules + $nagios_ignored_themes; $outdated_count = 0; $tmp_modules = ''; foreach ($tmp_projects as $projkey => $projval) { if (!isset($nagios_ignored_projects[$projkey])) { if ($projval['status'] < UPDATE_CURRENT && $projval['status'] >= UPDATE_NOT_SECURE) { switch ($projval['status']) { case UPDATE_NOT_SECURE: $tmp_projstatus = t('NOT SECURE'); break; case UPDATE_REVOKED: $tmp_projstatus = t('REVOKED'); break; case UPDATE_NOT_SUPPORTED: $tmp_projstatus = t('NOT SUPPORTED'); break; case UPDATE_NOT_CURRENT: $tmp_projstatus = t('NOT CURRENT'); break; default: $tmp_projstatus = $projval['status']; } $tmp_modules .= ' ' . $projkey . ':' . $tmp_projstatus; $outdated_count++; } } } if ($outdated_count > 0) { $tmp_modules = trim($tmp_modules); $tmp_state .= " ({$tmp_modules})"; } } $output_state[] = $tmp_state; break; case 'perf': $output_perf[] = $key . '=' . $value['text']; break; } } } $output .= implode(', ', $output_state) . ' | ' . implode(';', $output_perf) . "\n"; $response = new Response($output, Response::HTTP_OK, ['Content-Type' => 'text/plain']); // Disable browser cache $response->setMaxAge(0); $response->setExpires($date); return $response; }