コード例 #1
0
 /**
  * Tests creating and deleting a multi-field index when there are no existing entities.
  */
 public function testEntityIndexCreateDeleteWithoutData()
 {
     // Add an entity index and ensure the update manager reports that as an
     // update to the entity type.
     $this->addEntityIndex();
     $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
     $expected = array('entity_test_update' => array(t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()))));
     $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
     // Run the update and ensure the new index is created.
     $this->entityDefinitionUpdateManager->applyUpdates();
     $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created.');
     // Remove the index and ensure the update manager reports that as an
     // update to the entity type.
     $this->removeEntityIndex();
     $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
     $expected = array('entity_test_update' => array(t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()))));
     $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
     // Run the update and ensure the index is deleted.
     $this->entityDefinitionUpdateManager->applyUpdates();
     $this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index deleted.');
     // Test that composite indexes are handled correctly when dropping and
     // re-creating one of their columns.
     $this->addEntityIndex();
     $this->entityDefinitionUpdateManager->applyUpdates();
     $storage_definition = $this->entityDefinitionUpdateManager->getFieldStorageDefinition('name', 'entity_test_update');
     $this->entityDefinitionUpdateManager->updateFieldStorageDefinition($storage_definition);
     $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created.');
     $this->entityDefinitionUpdateManager->uninstallFieldStorageDefinition($storage_definition);
     $this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index deleted.');
     $this->entityDefinitionUpdateManager->installFieldStorageDefinition('name', 'entity_test_update', 'entity_test', $storage_definition);
     $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created again.');
 }
コード例 #2
0
 /**
  * Tests creating and deleting a multi-field index when there are no existing entities.
  */
 public function testEntityIndexCreateDeleteWithoutData()
 {
     // Add an entity index and ensure the update manager reports that as an
     // update to the entity type.
     $this->addEntityIndex();
     $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
     $expected = array('entity_test_update' => array(t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()))));
     $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
     // Run the update and ensure the new index is created.
     $this->entityDefinitionUpdateManager->applyUpdates();
     $this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index created.');
     // Remove the index and ensure the update manager reports that as an
     // update to the entity type.
     $this->removeEntityIndex();
     $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
     $expected = array('entity_test_update' => array(t('Update the %entity_type entity type.', array('%entity_type' => $this->entityManager->getDefinition('entity_test_update')->getLabel()))));
     $this->assertIdentical($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
     // Run the update and ensure the index is deleted.
     $this->entityDefinitionUpdateManager->applyUpdates();
     $this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update__new_index'), 'Index deleted.');
 }
コード例 #3
0
ファイル: DbUpdateController.php プロジェクト: brstde/gap1
 /**
  * Renders a list of available database updates.
  *
  * @return array
  *   A render array.
  */
 protected function selection()
 {
     // Make sure there is no stale theme registry.
     $this->cache->deleteAll();
     $count = 0;
     $incompatible_count = 0;
     $build['start'] = array('#tree' => TRUE, '#type' => 'details');
     // Ensure system.module's updates appear first.
     $build['start']['system'] = array();
     $updates = update_get_update_list();
     $starting_updates = array();
     $incompatible_updates_exist = FALSE;
     foreach ($updates as $module => $update) {
         if (!isset($update['start'])) {
             $build['start'][$module] = array('#type' => 'item', '#title' => $module . ' module', '#markup' => $update['warning'], '#prefix' => '<div class="messages messages--warning">', '#suffix' => '</div>');
             $incompatible_updates_exist = TRUE;
             continue;
         }
         if (!empty($update['pending'])) {
             $starting_updates[$module] = $update['start'];
             $build['start'][$module] = array('#type' => 'hidden', '#value' => $update['start']);
             $build['start'][$module . '_updates'] = array('#theme' => 'item_list', '#items' => $update['pending'], '#title' => $module . ' module');
         }
         if (isset($update['pending'])) {
             $count = $count + count($update['pending']);
         }
     }
     // Find and label any incompatible updates.
     foreach (update_resolve_dependencies($starting_updates) as $data) {
         if (!$data['allowed']) {
             $incompatible_updates_exist = TRUE;
             $incompatible_count++;
             $module_update_key = $data['module'] . '_updates';
             if (isset($build['start'][$module_update_key]['#items'][$data['number']])) {
                 if ($data['missing_dependencies']) {
                     $text = $this->t('This update will been skipped due to the following missing dependencies:') . '<em>' . implode(', ', $data['missing_dependencies']) . '</em>';
                 } else {
                     $text = $this->t("This update will be skipped due to an error in the module's code.");
                 }
                 $build['start'][$module_update_key]['#items'][$data['number']] .= '<div class="warning">' . $text . '</div>';
             }
             // Move the module containing this update to the top of the list.
             $build['start'] = array($module_update_key => $build['start'][$module_update_key]) + $build['start'];
         }
     }
     // Warn the user if any updates were incompatible.
     if ($incompatible_updates_exist) {
         drupal_set_message($this->t('Some of the pending updates cannot be applied because their dependencies were not met.'), 'warning');
     }
     // If there are entity definition updates, display their summary.
     if ($this->entityDefinitionUpdateManager->needsUpdates()) {
         $entity_build = array();
         $summary = $this->entityDefinitionUpdateManager->getChangeSummary();
         foreach ($summary as $entity_type_id => $items) {
             $entity_update_key = 'entity_type_updates_' . $entity_type_id;
             $entity_build[$entity_update_key] = array('#theme' => 'item_list', '#items' => $items, '#title' => $entity_type_id . ' entity type');
             $count++;
         }
         // Display these above the module updates, since they will be run first.
         $build['start'] = $entity_build + $build['start'];
     }
     if (empty($count)) {
         drupal_set_message($this->t('No pending updates.'));
         unset($build);
         $build['links'] = array('#theme' => 'links', '#links' => $this->helpfulLinks());
         // No updates to run, so caches won't get flushed later.  Clear them now.
         drupal_flush_all_caches();
     } else {
         $build['help'] = array('#markup' => '<p>' . $this->t('The version of Drupal you are updating from has been automatically detected.') . '</p>', '#weight' => -5);
         if ($incompatible_count) {
             $build['start']['#title'] = $this->formatPlural($count, '1 pending update (@number_applied to be applied, @number_incompatible skipped)', '@count pending updates (@number_applied to be applied, @number_incompatible skipped)', array('@number_applied' => $count - $incompatible_count, '@number_incompatible' => $incompatible_count));
         } else {
             $build['start']['#title'] = $this->formatPlural($count, '1 pending update', '@count pending updates');
         }
         $url = new Url('system.db_update', array('op' => 'run'));
         $build['link'] = array('#type' => 'link', '#title' => $this->t('Apply pending updates'), '#attributes' => array('class' => array('button', 'button--primary')), '#weight' => 5, '#url' => $url);
     }
     return $build;
 }