/** * Tests the keyValueExpirable() method. */ public function testKeyValueExpirable() { $keyvalue = $this->getMockBuilder('Drupal\\Core\\KeyValueStore\\KeyValueExpirableFactory')->disableOriginalConstructor()->getMock(); $keyvalue->expects($this->once())->method('get')->with('test_collection')->will($this->returnValue(TRUE)); $this->setMockContainerService('keyvalue.expirable', $keyvalue); $this->assertNotNull(\Drupal::keyValueExpirable('test_collection')); }
public function testLocaleUpdateNotDevelopmentRelease() { // Set available Drupal releases for test. $available = array('title' => 'Drupal core', 'short_name' => 'drupal', 'type' => 'project_core', 'api_version' => '8.x', 'project_status' => 'unsupported', 'link' => 'https://www.drupal.org/project/drupal', 'terms' => '', 'releases' => array('8.0.0-alpha110' => array('name' => 'drupal 8.0.0-alpha110', 'version' => '8.0.0-alpha110', 'tag' => '8.0.0-alpha110', 'version_major' => '8', 'version_minor' => '0', 'version_patch' => '0', 'version_extra' => 'alpha110', 'status' => 'published', 'release_link' => 'https://www.drupal.org/node/2316617', 'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha110.tar.gz', 'date' => '1407344628', 'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7', 'filesize' => '9172832', 'files' => '', 'terms' => array()), '8.0.0-alpha100' => array('name' => 'drupal 8.0.0-alpha100', 'version' => '8.0.0-alpha100', 'tag' => '8.0.0-alpha100', 'version_major' => '8', 'version_minor' => '0', 'version_patch' => '0', 'version_extra' => 'alpha100', 'status' => 'published', 'release_link' => 'https://www.drupal.org/node/2316617', 'download_link' => 'http://ftp.drupal.org/files/projects/drupal-8.0.0-alpha100.tar.gz', 'date' => '1407344628', 'mdhash' => '9d71afdd0ce541f2ff5ca2fbbca00df7', 'filesize' => '9172832', 'files' => '', 'terms' => array()))); $available['last_fetch'] = REQUEST_TIME; \Drupal::keyValueExpirable('update_available_releases')->setWithExpire('drupal', $available, 10); $projects = locale_translation_build_projects(); $this->verbose($projects['drupal']->info['version']); $this->assertEqual($projects['drupal']->info['version'], '8.0.0-alpha110', 'The first release with the same major release number which is not a development release.'); }
/** * Obtains release info for all installed projects via update.module. * * @see update_get_available(). * @see \Drupal\update\Controller\UpdateController::updateStatusManually() */ 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.yml files. \Drupal::keyValueExpirable('update')->deleteMultiple(array('update_project_projects', 'update_project_data')); // From update_get_available(): Iterate all projects and create a fetch task // for those we have no information or is obsolete. $available = \Drupal::keyValueExpirable('update_available_releases')->getAll(); $update_projects = \Drupal::service('update.manager')->getProjects(); foreach ($update_projects as $key => $project) { if (empty($available[$key])) { \Drupal::service('update.processor')->createFetchTask($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) { \Drupal::service('update.processor')->createFetchTask($project); } } // Set a batch to process all pending tasks. $batch = array('operations' => array(array(array(\Drupal::service('update.manager'), 'fetchDataBatch'), 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(); return \Drupal::keyValueExpirable('update_available_releases')->getAll(); }
public static function runSubscribeBatch(SubscriptionInterface $subscription) { switch ($subscription->getState()) { case 'subscribing': $mode = 'subscribe'; break; case 'unsubscribing': $mode = 'unsubscribe'; // The subscription has been deleted, store it for a bit to handle the // response. $id = $subscription->getToken() . ':' . $subscription->id(); \Drupal::keyValueExpirable('feeds_push_unsubscribe')->setWithExpire($id, $subscription, 3600); break; default: throw new \LogicException('A subscription was found in an invalid state.'); } $args = ['feeds_subscription_id' => $subscription->id(), 'feeds_push_token' => $subscription->getToken()]; $callback = \Drupal::url('entity.feeds_feed.subscribe', $args, ['absolute' => TRUE]); $post_body = ['hub.callback' => $callback, 'hub.mode' => $mode, 'hub.topic' => $subscription->getTopic(), 'hub.secret' => $subscription->getSecret()]; $response = static::retry($subscription, $post_body); // Response failed. if (!$response || $response->getStatusCode() != 202) { switch ($subscription->getState()) { case 'subscribing': // Deleting the subscription will make it re-subscribe on the next // import. $subscription->delete(); break; case 'unsubscribing': // Unsubscribe failed. The hub should give up eventually. break; } } }