Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / drush / drush / src / Drupal / Commands / core / EntityCommands.php
index dd85863b3efb6b868af11a65f7a0f46ae5962494..c425ad7a7f71480e20c5cefe5faba515a6726943 100644 (file)
@@ -35,6 +35,8 @@ class EntityCommands extends DrushCommands
      *   Delete all shortcut entities.
      * @usage drush entity:delete node 22,24
      *   Delete nodes 22 and 24.
+     * @usage drush entity:delete user
+     *   Delete all users except uid=1.
      *
      * @command entity:delete
      * @aliases edel,entity-delete
@@ -51,10 +53,18 @@ class EntityCommands extends DrushCommands
         } else {
             $entities = $storage->loadMultiple();
         }
+
+        // Don't delete uid=1, uid=0.
+        if ($entity_type == 'user') {
+            unset($entities[1]);
+            unset($entities[0]);
+        }
+
         if (empty($entities)) {
-            throw new \Exception(dt('No matching entities found.'));
+            $this->logger()->success(dt('No matching entities found.'));
+        } else {
+            $storage->delete($entities);
+            $this->logger()->success(dt('Deleted !type entity Ids: !ids', ['!type' => $entity_type, '!ids' => implode(', ', array_keys($entities))]));
         }
-        $storage->delete($entities);
-        $this->logger()->success(dt('Deleted !type entity Ids: !ids', ['!type' => $entity_type, '!ids' => implode(', ', array_keys($entities))]));
     }
 }