Skip to content

Commit

Permalink
Merge pull request #34 from Ethan3600/0.x-develop
Browse files Browse the repository at this point in the history
release v0.4.0
  • Loading branch information
Ethan Yehuda authored Mar 5, 2018
2 parents b8b659d + 550b3e1 commit e230b14
Show file tree
Hide file tree
Showing 49 changed files with 2,087 additions and 456 deletions.
49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
sudo: required
dist: trusty
group: edge
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
hosts:
- magento2.travis
language: php
matrix:
include:
- php: 7.1
env:
- MAGENTO_VERSION=2.3-develop
- TEST_SUITE=integration
- php: 7.1
env:
- MAGENTO_VERSION=2.2-develop
- TEST_SUITE=integration
- php: 7.1
env:
- MAGENTO_VERSION=2.2.2
- TEST_SUITE=integration
- php: 7.0
env:
- MAGENTO_VERSION=2.3-develop
- TEST_SUITE=integration
- php: 7.0
env:
- MAGENTO_VERSION=2.2-develop
- TEST_SUITE=integration
- php: 7.0
env:
- MAGENTO_VERSION=2.2.2
- TEST_SUITE=integration
env:
global:
- COMPOSER_BIN_DIR=~/bin
- COMPOSER_PACKAGE_NAME=ethanyehuda/magento2-cronjobmanager
cache:
apt: true
directories:
- $HOME/.composer/cache
before_script: ./.travis/before_script.sh
script: phpunit -c magento2/dev/tests/$TEST_SUITE
49 changes: 49 additions & 0 deletions .travis/before_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -e
trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit code $?' ERR

# mock mail
sudo service postfix stop
echo # print a newline
smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/sendmail.ini

# disable xdebug and adjust memory limit
echo > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
phpenv rehash;

composer selfupdate

# clone main magento github repository
git clone --branch $MAGENTO_VERSION --depth=1 https://github.com/magento/magento2

# install Magento
cd magento2

# add composer package under test, composer require will trigger update/install
composer config minimum-stability dev
composer config repositories.travis_to_test git https://github.com/$TRAVIS_REPO_SLUG.git
composer require $COMPOSER_PACKAGE_NAME:dev-$TRAVIS_BRANCH#$TRAVIS_COMMIT

# prepare for test suite
case $TEST_SUITE in
integration)
cp vendor/$COMPOSER_PACKAGE_NAME/Test/Integration/phpunit.xml.dist dev/tests/integration/phpunit.xml

cd dev/tests/integration

# create database and move db config into place
mysql -uroot -e '
SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION;
CREATE DATABASE magento_integration_tests;
'
mv etc/install-config-mysql.travis.php.dist etc/install-config-mysql.php

cd ../../..
;;
unit)
cp vendor/$COMPOSER_PACKAGE_NAME/Test/Unit/phpunit.xml.dist dev/tests/unit/phpunit.xml
;;
esac
15 changes: 8 additions & 7 deletions Block/Adminhtml/Cronjob/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
class DeleteButton extends GenericButton implements ButtonProviderInterface
{
/**
* @todo Need to figure out how to get the ID
* @return array
*/
public function getButtonData()
{
$params = $this->getRequestParams();
$cronId = $params['id'];
$params = $this->getRequestParams();
$cronId = $params['id'];

$data = [
$data = [
'label' => __('Delete'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . __(
'Are you sure you want to delete this?'
) . '\', \'' . $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId]) . '\')',
'on_click' => 'deleteConfirm(\''
. __('Are you sure you want to delete this?')
. '\', \''
. $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId])
. '\')',
'sort_order' => 20,
];
return $data;
Expand Down
11 changes: 6 additions & 5 deletions Block/Adminhtml/Cronjob/Edit/GenericButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EthanYehuda\CronjobManager\Block\Adminhtml\Cronjob\Edit;

use EthanYehuda\CronjobManager\Model\RegistryConstants;
use Magento\Framework\Registry;

class GenericButton
{
Expand All @@ -19,11 +18,11 @@ class GenericButton
*
* @var \Magento\Framework\Registry
*/
protected $registry;
protected $registry;

/**
* Constructor
*
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
*/
Expand All @@ -34,10 +33,12 @@ public function __construct(
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}

public function getRequestParams()
{
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB);
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB) ?
$this->registry->registry(RegistryConstants::CURRENT_CRON_JOB) :
$this->registry->registry(RegistryConstants::CURRENT_CRON_CONFIG);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions Block/Adminhtml/Cronjob/Edit/RestoreSystemDefault.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace EthanYehuda\CronjobManager\Block\Adminhtml\Cronjob\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class RestoreSystemDefault extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
$params = $this->getRequestParams();
unset($params['key'], $params['form_key']);
$data = [
'label' => __('Restore System Default'),
'class' => 'secondary',
'on_click' => 'deleteConfirm(\''
. __('Are you sure you want to restore this to system defaults?')
. '\', \''
. $this->urlBuilder->getUrl('*/config_job/restoreSystemDefault', $params)
. '\')',
'sort_order' => 5,
];
return $data;
}
}
10 changes: 5 additions & 5 deletions Block/Adminhtml/Cronjob/Edit/SaveAndContinueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function getButtonData()
$data = [
'label' => __('Save and Continue'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'saveAndContinue'],
]
],
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'saveAndContinue'],
]
],
'sort_order' => 90,
];
return $data;
Expand Down
12 changes: 6 additions & 6 deletions Block/Adminhtml/Cronjob/Edit/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public function getButtonData()
$data = [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save']
],
'form-role' => 'save',
],
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save']
],
'form-role' => 'save',
],
];
return $data;
}
Expand Down
1 change: 1 addition & 0 deletions Command/Runjob.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace EthanYehuda\CronjobManager\Command;

use Symfony\Component\Console\Command\Command;
Expand Down
109 changes: 57 additions & 52 deletions Command/Showjobs.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,78 @@
<?php

namespace EthanYehuda\CronjobManager\Command;

use Magento\Framework\App\Area;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use EthanYehuda\CronjobManager\Model\Manager;
use \Magento\Framework\App\State;
use \Magento\Framework\Console\Cli;
use EthanYehuda\CronjobManager\Model\ManagerFactory;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;

class Showjobs extends Command
{
/**
* @var EthanYehuda\CronjobManager\Model\Manager $manager
*/
private $manager;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var Array $headers
*/
private $headers = ['Code', 'Group', 'Frequency', 'Class'];

public function __construct(
State $state,
Manager $manager
) {
$this->manager = $manager;
$this->state = $state;
parent::__construct();
}
/**
* @var \EthanYehuda\CronjobManager\Model\ManagerFactory $managerFactory
*/
private $managerFactory;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var array $headers
*/
private $headers = ['Job Code', 'Group', 'Frequency', 'Class'];

public function __construct(
State $state,
ManagerFactory $managerFactory
) {
$this->managerFactory = $managerFactory;
$this->state = $state;
parent::__construct();
}

protected function configure()
{
$this->setName("cronmanager:showjobs");
$this->setDescription("Show all cron jobs in Magento");
$this->setDescription("Show all cron job codes in Magento");
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$manager = $this->managerFactory->create();

try {
$this->state->setAreaCode('adminhtml');
$jobs = $this->manager->getCronJobs();
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);
foreach ($jobs as $group => $crons) {
foreach ($crons as $code => $job) {
$instance = $job['instance'];
$method = $job['method'];
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
$jobData = [
$code,
$group,
$schedule,
"$instance::$method"
];
$table->addRow($jobData);
}
}
$table->render($output);
return Cli::RETURN_SUCCESS;
$this->state->setAreaCode(Area::AREA_ADMINHTML);

$jobs = $manager->getCronJobs();
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);

foreach ($jobs as $group => $crons) {
foreach ($crons as $code => $job) {
$instance = $job['instance'];
$method = $job['method'];
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
$jobData = [
$code,
$group,
$schedule,
"$instance::$method"
];
$table->addRow($jobData);
}
}

$table->render($output);
return Cli::RETURN_SUCCESS;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
}
}
}
}
Loading

0 comments on commit e230b14

Please sign in to comment.