Skip to content

Commit

Permalink
php 5.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MUlt1mate committed Jan 28, 2016
1 parent 3ea4faa commit 68e8367
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.phar
/vendor
/examples/active_record/vendor
/examples/codeigniter/framework_files
/.idea
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mult1mate/cron-manager",
"description": "Flexible cron tasks manager for MVC-type applications",
"minimum-stability": "dev",
"minimum-stability": "stable",
"keywords": ["cron","crontab","tasks manager","schedule","codeigniter"],
"homepage": "https://cron.multimate.ru",
"license": "MIT",
Expand All @@ -12,8 +12,8 @@
}
],
"require": {
"php": ">=5.4.0",
"mtdowling/cron-expression": "dev-master"
"php": ">=5.3.2",
"mtdowling/cron-expression": "1.1.*"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions examples/active_record/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public function __construct()
{
ActiveRecord\Config::initialize(function ($cfg) {
$cfg->set_model_directory('../models');
$cfg->set_connections([
'development' => 'mysql://root:qwerty@localhost/crontab']);
$cfg->set_connections(array(
'development' => 'mysql://root:qwerty@localhost/crontab'));
});
}

Expand Down
24 changes: 12 additions & 12 deletions examples/active_record/Controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class TasksController extends BaseController

public function index()
{
$this->renderView('tasks_list', [
$this->renderView('tasks_list', array(
'tasks' => Task::getList(),
'methods' => TaskManager::getAllMethods(self::CONTROLLERS_FOLDER),
]);
));
}

public function export()
{
$this->renderView('export', []);
$this->renderView('export', array());
}

public function parseCrontab()
Expand All @@ -36,7 +36,7 @@ public function exportTasks()
{
if (isset($_POST['folder'])) {
$tasks = Task::getList();
$result = [];
$result = array();
foreach ($tasks as $t) {
$line = TaskManager::getTaskCrontabLine($t, $_POST['folder'], $_POST['php'], $_POST['file']);
$result[] = nl2br($line);
Expand All @@ -49,13 +49,13 @@ public function taskLog()
{
$task_id = isset($_GET['task_id']) ? $_GET['task_id'] : null;
$runs = TaskRun::getLast($task_id);
$this->renderView('runs_list', ['runs' => $runs]);
$this->renderView('runs_list', array('runs' => $runs));
}

public function runTask()
{
if (isset($_POST['task_id'])) {
$tasks = !is_array($_POST['task_id']) ? [$_POST['task_id']] : $_POST['task_id'];
$tasks = !is_array($_POST['task_id']) ? array($_POST['task_id']) : $_POST['task_id'];
foreach ($tasks as $t) {
$task = Task::find($t);
/**
Expand Down Expand Up @@ -120,10 +120,10 @@ public function taskEdit()
$task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
}

$this->renderView('task_edit', [
$this->renderView('task_edit', array(
'task' => $task,
'methods' => TaskManager::getAllMethods(self::CONTROLLERS_FOLDER),
]);
));
}

public function tasksUpdate()
Expand All @@ -134,11 +134,11 @@ public function tasksUpdate()
/**
* @var Task $t
*/
$action_status = [
$action_status = array(
'Enable' => TaskInterface::TASK_STATUS_ACTIVE,
'Disable' => TaskInterface::TASK_STATUS_INACTIVE,
'Delete' => TaskInterface::TASK_STATUS_DELETED,
];
);
$t->setStatus($action_status[$_POST['action']]);
$t->save();
}
Expand All @@ -155,10 +155,10 @@ public function tasksReport()
$date_begin = isset($_GET['date_begin']) ? $_GET['date_begin'] : date('Y-m-d', strtotime('-6 day'));
$date_end = isset($_GET['date_end']) ? $_GET['date_end'] : date('Y-m-d');

$this->renderView('report', [
$this->renderView('report', array(
'report' => Task::getReport($date_begin, $date_end),
'date_begin' => $date_begin,
'date_end' => $date_end,
]);
));
}
}
14 changes: 7 additions & 7 deletions examples/active_record/models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/
class Task extends Model implements TaskInterface
{
static public $has_many = [
['taskruns', 'class_name' => 'TaskRun']
];
static public $has_many = array(
array('taskruns', 'class_name' => 'TaskRun')
);

public static function taskGet($task_id)
{
Expand All @@ -30,10 +30,10 @@ public static function taskGet($task_id)

public static function getList()
{
return self::find('all', [
'conditions' => ['status in (?)', [TaskInterface::TASK_STATUS_ACTIVE, TaskInterface::TASK_STATUS_INACTIVE]],
return self::find('all', array(
'conditions' => array('status in (?)', array(TaskInterface::TASK_STATUS_ACTIVE, TaskInterface::TASK_STATUS_INACTIVE)),
'order' => 'status, task_id desc',
]);
));
}

public static function getAll()
Expand All @@ -43,7 +43,7 @@ public static function getAll()

public static function getReport($date_begin, $date_end)
{
return self::query(DbHelper::getReportSql(), [$date_begin, $date_end])->fetchAll();
return self::query(DbHelper::getReportSql(), array($date_begin, $date_end))->fetchAll();
}

public function taskDelete()
Expand Down
10 changes: 5 additions & 5 deletions examples/active_record/models/TaskRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
class TaskRun extends Model implements TaskRunInterface
{
static public $belongs_to = [
['task']
];
static public $belongs_to = array(
array('task')
);

public static function getLast($task_id = null, $count = 100)
{
$conditions = ['order' => 'task_run_id desc', 'include' => ['task'], 'limit' => $count];
$conditions = array('order' => 'task_run_id desc', 'include' => array('task'), 'limit' => $count);
if ($task_id) {
$conditions['conditions'] = ['task_id' => $task_id];
$conditions['conditions'] = array('task_id' => $task_id);
}

return self::find('all', $conditions);
Expand Down
4 changes: 2 additions & 2 deletions examples/active_record/views/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* Date: 21.12.15
* Time: 0:29
*/
$menu = [
$menu = array(
'index' => 'Tasks list',
'taskEdit' => 'Add new/edit task',
'taskLog' => 'Logs',
'export' => 'Import/Export',
'tasksReport' => 'Report',
];
);
?>
<head>
<title>Cron tasks manager</title>
Expand Down
17 changes: 9 additions & 8 deletions examples/active_record/www/manager_actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
$(function () {
var controller_url = '';
//tasks list page
$('.run_task').click(function () {
if (confirm('Are you sure?')) {
$('#output_section').show();
$('#task_output_container').text('Running...');
$.post('?m=runTask', {task_id: $(this).attr('href')}, function (data) {
$.post(controller_url + '?m=runTask', {task_id: $(this).attr('href')}, function (data) {
$('#task_output_container').html(data);
})
}
Expand All @@ -25,19 +26,19 @@ $(function () {
if (confirm('Are you sure?')) {
$('#output_section').show();
$('#task_output_container').text('Running...');
$.post('?m=runTask', {task_id: tasks}, function (data) {
$.post(controller_url + '?m=runTask', {task_id: tasks}, function (data) {
$('#task_output_container').html(data);
})
}
} else {
$.post('?m=tasksUpdate', {task_id: tasks, action: action}, function () {
$.post(controller_url + '?m=tasksUpdate', {task_id: tasks, action: action}, function () {
window.location.reload();
});
}
return false;
});
$('.show_output').click(function () {
$.post('?m=getOutput', {task_run_id: $(this).attr('href')}, function (data) {
$.post(controller_url + '?m=getOutput', {task_run_id: $(this).attr('href')}, function (data) {
$('#output_container').html(data);
return false;
})
Expand All @@ -46,7 +47,7 @@ $(function () {
if (confirm('Are you sure?')) {
$('#output_section').show();
$('#task_output_container').text('Running...');
$.post('?m=runTask', {custom_task: $('#command').val()}, function (data) {
$.post(controller_url + '?m=runTask', {custom_task: $('#command').val()}, function (data) {
$('#task_output_container').html(data);
})
}
Expand All @@ -59,7 +60,7 @@ $(function () {
});

function getRunDates() {
$.post('?m=getDates', {time: $('#time').val()}, function (data) {
$.post(controller_url + '?m=getDates', {time: $('#time').val()}, function (data) {
$('#dates_list').html(data);
})
}
Expand All @@ -78,7 +79,7 @@ $(function () {

//export page
$('#parse_crontab_form').submit(function () {
$.post('?m=parseCrontab', $(this).serialize(), function (data) {
$.post(controller_url + '?m=parseCrontab', $(this).serialize(), function (data) {
var list = '';
data.forEach(function (element) {
element.forEach(function (el) {
Expand All @@ -91,7 +92,7 @@ $(function () {
return false;
});
$('#export_form').submit(function () {
$.post('?m=exportTasks', $(this).serialize(), function (data) {
$.post(controller_url + '?m=exportTasks', $(this).serialize(), function (data) {
var list = '';
data.forEach(function (element) {
list += '' + element + '<br>';
Expand Down
41 changes: 21 additions & 20 deletions examples/codeigniter/application/controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class TasksController extends CI_Controller
{
const CONTROLLERS_FOLDER = __DIR__ . '/../models';
private $controller_folder;

public function __construct()
{
Expand All @@ -20,22 +20,23 @@ public function __construct()
$this->load->model('DbBaseModel');
$this->load->model('Task', 'task');
$this->load->model('TaskRun', 'task_run');
$this->controller_folder = __DIR__ . '/../models';

TaskManager::set_setting(TaskManager::SETTING_LOAD_CLASS, true);
TaskManager::set_setting(TaskManager::SETTING_CLASS_FOLDERS, self::CONTROLLERS_FOLDER);
TaskManager::setSetting(TaskManager::SETTING_LOAD_CLASS, true);
TaskManager::setSetting(TaskManager::SETTING_CLASS_FOLDERS, $this->controller_folder);
}

public function index()
{
$this->load->view('tasks/tasks_list', [
'tasks' => Task::findAll(['not_in' => ['status', TaskInterface::TASK_STATUS_DELETED]]),
'methods' => TaskManager::getAllMethods(self::CONTROLLERS_FOLDER),
]);
$this->load->view('tasks/tasks_list', array(
'tasks' => Task::findAll(array('not_in' => array('status', TaskInterface::TASK_STATUS_DELETED))),
'methods' => TaskManager::getAllMethods($this->controller_folder),
));
}

public function export()
{
$this->load->view('tasks/export', []);
$this->load->view('tasks/export', array());
}

public function parseCrontab()
Expand All @@ -49,8 +50,8 @@ public function parseCrontab()
public function exportTasks()
{
if (isset($_POST['folder'])) {
$tasks = Task::findAll(['in' => ['status', [TaskInterface::TASK_STATUS_ACTIVE, TaskInterface::TASK_STATUS_INACTIVE]]]);
$result = [];
$tasks = Task::findAll(array('in' => array('status', array(TaskInterface::TASK_STATUS_ACTIVE, TaskInterface::TASK_STATUS_INACTIVE))));
$result = array();
foreach ($tasks as $t) {
$line = TaskManager::getTaskCrontabLine($t, $_POST['folder'], $_POST['php'], $_POST['file']);
$result[] = nl2br($line);
Expand All @@ -63,13 +64,13 @@ public function taskLog()
{
$task_id = isset($_GET['task_id']) ? $_GET['task_id'] : null;
$runs = TaskRun::getLast($task_id);
$this->load->view('tasks/runs_list', ['runs' => $runs]);
$this->load->view('tasks/runs_list', array('runs' => $runs));
}

public function runTask()
{
if (isset($_POST['task_id'])) {
$tasks = !is_array($_POST['task_id']) ? [$_POST['task_id']] : $_POST['task_id'];
$tasks = !is_array($_POST['task_id']) ? array($_POST['task_id']) : $_POST['task_id'];
foreach ($tasks as $t) {
$task = Task::findByPk($t);
/**
Expand Down Expand Up @@ -134,25 +135,25 @@ public function taskEdit()
$task = TaskManager::editTask($task, $_POST['time'], $_POST['command'], $_POST['status'], $_POST['comment']);
}

$this->load->view('tasks/task_edit', [
$this->load->view('tasks/task_edit', array(
'task' => $task,
'methods' => TaskManager::getAllMethods(self::CONTROLLERS_FOLDER),
]);
'methods' => TaskManager::getAllMethods($this->controller_folder),
));
}

public function tasksUpdate()
{
if (isset($_POST['task_id'])) {
$tasks = Task::findAll(['in' => ['task_id', $_POST['task_id']]]);
$tasks = Task::findAll(array('in' => array('task_id', $_POST['task_id'])));
foreach ($tasks as $t) {
/**
* @var Task $t
*/
$action_status = [
$action_status = array(
'Enable' => TaskInterface::TASK_STATUS_ACTIVE,
'Disable' => TaskInterface::TASK_STATUS_INACTIVE,
'Delete' => TaskInterface::TASK_STATUS_DELETED,
];
);
$t->setStatus($action_status[$_POST['action']]);
$t->taskSave();
}
Expand All @@ -169,10 +170,10 @@ public function tasksReport()
$date_begin = isset($_GET['date_begin']) ? $_GET['date_begin'] : date('Y-m-d', strtotime('-6 day'));
$date_end = isset($_GET['date_end']) ? $_GET['date_end'] : date('Y-m-d');

$this->load->view('tasks/report', [
$this->load->view('tasks/report', array(
'report' => Task::getReport($date_begin, $date_end),
'date_begin' => $date_begin,
'date_end' => $date_end,
]);
));
}
}
Loading

0 comments on commit 68e8367

Please sign in to comment.