*/
WCF.ACP.Cronjob = { };
+/**
+ * Handles the manual execution of cronjobs.
+ */
+WCF.ACP.Cronjob.ExecutionHandler = Class.extend({
+ /**
+ * notification object
+ * @var WCF.System.Notification
+ */
+ _notification: null,
+
+ /**
+ * action proxy
+ * @var WCF.Action.Proxy
+ */
+ _proxy: null,
+
+ /**
+ * Initializes WCF.ACP.Cronjob.ExecutionHandler object.
+ */
+ init: function() {
+ this._proxy = new WCF.Action.Proxy({
+ success: $.proxy(this._success, this)
+ });
+
+ $('.jsCronjobRow .jsExecuteButton').click($.proxy(this._click, this));
+
+ this._notification = new WCF.System.Notification(WCF.Language.get('wcf.global.success'), 'success');
+ },
+
+ /**
+ * Handles a click on an execute button.
+ *
+ * @param object event
+ */
+ _click: function(event) {
+ this._proxy.setOption('data', {
+ actionName: 'execute',
+ className: 'wcf\\data\\cronjob\\CronjobAction',
+ objectIDs: [ $(event.target).data('objectID') ]
+ });
+
+ this._proxy.sendRequest();
+ },
+
+ /**
+ * Handles successful cronjob execution.
+ *
+ * @param object data
+ * @param string textStatus
+ * @param jQuery jqXHR
+ */
+ _success: function(data, textStatus, jqXHR) {
+ $('.jsCronjobRow').each($.proxy(function(index, row) {
+ var $button = $(row).find('.jsExecuteButton');
+ var $objectID = ($button).data('objectID');
+
+ if (WCF.inArray($objectID, data.objectIDs)) {
+ if (data.returnValues[$objectID]) {
+ // insert feedback here
+ $(row).find('td.columnNextExec').html(data.returnValues[$objectID].formatted);
+ $(row).wcfHighlight();
+ }
+
+ this._notification.show();
+
+ return false;
+ }
+ }, this));
+ }
+});
+
/**
* Handles the cronjob log list.
*/
$(function() {
new WCF.Action.Delete('wcf\\data\\cronjob\\CronjobAction', '.jsCronjobRow');
new WCF.Action.Toggle('wcf\\data\\cronjob\\CronjobAction', '.jsCronjobRow');
- new WCF.Action.SimpleProxy({
- action: 'execute',
- className: 'wcf\\data\\cronjob\\CronjobAction',
- elements: $('.jsCronjobRow .jsExecuteButton')
- }, {
- success: function(data, statusText, jqXHR) {
- $('.jsCronjobRow').each(function(index, row) {
- var $button = $(row).find('.jsExecuteButton');
- var $objectID = ($button).data('objectID');
-
- if (WCF.inArray($objectID, data.objectIDs) && data.returnValues[$objectID]) {
- // insert feedback here
- $(row).find('td.columnNextExec').html(data.returnValues[$objectID].formatted);
- $(row).wcfHighlight();
- }
- });
- }
- });
+
+ new WCF.ACP.Cronjob.ExecutionHandler();
});
//]]>
</script>
$executable = new $className();
// execute cronjob
- $error = '';
+ $exception = null;
try {
$executable->execute(new Cronjob($cronjob->cronjobID));
}
- catch (\Exception $e) {
- $error = $e->getMessage();
- }
+ catch (\Exception $exception) { }
CronjobLogEditor::create(array(
'cronjobID' => $cronjob->cronjobID,
'execTime' => TIME_NOW,
- 'success' => ($error == '' ? 1 : 0),
- 'error' => $error
+ 'success' => ($exception ? 0 : 1),
+ 'error' => ($exception ? $exception->getMessage() : '')
));
// calculate next exec-time
'afterNextExec' => $cronjob->getNextExec(($nextExec + 120))
);
- // if no error: reset fail counter
- if ($error == '') {
- $data['failCount'] = 0;
-
- // if cronjob has been disabled because of too many
- // failed executions, enable it again
- if ($cronjob->failCount == Cronjob::MAX_FAIL_COUNT && $cronjob->isDisabled) {
- $data['isDisabled'] = 0;
- }
- }
// cronjob failed
- else {
+ if ($exception) {
if ($cronjob->failCount < Cronjob::MAX_FAIL_COUNT) {
$data['failCount'] = $cronjob->failCount + 1;
}
$data['isDisabled'] = 1;
}
}
+ // if no error: reset fail counter
+ else {
+ $data['failCount'] = 0;
+
+ // if cronjob has been disabled because of too many
+ // failed executions, enable it again
+ if ($cronjob->failCount == Cronjob::MAX_FAIL_COUNT && $cronjob->isDisabled) {
+ $data['isDisabled'] = 0;
+ }
+ }
$cronjob->update($data);
// build the return value
- $dateTime = DateUtil::getDateTimeByTimestamp($nextExec);
- $return[$cronjob->cronjobID] = array(
- 'time' => $nextExec,
- 'formatted' => str_replace(
- '%time%',
- DateUtil::format($dateTime, DateUtil::TIME_FORMAT),
- str_replace(
- '%date%',
- DateUtil::format($dateTime, DateUtil::DATE_FORMAT),
- WCF::getLanguage()->get('wcf.date.dateTimeFormat')
+ if ($exception === null && !$cronjob->isDisabled) {
+ $dateTime = DateUtil::getDateTimeByTimestamp($nextExec);
+ $return[$cronjob->cronjobID] = array(
+ 'time' => $nextExec,
+ 'formatted' => str_replace(
+ '%time%',
+ DateUtil::format($dateTime, DateUtil::TIME_FORMAT),
+ str_replace(
+ '%date%',
+ DateUtil::format($dateTime, DateUtil::DATE_FORMAT),
+ WCF::getLanguage()->get('wcf.date.dateTimeFormat')
+ )
)
- )
- );
+ );
+ }
// we are finished
$cronjob->update(array('state' => Cronjob::READY));
+
+ // throw exception again to show error message
+ if ($exception) {
+ throw $exception;
+ }
}
return $return;