private function configImport($io, StorageComparer $storage_comparer)
 {
     $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
     if ($config_importer->alreadyImporting()) {
         $io->success($this->trans('commands.config.import.messages.already-imported'));
     } else {
         try {
             if ($config_importer->validate()) {
                 $sync_steps = $config_importer->initialize();
                 foreach ($sync_steps as $step) {
                     $context = array();
                     do {
                         $config_importer->doSyncStep($step, $context);
                     } while ($context['finished'] < 1);
                 }
             }
         } catch (ConfigImporterException $e) {
             $message = 'The import failed due for the following reasons:' . "\n";
             $message .= implode("\n", $config_importer->getErrors());
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
         } catch (\Exception $e) {
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
         }
     }
 }
 /**
  * Tests the behavior of the theme registry class.
  */
 function testRaceCondition()
 {
     // The theme registry is not marked as persistable in case we don't have a
     // proper request.
     \Drupal::request()->setMethod('GET');
     $cid = 'test_theme_registry';
     // Directly instantiate the theme registry, this will cause a base cache
     // entry to be written in __construct().
     $cache = \Drupal::cache();
     $lock_backend = \Drupal::lock();
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Trigger a cache miss for an offset.
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.');
     // This will cause the ThemeRegistry class to write an updated version of
     // the cache entry when it is destroyed, usually at the end of the request.
     // Before that happens, manually delete the cache entry we created earlier
     // so that the new entry is written from scratch.
     \Drupal::cache()->delete($cid);
     // Destroy the class so that it triggers a cache write for the offset.
     $registry->destruct();
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Create a new instance of the class. Confirm that both the offset
     // requested previously, and one that has not yet been requested are both
     // available.
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry');
     $this->assertTrue($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry');
 }
 /**
  * Ensures that Stable overrides all relevant core templates.
  */
 public function testStableTemplateOverrides()
 {
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
     $registry->setThemeManager(\Drupal::theme());
     $registry_full = $registry->get();
     foreach ($registry_full as $hook => $info) {
         if (isset($info['template'])) {
             // Allow skipping templates.
             if (in_array($info['template'], $this->templatesToSkip)) {
                 continue;
             }
             $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');
         }
     }
 }
Example #4
0
 private function configImport(DrupalStyle $io, StorageComparer $storage_comparer)
 {
     $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
     if ($config_importer->alreadyImporting()) {
         $io->success($this->trans('commands.config.import.messages.already-imported'));
     } else {
         try {
             $config_importer->import();
             $io->info($this->trans('commands.config.import.messages.importing'));
         } catch (ConfigImporterException $e) {
             $message = 'The import failed due for the following reasons:' . "\n";
             $message .= implode("\n", $config_importer->getErrors());
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
         } catch (\Exception $e) {
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
         }
     }
 }
Example #5
0
 /**
  * Release the lock acquired for the thread in preSave().
  */
 protected function releaseThreadLock()
 {
     if ($this->threadLock) {
         \Drupal::lock()->release($this->threadLock);
         $this->threadLock = '';
     }
 }
Example #6
0
 /**
  * Tests that the theme registry can be altered by themes.
  */
 public function testThemeRegistryAlterByTheme()
 {
     /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
     $theme_handler = \Drupal::service('theme_handler');
     $theme_handler->install(['test_theme']);
     $theme_handler->setDefault('test_theme');
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
     $registry->setThemeManager(\Drupal::theme());
     $this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']);
 }
Example #7
0
 /**
  * @param $config
  *
  * @return mixed
  */
 protected function getNextCid()
 {
     $config = $this->getConfiguration();
     $nid = $config['nid'];
     $lock = \Drupal::lock();
     if ($lock->acquire('webform_component_insert_' . $nid, 5)) {
         $next_id_query = db_select('webform_component')->condition('nid', $nid);
         $next_id_query->addExpression('MAX(cid) + 1', 'cid');
         $cid = $next_id_query->execute()->fetchField();
         if ($cid == NULL) {
             $cid = 1;
         }
         $lock->release('webform_component_insert_' . $nid);
         return $cid;
     } else {
         \Drupal::logger('webform')->critical('A Webform component could not be saved because a timeout occurred while trying to acquire a lock for the node. Details: <pre>@component</pre>', array('@component' => print_r($config, TRUE)));
         return NULL;
     }
 }
Example #8
0
 /**
  * Tests the lock() method.
  *
  * @covers ::lock
  */
 public function testLock()
 {
     $this->setMockContainerService('lock');
     $this->assertNotNull(\Drupal::lock());
 }
Example #9
0
 /**
  * Gets all the service dependencies from \Drupal.
  *
  * Since the ConfigImporter handles module installation the kernel and the
  * container can be rebuilt and altered during processing. It is necessary to
  * keep the services used by the importer in sync.
  */
 protected function reInjectMe()
 {
     $this->eventDispatcher = \Drupal::service('event_dispatcher');
     $this->configManager = \Drupal::service('config.manager');
     $this->lock = \Drupal::lock();
     $this->typedConfigManager = \Drupal::service('config.typed');
     $this->moduleHandler = \Drupal::moduleHandler();
     $this->themeHandler = \Drupal::service('theme_handler');
     $this->stringTranslation = \Drupal::service('string_translation');
 }
Example #10
0
 /**
  * Releases a lock for this source.
  *
  * @return self
  *   Returns the Feed for method chaining.
  */
 protected function releaseLock()
 {
     \Drupal::lock()->release("feeds_feed_{$this->id()}");
     return $this;
 }