Skip to content

Commit

Permalink
Merge pull request #1601 from magento-engcom/2.1-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.1-develop
  • Loading branch information
vrann authored Oct 19, 2017
2 parents ced998f + eff2592 commit 13d3888
Show file tree
Hide file tree
Showing 15 changed files with 890 additions and 6 deletions.
3 changes: 1 addition & 2 deletions app/code/Magento/Cron/Console/Command/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Cron\Console\Command;

use Symfony\Component\Console\Command\Command;
Expand Down Expand Up @@ -94,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
/** @var \Magento\Framework\App\Cron $cronObserver */
$cronObserver = $objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]);
$cronObserver = $objectManager->create(\Magento\Framework\App\Cron::class, ['parameters' => $params]);
$cronObserver->launch();
$output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
}
Expand Down
79 changes: 79 additions & 0 deletions app/code/Magento/Cron/Console/Command/CronInstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cron\Console\Command;

use Magento\Framework\Crontab\CrontabManagerInterface;
use Magento\Framework\Crontab\TasksProviderInterface;
use Magento\Framework\Exception\LocalizedException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputOption;

/**
* CronInstallCommand installs Magento cron tasks
*/
class CronInstallCommand extends Command
{
/**
* @var CrontabManagerInterface
*/
private $crontabManager;

/**
* @var TasksProviderInterface
*/
private $tasksProvider;

/**
* @param CrontabManagerInterface $crontabManager
* @param TasksProviderInterface $tasksProvider
*/
public function __construct(
CrontabManagerInterface $crontabManager,
TasksProviderInterface $tasksProvider
) {
$this->crontabManager = $crontabManager;
$this->tasksProvider = $tasksProvider;

parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('cron:install')
->setDescription('Generates and installs crontab for current user')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force install tasks');

parent::configure();
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->crontabManager->getTasks() && !$input->getOption('force')) {
$output->writeln('<error>Crontab has already been generated and saved</error>');
return Cli::RETURN_FAILURE;
}

try {
$this->crontabManager->saveTasks($this->tasksProvider->getTasks());
} catch (LocalizedException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Cli::RETURN_FAILURE;
}

$output->writeln('<info>Crontab has been generated and saved</info>');

return Cli::RETURN_SUCCESS;
}
}
62 changes: 62 additions & 0 deletions app/code/Magento/Cron/Console/Command/CronRemoveCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cron\Console\Command;

use Magento\Framework\Crontab\CrontabManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;

/**
* CronRemoveCommand removes Magento cron tasks
*/
class CronRemoveCommand extends Command
{
/**
* @var CrontabManagerInterface
*/
private $crontabManager;

/**
* @param CrontabManagerInterface $crontabManager
*/
public function __construct(CrontabManagerInterface $crontabManager)
{
$this->crontabManager = $crontabManager;

parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('cron:remove')
->setDescription('Removes tasks from crontab');

parent::configure();
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$this->crontabManager->removeTasks();
} catch (LocalizedException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
return Cli::RETURN_FAILURE;
}

$output->writeln('<info>Magento cron tasks have been removed</info>');

return Cli::RETURN_SUCCESS;
}
}
24 changes: 24 additions & 0 deletions app/code/Magento/Cron/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Cron\Model\ConfigInterface" type="Magento\Cron\Model\Config" />
<preference for="Magento\Framework\Shell\CommandRendererInterface" type="Magento\Framework\Shell\CommandRenderer" />
<preference for="Magento\Framework\Crontab\CrontabManagerInterface" type="Magento\Framework\Crontab\CrontabManager" />
<preference for="Magento\Framework\Crontab\TasksProviderInterface" type="Magento\Framework\Crontab\TasksProvider" />
<type name="Magento\Cron\Model\Config\Reader\Db">
<arguments>
<argument name="defaultReader" xsi:type="object">DefaultScopeReader</argument>
Expand All @@ -33,6 +35,8 @@
<arguments>
<argument name="commands" xsi:type="array">
<item name="cronCommand" xsi:type="object">Magento\Cron\Console\Command\CronCommand</item>
<item name="cronInstall" xsi:type="object">Magento\Cron\Console\Command\CronInstallCommand</item>
<item name="cronRemove" xsi:type="object">Magento\Cron\Console\Command\CronRemoveCommand</item>
</argument>
</arguments>
</type>
Expand All @@ -43,4 +47,24 @@
</argument>
</arguments>
</type>
<type name="Magento\Framework\Crontab\CrontabManagerInterface">
<arguments>
<argument name="shell" xsi:type="object">Magento\Framework\App\Shell</argument>
</arguments>
</type>
<type name="Magento\Framework\Crontab\TasksProviderInterface">
<arguments>
<argument name="tasks" xsi:type="array">
<item name="cronMagento" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}bin/magento cron:run | grep -v "Ran jobs by schedule" >> {magentoLog}magento.cron.log</item>
</item>
<item name="cronUpdate" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}update/cron.php >> {magentoLog}update.cron.log</item>
</item>
<item name="cronSetup" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}bin/magento setup:cron:run >> {magentoLog}setup.cron.log</item>
</item>
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function create(
$appendComment,
$comment->getIsVisibleOnFront()
);

if ($appendComment) {
$shipment->setCustomerNote($comment->getComment());
$shipment->setCustomerNoteNotify($appendComment);
}
}

return $shipment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function setUp()

$this->shipmentMock = $this->getMockBuilder(ShipmentInterface::class)
->disableOriginalConstructor()
->setMethods(['addComment', 'addTrack'])
->setMethods(['addComment', 'addTrack', 'setCustomerNote', 'setCustomerNoteNotify'])
->getMockForAbstractClass();

$this->hydratorPoolMock = $this->getMockBuilder(HydratorPool::class)
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testCreate()
if ($appendComment) {
$comment = "New comment!";
$visibleOnFront = true;
$this->commentMock->expects($this->once())
$this->commentMock->expects($this->exactly(2))
->method('getComment')
->willReturn($comment);

Expand All @@ -178,6 +178,10 @@ public function testCreate()
->method('addComment')
->with($comment, $appendComment, $visibleOnFront)
->willReturnSelf();

$this->shipmentMock->expects($this->once())
->method('setCustomerNoteNotify')
->with(true);
}

$this->assertEquals(
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Store/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<item name="standard" xsi:type="array">
<item name="class" xsi:type="string">Magento\Framework\App\Router\Base</item>
<item name="disable" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">20</item>
<item name="sortOrder" xsi:type="string">30</item>
</item>
<item name="default" xsi:type="array">
<item name="class" xsi:type="string">Magento\Framework\App\Router\DefaultRouter</item>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/UrlRewrite/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<item name="urlrewrite" xsi:type="array">
<item name="class" xsi:type="string">Magento\UrlRewrite\Controller\Router</item>
<item name="disable" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">40</item>
<item name="sortOrder" xsi:type="string">20</item>
</item>
</argument>
</arguments>
Expand Down
Loading

0 comments on commit 13d3888

Please sign in to comment.