You are here

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

Same name and namespace in other branches
  1. 8 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 drush/entity_update.drush8.inc
Call back function of entity-update.
EntityUpdateExec::submitFormSafe in src/Form/EntityUpdateExec.php
Run updates using safe (full) method.
EntityUpdateFunctionsTest::testEntityUpdateAll in tests/src/Functional/EntityUpdateFunctionsTest.php
Entity update function : all.
EntityUpdateFunctionsTest::testEntityUpdateClean in tests/src/Functional/EntityUpdateFunctionsTest.php
Entity update function : clean.
EntityUpdateFunctionsTest::testEntityUpdateSel in tests/src/Functional/EntityUpdateFunctionsTest.php
Update a selected entity type.

... See full list

File

src/EntityUpdate.php, line 62

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_updated = FALSE;
  $flg_has_install = 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, "updated")) {
        $flg_has_updated = TRUE;
      }
      elseif (strstr($entity_change_summ, "uninstalled")) {
        $flg_has_updated = TRUE;
      }
      else {
        $flg_has_install = TRUE;
      }
    }
  }

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

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