Skip to content
Code-Schnipsel Gruppen Projekte
Commit 00863517 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

cron aktivieren, deaktivieren

Übergeordneter e38095cd
Keine zugehörigen Branchen gefunden
Keine zugehörigen Tags gefunden
Keine zugehörigen Merge Requests gefunden
<?php
/**
* activate a cron
* @param Integer $cronId - Cron-ID
*/
function package_quiqqer_cron_ajax_cron_activate($cronId)
{
$Manager = new \QUI\Cron\Manager();
$Manager->activateCron( $cronId );
}
\QUI::$Ajax->register(
'package_quiqqer_cron_ajax_cron_activate',
array( 'cronId' ),
'Permission::checkAdminUser'
);
<?php
/**
* deactivate a cron
* @param Integer $cronId - Cron-ID
*/
function package_quiqqer_cron_ajax_cron_deactivate($cronId)
{
$Manager = new \QUI\Cron\Manager();
$Manager->deactivateCron( $cronId );
}
\QUI::$Ajax->register(
'package_quiqqer_cron_ajax_cron_deactivate',
array( 'cronId' ),
'Permission::checkAdminUser'
);
<?php
/**
* Toggle the status of a cron
*
* @param Integer $cronId
* @throws \QUI\Exception
*/
function package_quiqqer_cron_ajax_cron_toggle($cronId)
{
$Manager = new \QUI\Cron\Manager();
$data = $Manager->getCronById( $cronId );
if ( !$data ) {
throw new \QUI\Exception( 'Cron not exists', 404 );
}
if ( $data['active'] == 1 )
{
$Manager->deactivateCron( $cronId );
} else
{
$Manager->activateCron( $cronId );
}
}
\QUI::$Ajax->register(
'package_quiqqer_cron_ajax_cron_toggle',
array( 'cronId' ),
'Permission::checkAdminUser'
);
......@@ -55,6 +55,26 @@ define('package/quiqqer/cron/bin/Manager', [
return;
}
var i, len, Btn;
for ( i = 0, len = result.length; i < len; i++ )
{
result[ i ].status = {
title : 'Cron aktivieren / deaktivieren',
icon : result[ i ].active ? 'icon-ok' : 'icon-remove',
cronId : result[ i ].id,
events :
{
onClick : function(Btn)
{
self.toggleStatusOfCron(
Btn.getAttribute( 'cronId' )
);
}
}
};
}
self.$Grid.setData({
data : result
});
......@@ -71,27 +91,35 @@ define('package/quiqqer/cron/bin/Manager', [
*/
$onCreate : function()
{
var self = this;
this.addButton(
new QUIButton({
text : 'Cron hinzufügen',
textimage : 'icon-plus',
events :
{
onClick : function()
{
require([
'package/quiqqer/cron/bin/AddCronWindow'
], function(Window)
{
new Window({
onClick : function() {
self.openAddCronWindow();
}
}
})
);
}).open();
});
this.addButton(
new QUIButton({
text : 'Markierte Cron löschen',
textimage : 'icon-trash',
events :
{
onClick : function() {
self.deleteMarkedCrons();
}
}
})
);
var Content = this.getContent(),
size = Content.getSize(),
......@@ -107,9 +135,14 @@ define('package/quiqqer/cron/bin/Manager', [
this.$Grid = new Grid(Container, {
columnModel : [{
header : 'Status',
dataIndex : 'activebtn',
dataIndex : 'status',
dataType : 'button',
width : 50
}, {
header : 'ID',
dataIndex : 'id',
dataType : 'string',
width : 50
}, {
header : 'Cron-Name',
dataIndex : 'title',
......@@ -135,16 +168,16 @@ define('package/quiqqer/cron/bin/Manager', [
dataIndex : 'month',
dataType : 'string',
width : 50
}, {
header : 'Cron-Beschreibung',
dataIndex : 'desc',
dataType : 'string',
width : 150
}, {
header : 'Parameter',
dataIndex : 'params',
dataType : 'string',
width : 150
}, {
header : 'Cron-Beschreibung',
dataIndex : 'desc',
dataType : 'string',
width : 200
}]
});
......@@ -165,7 +198,54 @@ define('package/quiqqer/cron/bin/Manager', [
this.$Grid.setHeight( size.y - 40 );
this.$Grid.setWidth( size.x - 40 );
},
/**
* Open the delete marked cron windows and delete all marked crons
*
* @return {self}
*/
deleteMarkedCrons : function()
{
return this;
},
/**
* Open the addCronWindow
*
* @return {self}
*/
openAddCronWindow : function()
{
require(['package/quiqqer/cron/bin/AddCronWindow'], function(Window) {
new Window({}).open();
});
return this;
},
/**
* Change the cron status
* If the cron is active to deactive
* If the cron is deactive to active
*
* @return {self}
*/
toggleStatusOfCron : function(cronId)
{
Ajax.post('package_quiqqer_cron_ajax_cron_toggle', function(result)
{
}, {
'package' : 'quiqqer/cron',
cronId : cronId
});
return this;
}
});
});
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<crons>
<cron exec="\QUI\Cron\">
<title>sss</title>
<description>desc</description>
<title>system:deleteTemp</title>
<description>Temporäre Daten löschen</description>
</cron>
</crons>
\ No newline at end of file
......@@ -4,6 +4,7 @@
<global>
<table name="cron">
<field type="INT( 3 ) NOT NULL AUTO_INCREMENT PRIMARY KEY">id</field>
<field type="TINYINT( 1 )">active</field>
<field type="VARCHAR( 60 ) NOT NULL">title</field>
<field type="VARCHAR( 2 ) NOT NULL">min</field>
<field type="VARCHAR( 2 ) NOT NULL">hour</field>
......@@ -11,14 +12,12 @@
<field type="VARCHAR( 2 ) NOT NULL">month</field>
<field type="TEXT NOT NULL">exec</field>
<field type="TEXT NOT NULL">params</field>
<field type="datetime NULL">lastexec</field>
<primary>id</primary>
<field type="DATETIME NULL">lastexec</field>
</table>
<table name="cron_history">
<field type="INT( 3 ) NOT NULL">cronid</field>
<field type="datetime NULL">lastexec</field>
<field type="DATETIME NULL">lastexec</field>
</table>
</global>
......
......@@ -32,6 +32,7 @@ class Manager
$cronData = $this->getCronData( $cron );
\QUI::getDataBase()->insert($this->Table(), array(
'active' => 1,
'exec' => $cronData['exec'],
'title' => $cronData['title'],
'min' => $min,
......@@ -45,6 +46,32 @@ class Manager
);
}
/**
* activate a cron in the cron list
* @param Integer $cronId - ID of the cron
*/
public function activateCron($cronId)
{
\QUI::getDataBase()->update(
$this->Table(),
array('active' => 1),
array('id' => (int)$cronId)
);
}
/**
* deactivate a cron in the cron list
* @param Integer $cronId - ID of the cron
*/
public function deactivateCron($cronId)
{
\QUI::getDataBase()->update(
$this->Table(),
array('active' => 0),
array('id' => (int)$cronId)
);
}
/**
* Return the Crons which are available and from other Plugins provided
*
......@@ -76,7 +103,34 @@ class Manager
}
/**
* Return the data of a specific cron
* Return the data of a inserted cron
*
* @param Integer $cronId - ID of the Cron
* @return Array|false - Cron Data
*/
public function getCronById($cronId)
{
$result = \QUI::getDataBase()->fetch(array(
'from' => $this->Table(),
'where' => array(
'id' => (int)$cronId
),
'limit' => 1
));
if ( !isset( $result[ 0 ] ) ) {
return false;
}
return $result[ 0 ];
}
/**
* Return the data of a specific cron from the available cron list
* This cron is not in the cron list
*
* @param String $cron - Name of the Cron
* @return Array|false - Cron Data
*/
public function getCronData($cron)
{
......
0% Lade oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren