Skip to content

Commit a33b340

Browse files
author
Dennis Garding
authored
Merge pull request #39 from shopwareLabs/ntr/5.7/prepare-plugin-xml
PT-12213 - Check cron time while saving
2 parents ec57ad9 + dc2c07f commit a33b340

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

Controllers/Backend/SwagTax.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function saveAction()
2626
'tax_mapping' => $params['taxMapping'],
2727
'copy_tax_rules' => (bool) $params['copyTaxRules'],
2828
'customer_group_mapping' => $params['customerGroupMapping'],
29-
'scheduled_date' => $this->Request()->getParam('scheduledDate'),
29+
'scheduled_date' => $this->checkCronDate($params['scheduledDate']),
3030
]);
3131
}
3232

@@ -114,4 +114,26 @@ private function clearTable()
114114
{
115115
$this->container->get('dbal_connection')->executeQuery(sprintf('TRUNCATE TABLE %s', self::TABLE_NAME));
116116
}
117+
118+
/**
119+
* @param string $scheduledDate
120+
*
121+
* @return string
122+
*/
123+
private function checkCronDate($scheduledDate)
124+
{
125+
$emptyDate = '0000-00-00 00:00:00';
126+
if ($scheduledDate === '' || empty($scheduledDate)) {
127+
return $emptyDate;
128+
}
129+
130+
$scheduledDateTime = new \DateTime($scheduledDate);
131+
$nowDateTime = new \DateTime('NOW');
132+
133+
if ($scheduledDateTime > $nowDateTime) {
134+
return $scheduledDate;
135+
}
136+
137+
return $emptyDate;
138+
}
117139
}

Tests/Controllers/Backend/SwagTaxTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,55 @@ public function test_saveTaxRateAction_withNameAndTaxRateShouldBe_true()
7979
static::assertSame('33 %', $savedTaxResult['description']);
8080
}
8181

82+
public function test_checkCronDate_shouldReturnEmptyDate()
83+
{
84+
$controller = $this->getController();
85+
$emptyDate = '0000-00-00 00:00:00';
86+
87+
$reflectionMethod = (new \ReflectionClass(\Shopware_Controllers_Backend_SwagTax::class))->getMethod('checkCronDate');
88+
$reflectionMethod->setAccessible(true);
89+
90+
$result = $reflectionMethod->invoke($controller, null);
91+
static::assertSame($emptyDate, $result);
92+
93+
$result = $reflectionMethod->invoke($controller, '');
94+
static::assertSame($emptyDate, $result);
95+
96+
$result = $reflectionMethod->invoke($controller, '0');
97+
static::assertSame($emptyDate, $result);
98+
99+
$result = $reflectionMethod->invoke($controller, '0000-00-00 00:00:00');
100+
static::assertSame($emptyDate, $result);
101+
102+
$result = $reflectionMethod->invoke($controller, '2020-01-01 00:00:00');
103+
static::assertSame($emptyDate, $result);
104+
105+
$result = $reflectionMethod->invoke($controller, '2020-01-01 00:00:00');
106+
static::assertSame($emptyDate, $result);
107+
108+
$now = date('Y-m-d H:i:s');
109+
$past = date('Y-m-d H:i:s', strtotime('-1 hour', strtotime($now)));
110+
$result = $reflectionMethod->invoke($controller, $past);
111+
static::assertSame($emptyDate, $result);
112+
}
113+
114+
public function test_checkCronDate_shouldReturnGivenDate()
115+
{
116+
$controller = $this->getController();
117+
118+
$reflectionMethod = (new \ReflectionClass(\Shopware_Controllers_Backend_SwagTax::class))->getMethod('checkCronDate');
119+
$reflectionMethod->setAccessible(true);
120+
121+
$future = '2222-02-02 20:20:20';
122+
$result = $reflectionMethod->invoke($controller, $future);
123+
static::assertSame($future, $result);
124+
125+
$now = date('Y-m-d H:i:s');
126+
$future = date('Y-m-d H:i:s', strtotime('+1 hour', strtotime($now)));
127+
$result = $reflectionMethod->invoke($controller, $future);
128+
static::assertSame($future, $result);
129+
}
130+
82131
private function getController()
83132
{
84133
$controller = new \Shopware_Controllers_Backend_SwagTax();

plugin.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<label lang="de">Steuern ändern</label>
66
<label lang="en">Change taxes</label>
77

8-
<version>2.0.2</version>
8+
<version>2.0.3</version>
99
<copyright>(c) by shopware AG</copyright>
1010
<license>mit</license>
1111
<link>http://store.shopware.com</link>
@@ -16,6 +16,11 @@
1616

1717
<compatibility minVersion="5.2.0"/>
1818

19+
<changelog version="2.0.3">
20+
<changes lang="en">PT-12211 - Check cron time while saving;</changes>
21+
<changes lang="de">PT-12211 - Überprüft die Cron-Zeit beim Speichern;</changes>
22+
</changelog>
23+
1924
<changelog version="2.0.2">
2025
<changes lang="en">PT-12211 - Fixed Shopware 5.2 compatibility;</changes>
2126
<changes lang="de">PT-12211 - Shopware 5.2 Kompatibilität hergestellt</changes>

0 commit comments

Comments
 (0)