/** * 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 that exactly one fetch task per project is created and not more. */ function testFetchTasks() { $projecta = array('name' => 'aaa_update_test'); $projectb = array('name' => 'bbb_update_test'); $queue = \Drupal::queue('update_fetch_tasks'); $this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty'); update_create_fetch_task($projecta); $this->assertEqual($queue->numberOfItems(), 1, 'Queue contains one item'); update_create_fetch_task($projectb); $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items'); // Try to add project a again. update_create_fetch_task($projecta); $this->assertEqual($queue->numberOfItems(), 2, 'Queue still contains two items'); // Clear storage and try again. update_storage_clear(); update_create_fetch_task($projecta); $this->assertEqual($queue->numberOfItems(), 2, 'Queue contains two items'); }