44namespace Discorgento \Queue \Console \Command ;
55
66use Discorgento \Core \Helper \Data as CoreHelper ;
7- use Discorgento \Queue \Model \MessageRepository ;
8- use Discorgento \Queue \Model \ResourceModel \Message \CollectionFactory as MessagesCollectionFactory ;
7+ use Discorgento \Queue \Command \ClearCommand ;
98use Symfony \Component \Console \Command \Command ;
109use Symfony \Component \Console \Helper \ProgressBarFactory ;
1110use Symfony \Component \Console \Input \InputInterface ;
1413
1514class Clear extends Command
1615{
16+ /** @var ClearCommand */
17+ private $ clearCommand ;
18+
1719 /** @var ConfirmationQuestionFactory */
1820 private $ confirmationQuestionFactory ;
1921
2022 /** @var CoreHelper */
2123 private $ coreHelper ;
2224
23- /** @var MessagesCollectionFactory */
24- private $ messagesCollectionFactory ;
25-
26- /** @var MessageRepository */
27- private $ messageRepository ;
28-
2925 /** @var ProgressBarFactory */
3026 private $ progressBarFactory ;
3127
3228 // phpcs:ignore
3329 public function __construct (
30+ ClearCommand $ clearCommand ,
3431 ConfirmationQuestionFactory $ confirmationQuestionFactory ,
3532 CoreHelper $ coreHelper ,
36- MessagesCollectionFactory $ messagesCollectionFactory ,
37- MessageRepository $ messageRepository ,
3833 ProgressBarFactory $ progressBarFactory ,
3934 string $ name = null
4035 ) {
4136 parent ::__construct ($ name );
37+
38+ $ this ->clearCommand = $ clearCommand ;
4239 $ this ->confirmationQuestionFactory = $ confirmationQuestionFactory ;
4340 $ this ->coreHelper = $ coreHelper ;
44- $ this ->messagesCollectionFactory = $ messagesCollectionFactory ;
45- $ this ->messageRepository = $ messageRepository ;
4641 $ this ->progressBarFactory = $ progressBarFactory ;
4742 }
4843
@@ -62,10 +57,8 @@ protected function configure()
6257 */
6358 protected function execute (InputInterface $ input , OutputInterface $ output )
6459 {
65- $ messages = $ this ->messagesCollectionFactory ->create ();
66-
67- $ totalMessages = $ messages ->getSize ();
68- if ($ totalMessages < 1 ) {
60+ $ total = $ this ->clearCommand ->getTotal ();
61+ if ($ total < 1 ) {
6962 $ output ->writeln ("<error>There's no pending jobs.</error> " );
7063
7164 return 0 ;
@@ -87,11 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
8780
8881 $ progressBar = $ this ->progressBarFactory ->create ([
8982 'output ' => $ output ,
90- 'max ' => $ totalMessages ,
83+ 'max ' => $ total ,
9184 ]);
9285
93- foreach ($ messages as $ message ) {
94- $ this ->messageRepository ->delete ($ message );
86+ foreach ($ this ->clearCommand ->iterator () as $ clearedMessage ) {
9587 $ progressBar ->advance ();
9688 }
9789
0 commit comments