GearmanCacheWarmupCommand.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Gearman Bundle for Symfony2
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * Feel free to edit as you please, and have fun.
  9. *
  10. * @author Marc Morera <yuhu@mmoreram.com>
  11. */
  12. namespace Mmoreram\GearmanBundle\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Mmoreram\GearmanBundle\Command\Abstracts\AbstractGearmanCommand;
  16. use Mmoreram\GearmanBundle\Service\GearmanCacheWrapper;
  17. /**
  18. * Warms up all cache data
  19. *
  20. * @since 2.3.1
  21. */
  22. class GearmanCacheWarmupCommand extends AbstractGearmanCommand
  23. {
  24. /**
  25. * @var GearmanCacheWrapper
  26. *
  27. * GearmanCacheWrapper
  28. */
  29. protected $gearmanCacheWrapper;
  30. /**
  31. * Set the GearmanCacheWrapper instance
  32. *
  33. * @param GearmanCacheWrapper $gearmanCacheWrapper GearmanCacheWrapper
  34. *
  35. * @return GearmanCacheWarmupCommand self Object
  36. */
  37. public function setGearmanCacheWrapper(GearmanCacheWrapper $gearmanCacheWrapper)
  38. {
  39. $this->gearmanCacheWrapper = $gearmanCacheWrapper;
  40. return $this;
  41. }
  42. /**
  43. * Set the kernel environment
  44. /**
  45. * Console Command configuration
  46. */
  47. protected function configure()
  48. {
  49. $this
  50. ->setName('gearman:cache:warmup')
  51. ->setAliases(array(
  52. 'cache:gearman:warmup'
  53. ))
  54. ->setDescription('Warms up gearman cache data');
  55. }
  56. /**
  57. * Executes the current command.
  58. *
  59. * @param InputInterface $input An InputInterface instance
  60. * @param OutputInterface $output An OutputInterface instance
  61. *
  62. * @return integer 0 if everything went fine, or an error code
  63. *
  64. * @throws \LogicException When this abstract class is not implemented
  65. */
  66. protected function execute(InputInterface $input, OutputInterface $output)
  67. {
  68. if (
  69. !$input->getOption('quiet')
  70. ) {
  71. $kernelEnvironment = $this
  72. ->kernel
  73. ->getEnvironment();
  74. $output->writeln('Warming the cache for the ' . $kernelEnvironment . ' environment');
  75. }
  76. $this
  77. ->gearmanCacheWrapper
  78. ->warmup('');
  79. }
  80. }