Skip to content

Commit 550b3e1

Browse files
author
Ethan Yehuda
authored
Merge pull request #33 from Ethan3600/backport/v0.4.0
Backport features new features
2 parents 9441e71 + 57846d3 commit 550b3e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2087
-456
lines changed

.travis.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
sudo: required
2+
dist: trusty
3+
group: edge
4+
addons:
5+
apt:
6+
packages:
7+
- mysql-server-5.6
8+
- mysql-client-core-5.6
9+
- mysql-client-5.6
10+
- postfix
11+
hosts:
12+
- magento2.travis
13+
language: php
14+
matrix:
15+
include:
16+
- php: 7.1
17+
env:
18+
- MAGENTO_VERSION=2.3-develop
19+
- TEST_SUITE=integration
20+
- php: 7.1
21+
env:
22+
- MAGENTO_VERSION=2.2-develop
23+
- TEST_SUITE=integration
24+
- php: 7.1
25+
env:
26+
- MAGENTO_VERSION=2.2.2
27+
- TEST_SUITE=integration
28+
- php: 7.0
29+
env:
30+
- MAGENTO_VERSION=2.3-develop
31+
- TEST_SUITE=integration
32+
- php: 7.0
33+
env:
34+
- MAGENTO_VERSION=2.2-develop
35+
- TEST_SUITE=integration
36+
- php: 7.0
37+
env:
38+
- MAGENTO_VERSION=2.2.2
39+
- TEST_SUITE=integration
40+
env:
41+
global:
42+
- COMPOSER_BIN_DIR=~/bin
43+
- COMPOSER_PACKAGE_NAME=ethanyehuda/magento2-cronjobmanager
44+
cache:
45+
apt: true
46+
directories:
47+
- $HOME/.composer/cache
48+
before_script: ./.travis/before_script.sh
49+
script: phpunit -c magento2/dev/tests/$TEST_SUITE

.travis/before_script.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR
5+
6+
# mock mail
7+
sudo service postfix stop
8+
echo # print a newline
9+
smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
10+
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/sendmail.ini
11+
12+
# disable xdebug and adjust memory limit
13+
echo > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
14+
echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
15+
phpenv rehash;
16+
17+
composer selfupdate
18+
19+
# clone main magento github repository
20+
git clone --branch $MAGENTO_VERSION --depth=1 https://github.com/magento/magento2
21+
22+
# install Magento
23+
cd magento2
24+
25+
# add composer package under test, composer require will trigger update/install
26+
composer config minimum-stability dev
27+
composer config repositories.travis_to_test git https://github.com/$TRAVIS_REPO_SLUG.git
28+
composer require $COMPOSER_PACKAGE_NAME:dev-$TRAVIS_BRANCH#$TRAVIS_COMMIT
29+
30+
# prepare for test suite
31+
case $TEST_SUITE in
32+
integration)
33+
cp vendor/$COMPOSER_PACKAGE_NAME/Test/Integration/phpunit.xml.dist dev/tests/integration/phpunit.xml
34+
35+
cd dev/tests/integration
36+
37+
# create database and move db config into place
38+
mysql -uroot -e '
39+
SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
40+
CREATE DATABASE magento_integration_tests;
41+
'
42+
mv etc/install-config-mysql.travis.php.dist etc/install-config-mysql.php
43+
44+
cd ../../..
45+
;;
46+
unit)
47+
cp vendor/$COMPOSER_PACKAGE_NAME/Test/Unit/phpunit.xml.dist dev/tests/unit/phpunit.xml
48+
;;
49+
esac

Block/Adminhtml/Cronjob/Edit/DeleteButton.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
class DeleteButton extends GenericButton implements ButtonProviderInterface
88
{
99
/**
10-
* @todo Need to figure out how to get the ID
1110
* @return array
1211
*/
1312
public function getButtonData()
1413
{
15-
$params = $this->getRequestParams();
16-
$cronId = $params['id'];
14+
$params = $this->getRequestParams();
15+
$cronId = $params['id'];
1716

18-
$data = [
17+
$data = [
1918
'label' => __('Delete'),
2019
'class' => 'delete',
21-
'on_click' => 'deleteConfirm(\'' . __(
22-
'Are you sure you want to delete this?'
23-
) . '\', \'' . $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId]) . '\')',
20+
'on_click' => 'deleteConfirm(\''
21+
. __('Are you sure you want to delete this?')
22+
. '\', \''
23+
. $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId])
24+
. '\')',
2425
'sort_order' => 20,
2526
];
2627
return $data;

Block/Adminhtml/Cronjob/Edit/GenericButton.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EthanYehuda\CronjobManager\Block\Adminhtml\Cronjob\Edit;
44

55
use EthanYehuda\CronjobManager\Model\RegistryConstants;
6-
use Magento\Framework\Registry;
76

87
class GenericButton
98
{
@@ -19,11 +18,11 @@ class GenericButton
1918
*
2019
* @var \Magento\Framework\Registry
2120
*/
22-
protected $registry;
21+
protected $registry;
2322

2423
/**
2524
* Constructor
26-
*
25+
*
2726
* @param \Magento\Backend\Block\Widget\Context $context
2827
* @param \Magento\Framework\Registry $registry
2928
*/
@@ -34,10 +33,12 @@ public function __construct(
3433
$this->urlBuilder = $context->getUrlBuilder();
3534
$this->registry = $registry;
3635
}
37-
36+
3837
public function getRequestParams()
3938
{
40-
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB);
39+
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB) ?
40+
$this->registry->registry(RegistryConstants::CURRENT_CRON_JOB) :
41+
$this->registry->registry(RegistryConstants::CURRENT_CRON_CONFIG);
4142
}
4243

4344
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace EthanYehuda\CronjobManager\Block\Adminhtml\Cronjob\Edit;
4+
5+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
6+
7+
class RestoreSystemDefault extends GenericButton implements ButtonProviderInterface
8+
{
9+
/**
10+
* @return array
11+
*/
12+
public function getButtonData()
13+
{
14+
$params = $this->getRequestParams();
15+
unset($params['key'], $params['form_key']);
16+
$data = [
17+
'label' => __('Restore System Default'),
18+
'class' => 'secondary',
19+
'on_click' => 'deleteConfirm(\''
20+
. __('Are you sure you want to restore this to system defaults?')
21+
. '\', \''
22+
. $this->urlBuilder->getUrl('*/config_job/restoreSystemDefault', $params)
23+
. '\')',
24+
'sort_order' => 5,
25+
];
26+
return $data;
27+
}
28+
}

Block/Adminhtml/Cronjob/Edit/SaveAndContinueButton.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public function getButtonData()
1414
$data = [
1515
'label' => __('Save and Continue'),
1616
'class' => 'save',
17-
'data_attribute' => [
18-
'mage-init' => [
19-
'button' => ['event' => 'saveAndContinue'],
20-
]
21-
],
17+
'data_attribute' => [
18+
'mage-init' => [
19+
'button' => ['event' => 'saveAndContinue'],
20+
]
21+
],
2222
'sort_order' => 90,
2323
];
2424
return $data;

Block/Adminhtml/Cronjob/Edit/SaveButton.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public function getButtonData()
1414
$data = [
1515
'label' => __('Save'),
1616
'class' => 'save primary',
17-
'data_attribute' => [
18-
'mage-init' => [
19-
'button' => ['event' => 'save']
20-
],
21-
'form-role' => 'save',
22-
],
17+
'data_attribute' => [
18+
'mage-init' => [
19+
'button' => ['event' => 'save']
20+
],
21+
'form-role' => 'save',
22+
],
2323
];
2424
return $data;
2525
}

Command/Runjob.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace EthanYehuda\CronjobManager\Command;
34

45
use Symfony\Component\Console\Command\Command;

Command/Showjobs.php

+57-52
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,78 @@
11
<?php
2+
23
namespace EthanYehuda\CronjobManager\Command;
34

5+
use Magento\Framework\App\Area;
46
use Symfony\Component\Console\Command\Command;
57
use Symfony\Component\Console\Input\InputInterface;
68
use Symfony\Component\Console\Output\OutputInterface;
7-
use EthanYehuda\CronjobManager\Model\Manager;
8-
use \Magento\Framework\App\State;
9-
use \Magento\Framework\Console\Cli;
9+
use EthanYehuda\CronjobManager\Model\ManagerFactory;
10+
use Magento\Framework\App\State;
11+
use Magento\Framework\Console\Cli;
1012

1113
class Showjobs extends Command
1214
{
13-
/**
14-
* @var EthanYehuda\CronjobManager\Model\Manager $manager
15-
*/
16-
private $manager;
17-
18-
/**
19-
* @var \Magento\Framework\App\State $state
20-
*/
21-
private $state;
22-
23-
/**
24-
* @var Array $headers
25-
*/
26-
private $headers = ['Code', 'Group', 'Frequency', 'Class'];
27-
28-
public function __construct(
29-
State $state,
30-
Manager $manager
31-
) {
32-
$this->manager = $manager;
33-
$this->state = $state;
34-
parent::__construct();
35-
}
15+
/**
16+
* @var \EthanYehuda\CronjobManager\Model\ManagerFactory $managerFactory
17+
*/
18+
private $managerFactory;
19+
20+
/**
21+
* @var \Magento\Framework\App\State $state
22+
*/
23+
private $state;
24+
25+
/**
26+
* @var array $headers
27+
*/
28+
private $headers = ['Job Code', 'Group', 'Frequency', 'Class'];
29+
30+
public function __construct(
31+
State $state,
32+
ManagerFactory $managerFactory
33+
) {
34+
$this->managerFactory = $managerFactory;
35+
$this->state = $state;
36+
parent::__construct();
37+
}
38+
3639
protected function configure()
3740
{
3841
$this->setName("cronmanager:showjobs");
39-
$this->setDescription("Show all cron jobs in Magento");
42+
$this->setDescription("Show all cron job codes in Magento");
4043
parent::configure();
4144
}
4245

4346
protected function execute(InputInterface $input, OutputInterface $output)
4447
{
48+
$manager = $this->managerFactory->create();
49+
4550
try {
46-
$this->state->setAreaCode('adminhtml');
47-
48-
$jobs = $this->manager->getCronJobs();
49-
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);
50-
51-
foreach ($jobs as $group => $crons) {
52-
foreach ($crons as $code => $job) {
53-
$instance = $job['instance'];
54-
$method = $job['method'];
55-
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
56-
$jobData = [
57-
$code,
58-
$group,
59-
$schedule,
60-
"$instance::$method"
61-
];
62-
$table->addRow($jobData);
63-
}
64-
}
65-
66-
$table->render($output);
67-
return Cli::RETURN_SUCCESS;
51+
$this->state->setAreaCode(Area::AREA_ADMINHTML);
52+
53+
$jobs = $manager->getCronJobs();
54+
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);
55+
56+
foreach ($jobs as $group => $crons) {
57+
foreach ($crons as $code => $job) {
58+
$instance = $job['instance'];
59+
$method = $job['method'];
60+
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
61+
$jobData = [
62+
$code,
63+
$group,
64+
$schedule,
65+
"$instance::$method"
66+
];
67+
$table->addRow($jobData);
68+
}
69+
}
70+
71+
$table->render($output);
72+
return Cli::RETURN_SUCCESS;
6873
} catch (\Magento\Framework\Exception\LocalizedException $e) {
69-
$output->writeln($e->getMessage());
70-
return Cli::RETURN_FAILURE;
74+
$output->writeln($e->getMessage());
75+
return Cli::RETURN_FAILURE;
7176
}
7277
}
73-
}
78+
}

0 commit comments

Comments
 (0)