You are here

public static function EntityUpdate::safeUpdateMain in Entity Update 8

Same name and namespace in other branches
  1. 2.0.x src/EntityUpdate.php \Drupal\entity_update\EntityUpdate::safeUpdateMain()

Update all entities.

Return value

bool Update is done or FAIL

10 calls to EntityUpdate::safeUpdateMain()
drush_entity_update in ./entity_update.drush.inc
Call back function of entity-update.
EntityUpdateExec::submitFormSafe in src/Form/EntityUpdateExec.php
Run updates using safe (full) method.
EntityUpdateFunctionsTest::testEntityUpdateAll in modules/entity_update_tests/src/Tests/EntityUpdateFunctionsTest.php
Entity update function : all.
EntityUpdateFunctionsTest::testEntityUpdateClean in modules/entity_update_tests/src/Tests/EntityUpdateFunctionsTest.php
Entity update function : clean.
EntityUpdateFunctionsTest::testEntityUpdateSel in modules/entity_update_tests/src/Tests/EntityUpdateFunctionsTest.php
Update a selected entity type.

... See full list

File

src/EntityUpdate.php, line 60

Class

EntityUpdate
EntityUpdate Main Class.

Namespace

Drupal\entity_update

Code

public static function safeUpdateMain(EntityTypeInterface $entity_type = NULL) {

  // Get entitiy types to update.
  $entity_change_summerys = self::getEntityTypesToUpdate();
  if (empty($entity_change_summerys)) {
    EntityUpdatePrint::drushLog('No entities to update.', 'cancel');
    return TRUE;
  }

  // Check entity type to update.
  if ($entity_type) {
    $entity_type_id = $entity_type
      ->id();
    foreach ($entity_change_summerys as $type_id => $entity_type_changes) {
      if ($type_id !== $entity_type_id) {
        unset($entity_change_summerys[$type_id]);
      }
    }

    // Check update for $entity_type_id.
    if (empty($entity_change_summerys)) {
      EntityUpdatePrint::drushLog("No updates for {$entity_type_id}", 'cancel');
      return TRUE;
    }
    else {

      // Run Update for $entity_type.
      return self::safeUpdateEntityType($entity_type);
    }
    return FALSE;
  }

  // Flags to select install / uninstall methode.
  $flg_has_install = FALSE;
  $flg_has_uninstall = FALSE;

  // Select the method to use.
  foreach ($entity_change_summerys as $entity_type_changes) {
    foreach ($entity_type_changes as $entity_change_summ) {
      if (strstr($entity_change_summ, "uninstalled")) {
        $flg_has_uninstall = TRUE;
      }
      else {
        $flg_has_install = TRUE;
      }
    }
  }

  // Execute Update all entities.
  if (!$flg_has_install && !$flg_has_uninstall) {

    // Install Or Uninstall not found.
    EntityUpdatePrint::drushLog('Entity install / Uninstall not found.', 'cancel');
    return FALSE;
  }
  elseif ($flg_has_install && $flg_has_uninstall) {
    EntityUpdatePrint::drushLog('Has fields to install and to uninstall. Do one action at a time.', 'cancel');
    return FALSE;
  }
  elseif ($flg_has_install) {
    return self::safeUpdateInstallFields();
  }
  elseif ($flg_has_uninstall) {
    return self::safeUpdateUninstallFields($entity_change_summerys);
  }
  EntityUpdatePrint::drushLog('UNKNOWN ERROR.', 'error');
  return FALSE;
}