You are here

public static function EntityUpdate::basicUpdate in Entity Update 2.0.x

Same name and namespace in other branches
  1. 8 src/EntityUpdate.php \Drupal\entity_update\EntityUpdate::basicUpdate()

Update all empty entities.

7 calls to EntityUpdate::basicUpdate()
drush_entity_update in drush/entity_update.drush8.inc
Call back function of entity-update.
EntityUpdateExec::submitFormBasic in src/Form/EntityUpdateExec.php
Run updates using basic method.
EntityUpdateFunctionsTest::testEntityUpdateAdvanced in tests/src/Functional/EntityUpdateFunctionsTest.php
Entity advanced update simulation.
EntityUpdateFunctionsTest::testEntityUpdateBasic in tests/src/Functional/EntityUpdateFunctionsTest.php
Entity update function : basic.
EntityUpdateFunctionsTest::testEntityUpdateBasicForce in tests/src/Functional/EntityUpdateFunctionsTest.php
Entity update function : basic --force.

... See full list

File

src/EntityUpdate.php, line 17

Class

EntityUpdate
EntityUpdate Main Class.

Namespace

Drupal\entity_update

Code

public static function basicUpdate($force = FALSE) {

  // Check all updateble entities are empty.
  $flgOK = TRUE;
  try {
    $list = self::getEntityTypesToUpdate();
    foreach ($list as $item => $entity_type_changes) {
      if (!empty(\Drupal::entityQuery($item)
        ->execute())) {
        $flgOK = FALSE;
        EntityUpdatePrint::drushLog("The entity '{$item}' is not empty", 'warning');
      }
    }
  } catch (\Exception $e) {
    EntityUpdatePrint::drushLog($e
      ->getMessage(), 'error', NULL, TRUE);
    $flgOK = FALSE;
  }

  // Return if one of the entity has data.
  if (!$flgOK && !$force) {
    EntityUpdatePrint::drushLog("Cant update as basic, use --all or --force option", 'cancel', NULL, TRUE);
    EntityUpdatePrint::drushPrint("Example : drush upe --basic --force --nobackup");
    return FALSE;
  }

  // Update.
  try {
    \Drupal::classResolver()
      ->getInstanceFromDefinition(CustomEntityDefinitionUpdateManager::class)
      ->applyUpdates();

    // No need to update = OK.
    return !\Drupal::entityDefinitionUpdateManager()
      ->needsUpdates();
  } catch (\Exception $e) {
    EntityUpdatePrint::drushLog($e
      ->getMessage(), 'warning', NULL, TRUE);
  }
  return FALSE;
}