class-import-status.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Import
  6. */
  7. /**
  8. * Class WPSEO_ImportStatus.
  9. *
  10. * Holds the status of and message about imports.
  11. */
  12. class WPSEO_Import_Status {
  13. /**
  14. * The import status.
  15. *
  16. * @var bool
  17. */
  18. public $status = false;
  19. /**
  20. * The import message.
  21. *
  22. * @var string
  23. */
  24. private $msg = '';
  25. /**
  26. * The type of action performed.
  27. *
  28. * @var string
  29. */
  30. private $action;
  31. /**
  32. * WPSEO_Import_Status constructor.
  33. *
  34. * @param string $action The type of import action.
  35. * @param bool $status The status of the import.
  36. * @param string $msg Extra messages about the status.
  37. */
  38. public function __construct( $action, $status, $msg = '' ) {
  39. $this->action = $action;
  40. $this->status = $status;
  41. $this->msg = $msg;
  42. }
  43. /**
  44. * Get the import message.
  45. *
  46. * @return string Message about current status.
  47. */
  48. public function get_msg() {
  49. if ( $this->msg !== '' ) {
  50. return $this->msg;
  51. }
  52. if ( $this->status === false ) {
  53. /* translators: %s is replaced with the name of the plugin we're trying to find data from. */
  54. return __( '%s data not found.', 'wordpress-seo' );
  55. }
  56. return $this->get_default_success_message();
  57. }
  58. /**
  59. * Get the import action.
  60. *
  61. * @return string Import action type.
  62. */
  63. public function get_action() {
  64. return $this->action;
  65. }
  66. /**
  67. * Set the import action, set status to false.
  68. *
  69. * @param string $action The type of action to set as import action.
  70. *
  71. * @return void
  72. */
  73. public function set_action( $action ) {
  74. $this->action = $action;
  75. $this->status = false;
  76. }
  77. /**
  78. * Sets the importer status message.
  79. *
  80. * @param string $msg The message to set.
  81. *
  82. * @return void
  83. */
  84. public function set_msg( $msg ) {
  85. $this->msg = $msg;
  86. }
  87. /**
  88. * Sets the importer status.
  89. *
  90. * @param bool $status The status to set.
  91. *
  92. * @return WPSEO_Import_Status The current object.
  93. */
  94. public function set_status( $status ) {
  95. $this->status = (bool) $status;
  96. return $this;
  97. }
  98. /**
  99. * Returns a success message depending on the action.
  100. *
  101. * @return string Returns a success message for the current action.
  102. */
  103. private function get_default_success_message() {
  104. switch ( $this->action ) {
  105. case 'import':
  106. /* translators: %s is replaced with the name of the plugin we're importing data from. */
  107. return __( '%s data successfully imported.', 'wordpress-seo' );
  108. case 'cleanup':
  109. /* translators: %s is replaced with the name of the plugin we're removing data from. */
  110. return __( '%s data successfully removed.', 'wordpress-seo' );
  111. case 'detect':
  112. default:
  113. /* translators: %s is replaced with the name of the plugin we've found data from. */
  114. return __( '%s data found.', 'wordpress-seo' );
  115. }
  116. }
  117. }