UpToDateDeclarativeSchema.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\Setup\Declaration\Schema;
  8. use Magento\Framework\Setup\Declaration\Schema\Diff\SchemaDiff;
  9. use Magento\Framework\Setup\UpToDateValidatorInterface;
  10. /**
  11. * Allows to validate if schema is up to date or not
  12. */
  13. class UpToDateDeclarativeSchema implements UpToDateValidatorInterface
  14. {
  15. /**
  16. * @var SchemaConfigInterface
  17. */
  18. private $schemaConfig;
  19. /**
  20. * @var SchemaDiff
  21. */
  22. private $schemaDiff;
  23. /**
  24. * UpToDateSchema constructor.
  25. * @param SchemaConfigInterface $schemaConfig
  26. * @param SchemaDiff $schemaDiff
  27. */
  28. public function __construct(
  29. SchemaConfigInterface $schemaConfig,
  30. SchemaDiff $schemaDiff
  31. ) {
  32. $this->schemaConfig = $schemaConfig;
  33. $this->schemaDiff = $schemaDiff;
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getNotUpToDateMessage() : string
  39. {
  40. return 'Declarative Schema is not up to date';
  41. }
  42. /**
  43. * @return bool
  44. */
  45. public function isUpToDate() : bool
  46. {
  47. $declarativeSchema = $this->schemaConfig->getDeclarationConfig();
  48. $dbSchema = $this->schemaConfig->getDbConfig();
  49. $diff = $this->schemaDiff->diff($declarativeSchema, $dbSchema);
  50. return empty($diff->getAll());
  51. }
  52. }