EntityStorageSchemaInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Drupal\Core\Entity\Schema;
  3. use Drupal\Core\Entity\EntityTypeInterface;
  4. use Drupal\Core\Entity\EntityTypeListenerInterface;
  5. /**
  6. * Defines the interface for entity storage schema handler classes.
  7. *
  8. * An entity type's storage schema handler is responsible for creating the
  9. * storage backend's schema that the entity type's storage handler needs for
  10. * storing its entities. For example, if the storage handler is for a SQL
  11. * backend, then the storage schema handler is responsible for creating the
  12. * needed tables. During the application lifetime, an entity type's definition
  13. * can change in a way that requires changes to the storage schema, so this
  14. * interface defines methods for that as well.
  15. *
  16. * @see \Drupal\Core\Entity\EntityStorageInterface
  17. */
  18. interface EntityStorageSchemaInterface extends EntityTypeListenerInterface {
  19. /**
  20. * Checks if the changes to the entity type requires storage schema changes.
  21. *
  22. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  23. * The updated entity type definition.
  24. * @param \Drupal\Core\Entity\EntityTypeInterface $original
  25. * The original entity type definition.
  26. *
  27. * @return bool
  28. * TRUE if storage schema changes are required, FALSE otherwise.
  29. */
  30. public function requiresEntityStorageSchemaChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original);
  31. /**
  32. * Checks if existing data would be lost if the schema changes were applied.
  33. *
  34. * If there are no schema changes needed, then no data needs to be migrated,
  35. * but it is not the responsibility of this function to recheck what
  36. * requiresEntityStorageSchemaChanges() checks. Rather, the meaning of what
  37. * this function returns when requiresEntityStorageSchemaChanges() returns
  38. * FALSE is undefined. Callers are expected to only call this function when
  39. * requiresEntityStorageSchemaChanges() is TRUE.
  40. *
  41. * This function can return FALSE if any of these conditions apply:
  42. * - There are no existing entities for the entity type.
  43. * - There are existing entities, but the schema changes can be applied
  44. * without losing their data (e.g., if the schema changes can be performed
  45. * by altering tables rather than dropping and recreating them).
  46. * - The only entity data that would be lost are ones that are not valid for
  47. * the new definition (e.g., if changing an entity type from revisionable
  48. * to non-revisionable, then it's okay to drop data for the non-default
  49. * revision).
  50. *
  51. * When this function returns FALSE, site administrators will be unable to
  52. * perform an automated update, and will instead need to perform a site
  53. * migration or invoke some custom update process.
  54. *
  55. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  56. * The updated entity type definition.
  57. * @param \Drupal\Core\Entity\EntityTypeInterface $original
  58. * The original entity type definition.
  59. *
  60. * @return bool
  61. * TRUE if data migration is required, FALSE otherwise.
  62. *
  63. * @see self::requiresEntityStorageSchemaChanges()
  64. */
  65. public function requiresEntityDataMigration(EntityTypeInterface $entity_type, EntityTypeInterface $original);
  66. }