Newer
Older
<?php
/**
* This File contains QUI\Cron\Manager
*/
namespace QUI\Cron;
/**
* Cron Manager
*
* @author www.pcsg.de (Henning Leutz)
* @error 1001 - Cannot add Cron. Cron not exists
* @error 1002 - Cannot edit Cron. Cron command not exists
* @param string $cron - Name of the Cron
* @param string $min - On which minute should it start
* @param string $hour - On which hour should it start
* @param string $day - On which day should it start
* @param string $month - On which month should it start
* @param string $dayOfWeek - day of week (0 - 6) (0 to 6 are Sunday to Saturday,
* or use names; 7 is Sunday, the same as 0)
* @param array $params - Cron Parameter
public function add($cron, $min, $hour, $day, $month, $dayOfWeek, $params = array())
QUI::getDataBase()->insert($this->table(), array(
'active' => 1,
'exec' => $cronData['exec'],
'title' => $cronData['title'],
'min' => $min,
'hour' => $hour,
'day' => $day,
'month' => $month,
'dayOfWeek' => $dayOfWeek,
'params' => json_encode($params)
QUI::getLocale()->get(
'quiqqer/cron',
'message.cron.succesful.added'
)
* @param string $cron - Name of the Cron
* @param integer $cronId
* @param string $min
* @param string $hour
* @param string $day
* @param string $month
* @param string $dayOfWeek
* @param array $params
public function edit(
$cronId,
$cron,
$min,
$hour,
$day,
$month,
$params = array()
) {
Permission::checkPermission('quiqqer.cron.edit');
// test the cron data
CronExpression::factory(
"$min $hour $day $month $dayOfWeek"
} catch (\Exception $Exception) {
throw new QUI\Exception($Exception->getMessage());
QUI::getDataBase()->update($this->table(), array(
'exec' => $cronData['exec'],
'title' => $cronData['title'],
'min' => $min,
'hour' => $hour,
'day' => $day,
'month' => $month,
'dayOfWeek' => $dayOfWeek,
'params' => json_encode($params)
QUI::getLocale()->get(
'quiqqer/cron',
'message.cron.succesful.edit'
)
/**
* activate a cron in the cron list
*/
public function activateCron($cronId)
{
array('active' => 1),
array('id' => (int)$cronId)
);
}
/**
* deactivate a cron in the cron list
*/
public function deactivateCron($cronId)
{
array('active' => 0),
array('id' => (int)$cronId)
);
}
/**
* Delete the crons
*/
public function deleteCronIds($ids)
{
$id = (int)$id;
return;
}
'id' => $id
));
}
}
/**
* Execute all upcoming crons
*/
public function execute()
{
$list = $this->getList();
$time = time();
continue;
}
$lastexec = $entry['lastexec'];
$min = $entry['min'];
$hour = $entry['hour'];
$day = $entry['day'];
$month = $entry['month'];
$dayOfWeek = '*';
if (isset($entry['dayOfMonth']) && !empty($entry['dayOfMonth'])) {
$dayOfWeek = $entry['dayOfMonth'];
}
"$min $hour $day $month $dayOfWeek"
);
// no execute
continue;
}
// execute cron
} catch (\Exception $Exception) {
$message = print_r($entry, true);
$message .= "\n" . $Exception->getMessage();
self::log($message);
QUI::getMessagesHandler()->addError($message);
}
}
/**
* Execute a cron
*
* @return \QUI\Cron\Manager
*/
public function executeCron($cronId)
{
if (!$cronData) {
throw new QUI\Exception('Cron ID not exist');
}
if (isset($cronData['params'])) {
$cronDataParams = json_decode($cronData['params'], true);
if (is_array($cronDataParams)) {
foreach ($cronDataParams as $entry) {
$params[$entry['name']] = $entry['value'];
call_user_func_array($cronData['exec'], array($params, $this));
QUI::getMessagesHandler()->addSuccess(
QUI::getLocale()->get(
'quiqqer/cron',
'message.cron.succesful.executed'
)
);
return $this;
}
/**
* Return the Crons which are available and from other Plugins provided
*
$packageList = $PackageManager->getInstalled();
$dir = OPT_DIR . $entry['name'] . '/';
$cronFile = $dir . 'cron.xml';
continue;
}
$result = array_merge(
$result,
);
}
return $result;
}
/**
* Return the data of a inserted cron
*
*/
public function getCronById($cronId)
{
'where' => array(
'id' => (int)$cronId
),
'limit' => 1
));
}
/**
* Return the data of a specific cron from the available cron list
* This cron is not in the cron list
*
*/
public function getCronData($cron)
{
$availableCrons = $this->getAvailableCrons();
// check if cron is available
foreach ($availableCrons as $entry) {
if ($entry['title'] == $cron) {
return $entry;
}
}
return false;
}

Henning Leutz
committed
*
* @param array $params - select params -> (page, perPage)

Henning Leutz
committed
* @return array

Henning Leutz
committed
$limit = '0,20';
$order = 'lastexec DESC';

Henning Leutz
committed
$start = (int)$params['page'] - 1;
$limit = $start . ',' . (int)$params['perPage'];

Henning Leutz
committed
}
$data = QUI::getDataBase()->fetch(array(

Henning Leutz
committed
'limit' => $limit,
'order' => $order
));
$dataOfCron = QUI::getDataBase()->fetch(array(

Henning Leutz
committed
));
$Users = QUI::getUsers();
$crons = array();

Henning Leutz
committed
$result = array();
// create assoc cron data array
foreach ($dataOfCron as $cronData) {
$crons[$cronData['id']] = $cronData;

Henning Leutz
committed
}

Henning Leutz
committed
$entry['cronTitle'] = '';
$entry['username'] = '';

Henning Leutz
committed
if (isset($crons[$entry['cronid']])) {
$entry['cronTitle'] = $crons[$entry['cronid']]['title'];

Henning Leutz
committed
}
try {
$entry['username'] = $Users->get($entry['uid'])->getName();

Henning Leutz
committed

Henning Leutz
committed
}
$result[] = $entry;
}
return $result;
}
/**
* Return the history count, how many history entries exist
*

Henning Leutz
committed
*/
public function getHistoryCount()
{
$result = QUI::getDataBase()->fetch(array(

Henning Leutz
committed
return $result[0]['id'];
/**
* Checks if a specific cron is already set up
*
* @param string $cron - cron title
* @return bool
*/
public function isCronSetUp($cron)
{
$list = $this->getList();
foreach ($list as $entry) {
if ($entry['title'] == $cron) {
return true;
}
}
return false;
}
return QUI_DB_PRFX . 'cron';
return QUI_DB_PRFX . 'cron_history';
$Dom = QUI\Utils\XML::getDomFromXml($file);
$list = $Crons->getElementsByTagName('cron');
return array();
}
$result = array();
for ($i = 0; $i < $list->length; $i++) {
$Cron = $list->item($i);
$title = '';
$desc = '';
$Title = $Cron->getElementsByTagName('title');
$Desc = $Cron->getElementsByTagName('description');
$title = QUI\Utils\DOM::getTextFromNode($Title->item(0));
\QUI\System\Log::writeRecursive($title);
$desc = QUI\Utils\DOM::getTextFromNode($Desc->item(0));
'name' => $Param->getAttribute('name'),
'type' => $Param->getAttribute('type')
$result[] = array(
'title' => $title,
'description' => $desc,
/**
* Print a message to the log cron.log
*
* @param String $message - Message
*/