Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tkotosz committed Dec 1, 2018
1 parent cb09c27 commit 8ff44fa
Show file tree
Hide file tree
Showing 47 changed files with 2,058 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
# Composer packages directory
/vendor

# Composer executable files directory
/bin

# Installed Composer packages versions
/composer.lock
51 changes: 51 additions & 0 deletions .scrutinizer.yml
@@ -0,0 +1,51 @@
checks:
php: true

tools:
external_code_coverage: false
php_code_coverage: false
php_code_sniffer:
config: { standard: 'PSR2' }
php_changetracking: false
php_sim: false
php_mess_detector: true
php_pdepend: true
php_analyzer: false
sensiolabs_security_checker: true

filter:
paths:
- 'src/*'
excluded_paths:
- 'features/bootstrap/*'
- 'dev/*'
- 'var/*'
- 'lib/*'
- 'bin/*'
- 'vendor/*'

build:
environment:
php:
version: '7.1.6'
ini:
'always_populate_raw_post_data': '-1'

nodes:
analysis:
tests:
override:
- php-scrutinizer-run

dependencies:
override:
- { command: 'composer update --no-interaction --prefer-source', idle_timeout: 600 }

cache:
directories: [ vendor/, bin/, ~/.composer/cache ]

build_failure_conditions:
- 'elements.rating(<= B).new.exists'
- 'issues.label("coding-style").new.exists'
- 'issues.new.exists'
- 'project.metric("scrutinizer.quality", < 9.00)'
28 changes: 28 additions & 0 deletions README.md
@@ -0,0 +1,28 @@
Command Scheduler module for Magento 2
=========================
[![License](https://poser.pugx.org/tkotosz/command-scheduler-magento2/license)](https://packagist.org/packages/tkotosz/command-scheduler-magento2)
[![Latest Stable Version](https://poser.pugx.org/tkotosz/command-scheduler-magento2/version)](https://packagist.org/packages/tkotosz/command-scheduler-magento2)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tkotosz/command-scheduler-magento2/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tkotosz/command-scheduler-magento2/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/tkotosz/command-scheduler-magento2/badges/build.png?b=master)](https://scrutinizer-ci.com/g/tkotosz/command-scheduler-magento2/build-status/master)

This module allows you to schedule bin/magento commands in the Magento admin. This makes it possible to run bin/magento command with only Magento admin access.

Usage:

1. Configure the allowed commands:
List of allowed commands can be configured in the di like this:
```
<type name="Tkotosz\CommandScheduler\Model\AllowedCommandsContainer">
<arguments>
<argument name="allowedCommands" xsi:type="array">
<item name="Cache Clean" xsi:type="string">cache:clean</item>
</argument>
</arguments>
</type>
```

2. Schedule any allowed command on the System > Tools > Schedule Commands admin page

3. Wait for the schedule processor to run: By default a cron runs every 5 minute to process the next pending schedule. (alternatively you can use the bin/magento command-scheduler:process-next-schedule command to trigger the schedule processing)

4. Check the result of the command execution on the System > Tools > Schedule Commands admin page by clicking on the "view result" link
36 changes: 36 additions & 0 deletions composer.json
@@ -0,0 +1,36 @@
{
"name": "tkotosz/command-scheduler-magento2",
"description": "Tkotosz - Catalog Router",
"type": "magento2-module",
"repositories": {
"magento-repo": {
"type": "composer",
"url": "https://repo.magento.com/"
}
},
"license": "MIT",
"authors": [
{
"name": "Tibor Kotosz",
"email": "kotosy@gmail.com",
"homepage": "https://github.com/tkotosz",
"role": "Developer"
}
],
"require": {
"php": ">=7.1",
"magento/framework": "^101.0"
},
"config": {
"bin-dir": "bin",
"use-include-path": true
},
"autoload": {
"files": [
"src/Tkotosz/CommandScheduler/registration.php"
],
"psr-0": {
"Tkotosz\\CommandScheduler\\": "src"
}
}
}
@@ -0,0 +1,30 @@
<?php

namespace Tkotosz\CommandScheduler\Api;

use Tkotosz\CommandScheduler\Api\Data\CommandScheduleInterface;
use Tkotosz\CommandScheduler\Api\Data\CommandScheduleSearchResultsInterface;
use Magento\Framework\Api\SearchCriteria;

interface CommandScheduleRepositoryInterface
{
public function save(CommandScheduleInterface $commandSchedule): CommandScheduleInterface;

public function create(string $commandName, string $commandParams): CommandScheduleInterface;

public function updateStatus(CommandScheduleInterface $commandSchedule, string $status): CommandScheduleInterface;

public function updateResult(CommandScheduleInterface $commandSchedule, string $result): CommandScheduleInterface;

public function getById(int $id): CommandScheduleInterface;

public function getList(SearchCriteria $searchCriteria): CommandScheduleSearchResultsInterface;

public function getOneByStatus(string $status): ?CommandScheduleInterface;

public function getAll(): CommandScheduleSearchResultsInterface;

public function delete(CommandScheduleInterface $commandSchedule): bool;

public function deleteById(int $id): bool;
}
91 changes: 91 additions & 0 deletions src/Tkotosz/CommandScheduler/Api/Data/CommandScheduleInterface.php
@@ -0,0 +1,91 @@
<?php

namespace Tkotosz\CommandScheduler\Api\Data;

interface CommandScheduleInterface
{
public const SCHEDULE_ID = 'schedule_id';
public const COMMAND_NAME = 'command_name';
public const COMMAND_PARAMS = 'command_params';
public const STATUS = 'status';
public const RESULT = 'result';
public const SCHEDULED_AT = 'scheduled_at';
public const UPDATED_AT = 'updated_at';

/**
* @return int|null
*/
public function getScheduleId(): ?int;

/**
* @param int $scheduleId
* @return CommandScheduleInterface
*/
public function setScheduleId($scheduleId): CommandScheduleInterface;

/**
* @return string|null
*/
public function getCommandName(): ?string;

/**
* @param string $commandName
* @return CommandScheduleInterface
*/
public function setCommandName(string $commandName): CommandScheduleInterface;

/**
* @return string|null
*/
public function getCommandParams(): ?string;

/**
* @param string $commandParams
* @return CommandScheduleInterface
*/
public function setCommandParams(string $commandParams): CommandScheduleInterface;

/**
* @return string|null
*/
public function getStatus(): ?string;

/**
* @param string $status
* @return CommandScheduleInterface
*/
public function setStatus(string $status): CommandScheduleInterface;

/**
* @return string|null
*/
public function getResult(): ?string;

/**
* @param string $result
* @return CommandScheduleInterface
*/
public function setResult(string $result): CommandScheduleInterface;

/**
* @return string|null
*/
public function getScheduledAt(): ?string;

/**
* @param string $scheduledAt
* @return CommandScheduleInterface
*/
public function setScheduledAt(string $scheduledAt): CommandScheduleInterface;

/**
* @return string|null
*/
public function getUpdatedAt(): ?string;

/**
* @param string $updatedAt
* @return CommandScheduleInterface
*/
public function setUpdatedAt(string $updatedAt): CommandScheduleInterface;
}
@@ -0,0 +1,25 @@
<?php

namespace Tkotosz\CommandScheduler\Api\Data;

use Tkotosz\CommandScheduler\Api\Data\CommandScheduleInterface;
use Magento\Framework\Api\SearchResultsInterface;

interface CommandScheduleSearchResultsInterface extends SearchResultsInterface
{
/**
* Get brands list.
*
* @return CommandScheduleInterface[]
*/
public function getItems(): array;

/**
* Set brands list.
*
* @param CommandScheduleInterface[] $items
*
* @return $this
*/
public function setItems(array $items): CommandScheduleSearchResultsInterface;
}
@@ -0,0 +1,24 @@
<?php

namespace Tkotosz\CommandScheduler\Block\Adminhtml\Schedule\Create;

use Magento\Backend\Block\Widget\Form\Generic;

class Form extends Generic
{
/**
* Prepare form before rendering HTML
*
* @return $this
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]
);
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
@@ -0,0 +1,84 @@
<?php

namespace Tkotosz\CommandScheduler\Block\Adminhtml\Schedule\Create\From;

use Magento\Backend\Block\Widget\Form\Container as BaseFormContainer;

class Container extends BaseFormContainer
{
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $coreRegistry = null;

/**
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
) {
$this->coreRegistry = $registry;
parent::__construct($context, $data);
}

/**
* Internal constructor
*
* @return void
*/
protected function _construct()
{
$this->_objectId = 'schedule_id';
$this->_blockGroup = 'Tkotosz_CommandScheduler';
$this->_controller = 'adminhtml_schedule';
$this->_mode = 'create';
parent::_construct();
}


public function getFromData()
{
return $this->coreRegistry->registry('tkotosz_command_scheduler_data_container');
}

/**
* Prepare layout.
* Adding save_and_continue button
*
* @return $this
*/
protected function _preparelayout()
{
if (!$this->getFromData()->getData('command')) {
$this->removeButton('save');
}

return parent::_prepareLayout();
}

/**
* Return translated header text depending on creating/editing action
*
* @return \Magento\Framework\Phrase
*/
public function getHeaderText()
{
return __('New Schedule');
}

/**
* Return save url for edit form
*
* @return string
*/
public function getSaveUrl()
{
return $this->getUrl('tkotosz_commandscheduler/schedule/save', ['_current' => false, 'back' => null]);
}
}

0 comments on commit 8ff44fa

Please sign in to comment.