You are here

public static function EntityCheck::showEntityStatusCli in Entity Update 8

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

Print entity status to the terminal.

Return value

bool The entity types are updatable even having data.

1 call to EntityCheck::showEntityStatusCli()
drush_entity_update in ./entity_update.drush.inc
Call back function of entity-update.

File

src/EntityCheck.php, line 111

Class

EntityCheck
EntityCheck Main Class.

Namespace

Drupal\entity_update

Code

public static function showEntityStatusCli() {
  $flg_updatable = TRUE;
  $esp = "    ";
  $arr = "->  ";
  $list = EntityUpdate::getEntityTypesToUpdate();
  if (empty($list)) {
    EntityUpdatePrint::drushPrint(' -> ALl Entities are up to date');
  }
  else {
    foreach ($list as $item => $entity_type_changes) {
      EntityUpdatePrint::drushPrint(" -> {$item} . Change(s) : " . count($entity_type_changes));
      $flg_has_install = FALSE;
      $flg_has_uninstall = FALSE;
      $flg_has_update = FALSE;

      // Print change details and check install/uninstall.
      foreach ($entity_type_changes as $entity_change_summ) {
        EntityUpdatePrint::drushPrint($esp . strip_tags($entity_change_summ));
        if (strstr($entity_change_summ, "updated")) {
          $flg_has_update = TRUE;
        }
        elseif (strstr($entity_change_summ, "uninstalled")) {
          $flg_has_uninstall = TRUE;
        }
        else {
          $flg_has_install = TRUE;
        }
      }

      // Print update instruction.
      if ($flg_has_update || $flg_has_install && $flg_has_uninstall) {

        // Check has data.
        if (empty(\Drupal::entityQuery($item)
          ->execute())) {
          EntityUpdatePrint::drushLog("{$esp}{$arr}" . "Entity type '{$item}' is updatable.", 'ok');
          EntityUpdatePrint::drushPrint("{$esp}{$arr}" . "Use: drush upe --basic");
        }
        else {
          EntityUpdatePrint::drushLog("{$esp}{$arr}" . "Multiple actions detected on '{$item}'.", 'warning');
          EntityUpdatePrint::drushLog("{$esp}{$arr}" . "The entity '{$item}' is not empty", 'warning');
          EntityUpdatePrint::drushPrint("{$esp}{$arr}" . "Try: drush upe --basic --force");
          EntityUpdatePrint::drushPrint("{$esp}{$arr}" . "Refer to the documentation");
        }
        $flg_updatable = FALSE;
      }
      else {
        EntityUpdatePrint::drushLog("{$esp}{$arr}" . "Entity type '{$item}' is updatable.", 'ok');
        EntityUpdatePrint::drushPrint("{$esp}{$arr}" . "Use: drush upe {$item}");
      }
      EntityUpdatePrint::drushPrint("");
    }
  }
  return $flg_updatable;
}