public static function EntityUpdate::basicUpdate in Entity Update 8
Same name and namespace in other branches
- 2.0.x src/EntityUpdate.php \Drupal\entity_update\EntityUpdate::basicUpdate()
 
Update all empty entities.
6 calls to EntityUpdate::basicUpdate()
- drush_entity_update in ./
entity_update.drush.inc  - Call back function of entity-update.
 - EntityUpdateExec::submitFormBasic in src/
Form/ EntityUpdateExec.php  - Run updates using basic method.
 - EntityUpdateFunctionsTest::testEntityUpdateAdvanced in modules/
entity_update_tests/ src/ Tests/ EntityUpdateFunctionsTest.php  - Entity advanced update simulation.
 - EntityUpdateFunctionsTest::testEntityUpdateBasic in modules/
entity_update_tests/ src/ Tests/ EntityUpdateFunctionsTest.php  - Entity update function : basic.
 - EntityUpdateFunctionsTest::testEntityUpdateBasicForce in modules/
entity_update_tests/ src/ Tests/ EntityUpdateFunctionsTest.php  - Entity update function : basic --force.
 
File
- src/
EntityUpdate.php, line 17  
Class
- EntityUpdate
 - EntityUpdate Main Class.
 
Namespace
Drupal\entity_updateCode
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::entityDefinitionUpdateManager()
      ->applyUpdates();
    // No need to update = OK.
    return !\Drupal::entityDefinitionUpdateManager()
      ->needsUpdates();
  } catch (\Exception $e) {
    EntityUpdatePrint::drushLog($e
      ->getMessage(), 'warning', NULL, TRUE);
  }
  return FALSE;
}