Refactor rte_events functions to static methods
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
3923ac75d1
commit
2e52c0f1f8
@ -11,11 +11,6 @@
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
|
||||
/**
|
||||
* Include all other files
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
/**
|
||||
* Do the magic
|
||||
*/
|
||||
|
||||
622
libraries/classes/Rte/Events.php
Normal file
622
libraries/classes/Rte/Events.php
Normal file
@ -0,0 +1,622 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for event management.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin\Rte;
|
||||
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\Rte\Events class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* Sets required globals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setGlobals()
|
||||
{
|
||||
global $event_status, $event_type, $event_interval;
|
||||
|
||||
$event_status = array(
|
||||
'query' => array('ENABLE',
|
||||
'DISABLE',
|
||||
'DISABLE ON SLAVE'),
|
||||
'display' => array('ENABLED',
|
||||
'DISABLED',
|
||||
'SLAVESIDE_DISABLED')
|
||||
);
|
||||
$event_type = array('RECURRING',
|
||||
'ONE TIME');
|
||||
$event_interval = array('YEAR',
|
||||
'QUARTER',
|
||||
'MONTH',
|
||||
'DAY',
|
||||
'HOUR',
|
||||
'MINUTE',
|
||||
'WEEK',
|
||||
'SECOND',
|
||||
'YEAR_MONTH',
|
||||
'DAY_HOUR',
|
||||
'DAY_MINUTE',
|
||||
'DAY_SECOND',
|
||||
'HOUR_MINUTE',
|
||||
'HOUR_SECOND',
|
||||
'MINUTE_SECOND');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function for the events functionality
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function main()
|
||||
{
|
||||
global $db;
|
||||
|
||||
self::setGlobals();
|
||||
/**
|
||||
* Process all requests
|
||||
*/
|
||||
self::handleEditor();
|
||||
PMA_EVN_handleExport();
|
||||
/**
|
||||
* Display a list of available events
|
||||
*/
|
||||
$items = $GLOBALS['dbi']->getEvents($db);
|
||||
echo PMA_RTE_getList('event', $items);
|
||||
/**
|
||||
* Display a link for adding a new event, if
|
||||
* the user has the privileges and a link to
|
||||
* toggle the state of the event scheduler.
|
||||
*/
|
||||
echo PMA_EVN_getFooterLinks();
|
||||
} // end self::main()
|
||||
|
||||
/**
|
||||
* Handles editor requests for adding or editing an item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function handleEditor()
|
||||
{
|
||||
global $_REQUEST, $_POST, $errors, $db;
|
||||
|
||||
if (! empty($_REQUEST['editor_process_add'])
|
||||
|| ! empty($_REQUEST['editor_process_edit'])
|
||||
) {
|
||||
$sql_query = '';
|
||||
|
||||
$item_query = self::getQueryFromRequest();
|
||||
|
||||
if (! count($errors)) { // set by PMA_RTN_getQueryFromRequest()
|
||||
// Execute the created query
|
||||
if (! empty($_REQUEST['editor_process_edit'])) {
|
||||
// Backup the old trigger, in case something goes wrong
|
||||
$create_item = $GLOBALS['dbi']->getDefinition(
|
||||
$db,
|
||||
'EVENT',
|
||||
$_REQUEST['item_original_name']
|
||||
);
|
||||
$drop_item = "DROP EVENT "
|
||||
. Util::backquote($_REQUEST['item_original_name'])
|
||||
. ";\n";
|
||||
$result = $GLOBALS['dbi']->tryQuery($drop_item);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($drop_item)
|
||||
)
|
||||
. '<br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
} else {
|
||||
$result = $GLOBALS['dbi']->tryQuery($item_query);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query)
|
||||
)
|
||||
. '<br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
// We dropped the old item, but were unable to create
|
||||
// the new one. Try to restore the backup query
|
||||
$result = $GLOBALS['dbi']->tryQuery($create_item);
|
||||
$errors = checkResult(
|
||||
$result,
|
||||
__(
|
||||
'Sorry, we failed to restore the dropped event.'
|
||||
),
|
||||
$create_item,
|
||||
$errors
|
||||
);
|
||||
} else {
|
||||
$message = Message::success(
|
||||
__('Event %1$s has been modified.')
|
||||
);
|
||||
$message->addParam(
|
||||
Util::backquote($_REQUEST['item_name'])
|
||||
);
|
||||
$sql_query = $drop_item . $item_query;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 'Add a new item' mode
|
||||
$result = $GLOBALS['dbi']->tryQuery($item_query);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query)
|
||||
)
|
||||
. '<br /><br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
} else {
|
||||
$message = Message::success(
|
||||
__('Event %1$s has been created.')
|
||||
);
|
||||
$message->addParam(
|
||||
Util::backquote($_REQUEST['item_name'])
|
||||
);
|
||||
$sql_query = $item_query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($errors)) {
|
||||
$message = Message::error(
|
||||
'<b>'
|
||||
. __(
|
||||
'One or more errors have occurred while processing your request:'
|
||||
)
|
||||
. '</b>'
|
||||
);
|
||||
$message->addHtml('<ul>');
|
||||
foreach ($errors as $string) {
|
||||
$message->addHtml('<li>' . $string . '</li>');
|
||||
}
|
||||
$message->addHtml('</ul>');
|
||||
}
|
||||
|
||||
$output = Util::getMessage($message, $sql_query);
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
if ($message->isSuccess()) {
|
||||
$events = $GLOBALS['dbi']->getEvents($db, $_REQUEST['item_name']);
|
||||
$event = $events[0];
|
||||
$response->addJSON(
|
||||
'name',
|
||||
htmlspecialchars(
|
||||
mb_strtoupper($_REQUEST['item_name'])
|
||||
)
|
||||
);
|
||||
$response->addJSON('new_row', PMA_EVN_getRowForList($event));
|
||||
$response->addJSON('insert', ! empty($event));
|
||||
$response->addJSON('message', $output);
|
||||
} else {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Display a form used to add/edit a trigger, if necessary
|
||||
*/
|
||||
if (count($errors)
|
||||
|| (empty($_REQUEST['editor_process_add'])
|
||||
&& empty($_REQUEST['editor_process_edit'])
|
||||
&& (! empty($_REQUEST['add_item'])
|
||||
|| ! empty($_REQUEST['edit_item'])
|
||||
|| ! empty($_REQUEST['item_changetype'])))
|
||||
) { // FIXME: this must be simpler than that
|
||||
$operation = '';
|
||||
if (! empty($_REQUEST['item_changetype'])) {
|
||||
$operation = 'change';
|
||||
}
|
||||
// Get the data for the form (if any)
|
||||
if (! empty($_REQUEST['add_item'])) {
|
||||
$title = PMA_RTE_getWord('add');
|
||||
$item = self::getDataFromRequest();
|
||||
$mode = 'add';
|
||||
} else if (! empty($_REQUEST['edit_item'])) {
|
||||
$title = __("Edit event");
|
||||
if (! empty($_REQUEST['item_name'])
|
||||
&& empty($_REQUEST['editor_process_edit'])
|
||||
&& empty($_REQUEST['item_changetype'])
|
||||
) {
|
||||
$item = self::getDataFromName($_REQUEST['item_name']);
|
||||
if ($item !== false) {
|
||||
$item['item_original_name'] = $item['item_name'];
|
||||
}
|
||||
} else {
|
||||
$item = self::getDataFromRequest();
|
||||
}
|
||||
$mode = 'edit';
|
||||
}
|
||||
PMA_RTE_sendEditor('EVN', $mode, $item, $title, $db, $operation);
|
||||
}
|
||||
} // end self::handleEditor()
|
||||
|
||||
/**
|
||||
* This function will generate the values that are required to for the editor
|
||||
*
|
||||
* @return array Data necessary to create the editor.
|
||||
*/
|
||||
public static function getDataFromRequest()
|
||||
{
|
||||
$retval = array();
|
||||
$indices = array('item_name',
|
||||
'item_original_name',
|
||||
'item_status',
|
||||
'item_execute_at',
|
||||
'item_interval_value',
|
||||
'item_interval_field',
|
||||
'item_starts',
|
||||
'item_ends',
|
||||
'item_definition',
|
||||
'item_preserve',
|
||||
'item_comment',
|
||||
'item_definer');
|
||||
foreach ($indices as $index) {
|
||||
$retval[$index] = isset($_REQUEST[$index]) ? $_REQUEST[$index] : '';
|
||||
}
|
||||
$retval['item_type'] = 'ONE TIME';
|
||||
$retval['item_type_toggle'] = 'RECURRING';
|
||||
if (isset($_REQUEST['item_type']) && $_REQUEST['item_type'] == 'RECURRING') {
|
||||
$retval['item_type'] = 'RECURRING';
|
||||
$retval['item_type_toggle'] = 'ONE TIME';
|
||||
}
|
||||
return $retval;
|
||||
} // end self::getDataFromRequest()
|
||||
|
||||
/**
|
||||
* This function will generate the values that are required to complete
|
||||
* the "Edit event" form given the name of a event.
|
||||
*
|
||||
* @param string $name The name of the event.
|
||||
*
|
||||
* @return array Data necessary to create the editor.
|
||||
*/
|
||||
public static function getDataFromName($name)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$retval = array();
|
||||
$columns = "`EVENT_NAME`, `STATUS`, `EVENT_TYPE`, `EXECUTE_AT`, "
|
||||
. "`INTERVAL_VALUE`, `INTERVAL_FIELD`, `STARTS`, `ENDS`, "
|
||||
. "`EVENT_DEFINITION`, `ON_COMPLETION`, `DEFINER`, `EVENT_COMMENT`";
|
||||
$where = "EVENT_SCHEMA " . Util::getCollateForIS() . "="
|
||||
. "'" . $GLOBALS['dbi']->escapeString($db) . "' "
|
||||
. "AND EVENT_NAME='" . $GLOBALS['dbi']->escapeString($name) . "'";
|
||||
$query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;";
|
||||
$item = $GLOBALS['dbi']->fetchSingleRow($query);
|
||||
if (! $item) {
|
||||
return false;
|
||||
}
|
||||
$retval['item_name'] = $item['EVENT_NAME'];
|
||||
$retval['item_status'] = $item['STATUS'];
|
||||
$retval['item_type'] = $item['EVENT_TYPE'];
|
||||
if ($retval['item_type'] == 'RECURRING') {
|
||||
$retval['item_type_toggle'] = 'ONE TIME';
|
||||
} else {
|
||||
$retval['item_type_toggle'] = 'RECURRING';
|
||||
}
|
||||
$retval['item_execute_at'] = $item['EXECUTE_AT'];
|
||||
$retval['item_interval_value'] = $item['INTERVAL_VALUE'];
|
||||
$retval['item_interval_field'] = $item['INTERVAL_FIELD'];
|
||||
$retval['item_starts'] = $item['STARTS'];
|
||||
$retval['item_ends'] = $item['ENDS'];
|
||||
$retval['item_preserve'] = '';
|
||||
if ($item['ON_COMPLETION'] == 'PRESERVE') {
|
||||
$retval['item_preserve'] = " checked='checked'";
|
||||
}
|
||||
$retval['item_definition'] = $item['EVENT_DEFINITION'];
|
||||
$retval['item_definer'] = $item['DEFINER'];
|
||||
$retval['item_comment'] = $item['EVENT_COMMENT'];
|
||||
|
||||
return $retval;
|
||||
} // end self::getDataFromName()
|
||||
|
||||
/**
|
||||
* Displays a form used to add/edit an event
|
||||
*
|
||||
* @param string $mode If the editor will be used to edit an event
|
||||
* or add a new one: 'edit' or 'add'.
|
||||
* @param string $operation If the editor was previously invoked with
|
||||
* JS turned off, this will hold the name of
|
||||
* the current operation
|
||||
* @param array $item Data for the event returned by
|
||||
* self::getDataFromRequest() or
|
||||
* self::getDataFromName()
|
||||
*
|
||||
* @return string HTML code for the editor.
|
||||
*/
|
||||
public static function getEditorForm($mode, $operation, $item)
|
||||
{
|
||||
global $db, $table, $event_status, $event_type, $event_interval;
|
||||
|
||||
$modeToUpper = mb_strtoupper($mode);
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
// Escape special characters
|
||||
$need_escape = array(
|
||||
'item_original_name',
|
||||
'item_name',
|
||||
'item_type',
|
||||
'item_execute_at',
|
||||
'item_interval_value',
|
||||
'item_starts',
|
||||
'item_ends',
|
||||
'item_definition',
|
||||
'item_definer',
|
||||
'item_comment'
|
||||
);
|
||||
foreach ($need_escape as $index) {
|
||||
$item[$index] = htmlentities($item[$index], ENT_QUOTES);
|
||||
}
|
||||
$original_data = '';
|
||||
if ($mode == 'edit') {
|
||||
$original_data = "<input name='item_original_name' "
|
||||
. "type='hidden' value='{$item['item_original_name']}'/>\n";
|
||||
}
|
||||
// Handle some logic first
|
||||
if ($operation == 'change') {
|
||||
if ($item['item_type'] == 'RECURRING') {
|
||||
$item['item_type'] = 'ONE TIME';
|
||||
$item['item_type_toggle'] = 'RECURRING';
|
||||
} else {
|
||||
$item['item_type'] = 'RECURRING';
|
||||
$item['item_type_toggle'] = 'ONE TIME';
|
||||
}
|
||||
}
|
||||
if ($item['item_type'] == 'ONE TIME') {
|
||||
$isrecurring_class = ' hide';
|
||||
$isonetime_class = '';
|
||||
} else {
|
||||
$isrecurring_class = '';
|
||||
$isonetime_class = ' hide';
|
||||
}
|
||||
// Create the output
|
||||
$retval = "";
|
||||
$retval .= "<!-- START " . $modeToUpper . " EVENT FORM -->\n\n";
|
||||
$retval .= "<form class='rte_form' action='db_events.php' method='post'>\n";
|
||||
$retval .= "<input name='{$mode}_item' type='hidden' value='1' />\n";
|
||||
$retval .= $original_data;
|
||||
$retval .= Url::getHiddenInputs($db, $table) . "\n";
|
||||
$retval .= "<fieldset>\n";
|
||||
$retval .= "<legend>" . __('Details') . "</legend>\n";
|
||||
$retval .= "<table class='rte_table' style='width: 100%'>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td style='width: 20%;'>" . __('Event name') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_name' \n";
|
||||
$retval .= " value='{$item['item_name']}'\n";
|
||||
$retval .= " maxlength='64' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Status') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
$retval .= " <select name='item_status'>\n";
|
||||
foreach ($event_status['display'] as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_status']) && $item['item_status'] == $value) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Event type') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
if ($response->isAjax()) {
|
||||
$retval .= " <select name='item_type'>";
|
||||
foreach ($event_type as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_type']) && $item['item_type'] == $value) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
} else {
|
||||
$retval .= " <input name='item_type' type='hidden' \n";
|
||||
$retval .= " value='{$item['item_type']}' />\n";
|
||||
$retval .= " <div class='floatleft' style='width: 49%; "
|
||||
. "text-align: center; font-weight: bold;'>\n";
|
||||
$retval .= " {$item['item_type']}\n";
|
||||
$retval .= " </div>\n";
|
||||
$retval .= " <input style='width: 49%;' type='submit'\n";
|
||||
$retval .= " name='item_changetype'\n";
|
||||
$retval .= " value='";
|
||||
$retval .= sprintf(__('Change to %s'), $item['item_type_toggle']);
|
||||
$retval .= "' />\n";
|
||||
}
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='onetime_event_row $isonetime_class'>\n";
|
||||
$retval .= " <td>" . __('Execute at') . "</td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text' name='item_execute_at'\n";
|
||||
$retval .= " value='{$item['item_execute_at']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row $isrecurring_class'>\n";
|
||||
$retval .= " <td>" . __('Execute every') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
$retval .= " <input style='width: 49%;' type='text'\n";
|
||||
$retval .= " name='item_interval_value'\n";
|
||||
$retval .= " value='{$item['item_interval_value']}' />\n";
|
||||
$retval .= " <select style='width: 49%;' name='item_interval_field'>";
|
||||
foreach ($event_interval as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_interval_field'])
|
||||
&& $item['item_interval_field'] == $value
|
||||
) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row$isrecurring_class'>\n";
|
||||
$retval .= " <td>" . _pgettext('Start of recurring event', 'Start');
|
||||
$retval .= " </td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text'\n name='item_starts'\n";
|
||||
$retval .= " value='{$item['item_starts']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row$isrecurring_class'>\n";
|
||||
$retval .= " <td>" . _pgettext('End of recurring event', 'End') . "</td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text' name='item_ends'\n";
|
||||
$retval .= " value='{$item['item_ends']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Definition') . "</td>\n";
|
||||
$retval .= " <td><textarea name='item_definition' rows='15' cols='40'>";
|
||||
$retval .= $item['item_definition'];
|
||||
$retval .= "</textarea></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('On completion preserve') . "</td>\n";
|
||||
$retval .= " <td><input type='checkbox'\n";
|
||||
$retval .= " name='item_preserve'{$item['item_preserve']} /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Definer') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_definer'\n";
|
||||
$retval .= " value='{$item['item_definer']}' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Comment') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_comment' maxlength='64'\n";
|
||||
$retval .= " value='{$item['item_comment']}' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "</table>\n";
|
||||
$retval .= "</fieldset>\n";
|
||||
if ($response->isAjax()) {
|
||||
$retval .= "<input type='hidden' name='editor_process_{$mode}'\n";
|
||||
$retval .= " value='true' />\n";
|
||||
$retval .= "<input type='hidden' name='ajax_request' value='true' />\n";
|
||||
} else {
|
||||
$retval .= "<fieldset class='tblFooters'>\n";
|
||||
$retval .= " <input type='submit' name='editor_process_{$mode}'\n";
|
||||
$retval .= " value='" . __('Go') . "' />\n";
|
||||
$retval .= "</fieldset>\n";
|
||||
}
|
||||
$retval .= "</form>\n\n";
|
||||
$retval .= "<!-- END " . $modeToUpper . " EVENT FORM -->\n\n";
|
||||
|
||||
return $retval;
|
||||
} // end self::getEditorForm()
|
||||
|
||||
/**
|
||||
* Composes the query necessary to create an event from an HTTP request.
|
||||
*
|
||||
* @return string The CREATE EVENT query.
|
||||
*/
|
||||
public static function getQueryFromRequest()
|
||||
{
|
||||
global $_REQUEST, $errors, $event_status, $event_type, $event_interval;
|
||||
|
||||
$query = 'CREATE ';
|
||||
if (! empty($_REQUEST['item_definer'])) {
|
||||
if (mb_strpos($_REQUEST['item_definer'], '@') !== false
|
||||
) {
|
||||
$arr = explode('@', $_REQUEST['item_definer']);
|
||||
$query .= 'DEFINER=' . Util::backquote($arr[0]);
|
||||
$query .= '@' . Util::backquote($arr[1]) . ' ';
|
||||
} else {
|
||||
$errors[] = __('The definer must be in the "username@hostname" format!');
|
||||
}
|
||||
}
|
||||
$query .= 'EVENT ';
|
||||
if (! empty($_REQUEST['item_name'])) {
|
||||
$query .= Util::backquote($_REQUEST['item_name']) . ' ';
|
||||
} else {
|
||||
$errors[] = __('You must provide an event name!');
|
||||
}
|
||||
$query .= 'ON SCHEDULE ';
|
||||
if (! empty($_REQUEST['item_type'])
|
||||
&& in_array($_REQUEST['item_type'], $event_type)
|
||||
) {
|
||||
if ($_REQUEST['item_type'] == 'RECURRING') {
|
||||
if (! empty($_REQUEST['item_interval_value'])
|
||||
&& !empty($_REQUEST['item_interval_field'])
|
||||
&& in_array($_REQUEST['item_interval_field'], $event_interval)
|
||||
) {
|
||||
$query .= 'EVERY ' . intval($_REQUEST['item_interval_value']) . ' ';
|
||||
$query .= $_REQUEST['item_interval_field'] . ' ';
|
||||
} else {
|
||||
$errors[]
|
||||
= __('You must provide a valid interval value for the event.');
|
||||
}
|
||||
if (! empty($_REQUEST['item_starts'])) {
|
||||
$query .= "STARTS '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_starts'])
|
||||
. "' ";
|
||||
}
|
||||
if (! empty($_REQUEST['item_ends'])) {
|
||||
$query .= "ENDS '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_ends'])
|
||||
. "' ";
|
||||
}
|
||||
} else {
|
||||
if (! empty($_REQUEST['item_execute_at'])) {
|
||||
$query .= "AT '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_execute_at'])
|
||||
. "' ";
|
||||
} else {
|
||||
$errors[]
|
||||
= __('You must provide a valid execution time for the event.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errors[] = __('You must provide a valid type for the event.');
|
||||
}
|
||||
$query .= 'ON COMPLETION ';
|
||||
if (empty($_REQUEST['item_preserve'])) {
|
||||
$query .= 'NOT ';
|
||||
}
|
||||
$query .= 'PRESERVE ';
|
||||
if (! empty($_REQUEST['item_status'])) {
|
||||
foreach ($event_status['display'] as $key => $value) {
|
||||
if ($value == $_REQUEST['item_status']) {
|
||||
$query .= $event_status['query'][$key] . ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! empty($_REQUEST['item_comment'])) {
|
||||
$query .= "COMMENT '" . $GLOBALS['dbi']->escapeString(
|
||||
$_REQUEST['item_comment']
|
||||
) . "' ";
|
||||
}
|
||||
$query .= 'DO ';
|
||||
if (! empty($_REQUEST['item_definition'])) {
|
||||
$query .= $_REQUEST['item_definition'];
|
||||
} else {
|
||||
$errors[] = __('You must provide an event definition.');
|
||||
}
|
||||
|
||||
return $query;
|
||||
} // end self::getQueryFromRequest()
|
||||
}
|
||||
@ -1,615 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for event management.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Url;
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets required globals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_EVN_setGlobals()
|
||||
{
|
||||
global $event_status, $event_type, $event_interval;
|
||||
|
||||
$event_status = array(
|
||||
'query' => array('ENABLE',
|
||||
'DISABLE',
|
||||
'DISABLE ON SLAVE'),
|
||||
'display' => array('ENABLED',
|
||||
'DISABLED',
|
||||
'SLAVESIDE_DISABLED')
|
||||
);
|
||||
$event_type = array('RECURRING',
|
||||
'ONE TIME');
|
||||
$event_interval = array('YEAR',
|
||||
'QUARTER',
|
||||
'MONTH',
|
||||
'DAY',
|
||||
'HOUR',
|
||||
'MINUTE',
|
||||
'WEEK',
|
||||
'SECOND',
|
||||
'YEAR_MONTH',
|
||||
'DAY_HOUR',
|
||||
'DAY_MINUTE',
|
||||
'DAY_SECOND',
|
||||
'HOUR_MINUTE',
|
||||
'HOUR_SECOND',
|
||||
'MINUTE_SECOND');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function for the events functionality
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_EVN_main()
|
||||
{
|
||||
global $db;
|
||||
|
||||
PMA_EVN_setGlobals();
|
||||
/**
|
||||
* Process all requests
|
||||
*/
|
||||
PMA_EVN_handleEditor();
|
||||
PMA_EVN_handleExport();
|
||||
/**
|
||||
* Display a list of available events
|
||||
*/
|
||||
$items = $GLOBALS['dbi']->getEvents($db);
|
||||
echo PMA_RTE_getList('event', $items);
|
||||
/**
|
||||
* Display a link for adding a new event, if
|
||||
* the user has the privileges and a link to
|
||||
* toggle the state of the event scheduler.
|
||||
*/
|
||||
echo PMA_EVN_getFooterLinks();
|
||||
} // end PMA_EVN_main()
|
||||
|
||||
/**
|
||||
* Handles editor requests for adding or editing an item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_EVN_handleEditor()
|
||||
{
|
||||
global $_REQUEST, $_POST, $errors, $db;
|
||||
|
||||
if (! empty($_REQUEST['editor_process_add'])
|
||||
|| ! empty($_REQUEST['editor_process_edit'])
|
||||
) {
|
||||
$sql_query = '';
|
||||
|
||||
$item_query = PMA_EVN_getQueryFromRequest();
|
||||
|
||||
if (! count($errors)) { // set by PMA_RTN_getQueryFromRequest()
|
||||
// Execute the created query
|
||||
if (! empty($_REQUEST['editor_process_edit'])) {
|
||||
// Backup the old trigger, in case something goes wrong
|
||||
$create_item = $GLOBALS['dbi']->getDefinition(
|
||||
$db,
|
||||
'EVENT',
|
||||
$_REQUEST['item_original_name']
|
||||
);
|
||||
$drop_item = "DROP EVENT "
|
||||
. PhpMyAdmin\Util::backquote($_REQUEST['item_original_name'])
|
||||
. ";\n";
|
||||
$result = $GLOBALS['dbi']->tryQuery($drop_item);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($drop_item)
|
||||
)
|
||||
. '<br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
} else {
|
||||
$result = $GLOBALS['dbi']->tryQuery($item_query);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query)
|
||||
)
|
||||
. '<br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
// We dropped the old item, but were unable to create
|
||||
// the new one. Try to restore the backup query
|
||||
$result = $GLOBALS['dbi']->tryQuery($create_item);
|
||||
$errors = checkResult(
|
||||
$result,
|
||||
__(
|
||||
'Sorry, we failed to restore the dropped event.'
|
||||
),
|
||||
$create_item,
|
||||
$errors
|
||||
);
|
||||
} else {
|
||||
$message = PhpMyAdmin\Message::success(
|
||||
__('Event %1$s has been modified.')
|
||||
);
|
||||
$message->addParam(
|
||||
PhpMyAdmin\Util::backquote($_REQUEST['item_name'])
|
||||
);
|
||||
$sql_query = $drop_item . $item_query;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 'Add a new item' mode
|
||||
$result = $GLOBALS['dbi']->tryQuery($item_query);
|
||||
if (! $result) {
|
||||
$errors[] = sprintf(
|
||||
__('The following query has failed: "%s"'),
|
||||
htmlspecialchars($item_query)
|
||||
)
|
||||
. '<br /><br />'
|
||||
. __('MySQL said: ') . $GLOBALS['dbi']->getError(null);
|
||||
} else {
|
||||
$message = PhpMyAdmin\Message::success(
|
||||
__('Event %1$s has been created.')
|
||||
);
|
||||
$message->addParam(
|
||||
PhpMyAdmin\Util::backquote($_REQUEST['item_name'])
|
||||
);
|
||||
$sql_query = $item_query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($errors)) {
|
||||
$message = PhpMyAdmin\Message::error(
|
||||
'<b>'
|
||||
. __(
|
||||
'One or more errors have occurred while processing your request:'
|
||||
)
|
||||
. '</b>'
|
||||
);
|
||||
$message->addHtml('<ul>');
|
||||
foreach ($errors as $string) {
|
||||
$message->addHtml('<li>' . $string . '</li>');
|
||||
}
|
||||
$message->addHtml('</ul>');
|
||||
}
|
||||
|
||||
$output = PhpMyAdmin\Util::getMessage($message, $sql_query);
|
||||
$response = Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
if ($message->isSuccess()) {
|
||||
$events = $GLOBALS['dbi']->getEvents($db, $_REQUEST['item_name']);
|
||||
$event = $events[0];
|
||||
$response->addJSON(
|
||||
'name',
|
||||
htmlspecialchars(
|
||||
mb_strtoupper($_REQUEST['item_name'])
|
||||
)
|
||||
);
|
||||
$response->addJSON('new_row', PMA_EVN_getRowForList($event));
|
||||
$response->addJSON('insert', ! empty($event));
|
||||
$response->addJSON('message', $output);
|
||||
} else {
|
||||
$response->setRequestStatus(false);
|
||||
$response->addJSON('message', $message);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Display a form used to add/edit a trigger, if necessary
|
||||
*/
|
||||
if (count($errors)
|
||||
|| (empty($_REQUEST['editor_process_add'])
|
||||
&& empty($_REQUEST['editor_process_edit'])
|
||||
&& (! empty($_REQUEST['add_item'])
|
||||
|| ! empty($_REQUEST['edit_item'])
|
||||
|| ! empty($_REQUEST['item_changetype'])))
|
||||
) { // FIXME: this must be simpler than that
|
||||
$operation = '';
|
||||
if (! empty($_REQUEST['item_changetype'])) {
|
||||
$operation = 'change';
|
||||
}
|
||||
// Get the data for the form (if any)
|
||||
if (! empty($_REQUEST['add_item'])) {
|
||||
$title = PMA_RTE_getWord('add');
|
||||
$item = PMA_EVN_getDataFromRequest();
|
||||
$mode = 'add';
|
||||
} else if (! empty($_REQUEST['edit_item'])) {
|
||||
$title = __("Edit event");
|
||||
if (! empty($_REQUEST['item_name'])
|
||||
&& empty($_REQUEST['editor_process_edit'])
|
||||
&& empty($_REQUEST['item_changetype'])
|
||||
) {
|
||||
$item = PMA_EVN_getDataFromName($_REQUEST['item_name']);
|
||||
if ($item !== false) {
|
||||
$item['item_original_name'] = $item['item_name'];
|
||||
}
|
||||
} else {
|
||||
$item = PMA_EVN_getDataFromRequest();
|
||||
}
|
||||
$mode = 'edit';
|
||||
}
|
||||
PMA_RTE_sendEditor('EVN', $mode, $item, $title, $db, $operation);
|
||||
}
|
||||
} // end PMA_EVN_handleEditor()
|
||||
|
||||
/**
|
||||
* This function will generate the values that are required to for the editor
|
||||
*
|
||||
* @return array Data necessary to create the editor.
|
||||
*/
|
||||
function PMA_EVN_getDataFromRequest()
|
||||
{
|
||||
$retval = array();
|
||||
$indices = array('item_name',
|
||||
'item_original_name',
|
||||
'item_status',
|
||||
'item_execute_at',
|
||||
'item_interval_value',
|
||||
'item_interval_field',
|
||||
'item_starts',
|
||||
'item_ends',
|
||||
'item_definition',
|
||||
'item_preserve',
|
||||
'item_comment',
|
||||
'item_definer');
|
||||
foreach ($indices as $index) {
|
||||
$retval[$index] = isset($_REQUEST[$index]) ? $_REQUEST[$index] : '';
|
||||
}
|
||||
$retval['item_type'] = 'ONE TIME';
|
||||
$retval['item_type_toggle'] = 'RECURRING';
|
||||
if (isset($_REQUEST['item_type']) && $_REQUEST['item_type'] == 'RECURRING') {
|
||||
$retval['item_type'] = 'RECURRING';
|
||||
$retval['item_type_toggle'] = 'ONE TIME';
|
||||
}
|
||||
return $retval;
|
||||
} // end PMA_EVN_getDataFromRequest()
|
||||
|
||||
/**
|
||||
* This function will generate the values that are required to complete
|
||||
* the "Edit event" form given the name of a event.
|
||||
*
|
||||
* @param string $name The name of the event.
|
||||
*
|
||||
* @return array Data necessary to create the editor.
|
||||
*/
|
||||
function PMA_EVN_getDataFromName($name)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$retval = array();
|
||||
$columns = "`EVENT_NAME`, `STATUS`, `EVENT_TYPE`, `EXECUTE_AT`, "
|
||||
. "`INTERVAL_VALUE`, `INTERVAL_FIELD`, `STARTS`, `ENDS`, "
|
||||
. "`EVENT_DEFINITION`, `ON_COMPLETION`, `DEFINER`, `EVENT_COMMENT`";
|
||||
$where = "EVENT_SCHEMA " . PhpMyAdmin\Util::getCollateForIS() . "="
|
||||
. "'" . $GLOBALS['dbi']->escapeString($db) . "' "
|
||||
. "AND EVENT_NAME='" . $GLOBALS['dbi']->escapeString($name) . "'";
|
||||
$query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;";
|
||||
$item = $GLOBALS['dbi']->fetchSingleRow($query);
|
||||
if (! $item) {
|
||||
return false;
|
||||
}
|
||||
$retval['item_name'] = $item['EVENT_NAME'];
|
||||
$retval['item_status'] = $item['STATUS'];
|
||||
$retval['item_type'] = $item['EVENT_TYPE'];
|
||||
if ($retval['item_type'] == 'RECURRING') {
|
||||
$retval['item_type_toggle'] = 'ONE TIME';
|
||||
} else {
|
||||
$retval['item_type_toggle'] = 'RECURRING';
|
||||
}
|
||||
$retval['item_execute_at'] = $item['EXECUTE_AT'];
|
||||
$retval['item_interval_value'] = $item['INTERVAL_VALUE'];
|
||||
$retval['item_interval_field'] = $item['INTERVAL_FIELD'];
|
||||
$retval['item_starts'] = $item['STARTS'];
|
||||
$retval['item_ends'] = $item['ENDS'];
|
||||
$retval['item_preserve'] = '';
|
||||
if ($item['ON_COMPLETION'] == 'PRESERVE') {
|
||||
$retval['item_preserve'] = " checked='checked'";
|
||||
}
|
||||
$retval['item_definition'] = $item['EVENT_DEFINITION'];
|
||||
$retval['item_definer'] = $item['DEFINER'];
|
||||
$retval['item_comment'] = $item['EVENT_COMMENT'];
|
||||
|
||||
return $retval;
|
||||
} // end PMA_EVN_getDataFromName()
|
||||
|
||||
/**
|
||||
* Displays a form used to add/edit an event
|
||||
*
|
||||
* @param string $mode If the editor will be used to edit an event
|
||||
* or add a new one: 'edit' or 'add'.
|
||||
* @param string $operation If the editor was previously invoked with
|
||||
* JS turned off, this will hold the name of
|
||||
* the current operation
|
||||
* @param array $item Data for the event returned by
|
||||
* PMA_EVN_getDataFromRequest() or
|
||||
* PMA_EVN_getDataFromName()
|
||||
*
|
||||
* @return string HTML code for the editor.
|
||||
*/
|
||||
function PMA_EVN_getEditorForm($mode, $operation, $item)
|
||||
{
|
||||
global $db, $table, $event_status, $event_type, $event_interval;
|
||||
|
||||
$modeToUpper = mb_strtoupper($mode);
|
||||
|
||||
$response = Response::getInstance();
|
||||
|
||||
// Escape special characters
|
||||
$need_escape = array(
|
||||
'item_original_name',
|
||||
'item_name',
|
||||
'item_type',
|
||||
'item_execute_at',
|
||||
'item_interval_value',
|
||||
'item_starts',
|
||||
'item_ends',
|
||||
'item_definition',
|
||||
'item_definer',
|
||||
'item_comment'
|
||||
);
|
||||
foreach ($need_escape as $index) {
|
||||
$item[$index] = htmlentities($item[$index], ENT_QUOTES);
|
||||
}
|
||||
$original_data = '';
|
||||
if ($mode == 'edit') {
|
||||
$original_data = "<input name='item_original_name' "
|
||||
. "type='hidden' value='{$item['item_original_name']}'/>\n";
|
||||
}
|
||||
// Handle some logic first
|
||||
if ($operation == 'change') {
|
||||
if ($item['item_type'] == 'RECURRING') {
|
||||
$item['item_type'] = 'ONE TIME';
|
||||
$item['item_type_toggle'] = 'RECURRING';
|
||||
} else {
|
||||
$item['item_type'] = 'RECURRING';
|
||||
$item['item_type_toggle'] = 'ONE TIME';
|
||||
}
|
||||
}
|
||||
if ($item['item_type'] == 'ONE TIME') {
|
||||
$isrecurring_class = ' hide';
|
||||
$isonetime_class = '';
|
||||
} else {
|
||||
$isrecurring_class = '';
|
||||
$isonetime_class = ' hide';
|
||||
}
|
||||
// Create the output
|
||||
$retval = "";
|
||||
$retval .= "<!-- START " . $modeToUpper . " EVENT FORM -->\n\n";
|
||||
$retval .= "<form class='rte_form' action='db_events.php' method='post'>\n";
|
||||
$retval .= "<input name='{$mode}_item' type='hidden' value='1' />\n";
|
||||
$retval .= $original_data;
|
||||
$retval .= Url::getHiddenInputs($db, $table) . "\n";
|
||||
$retval .= "<fieldset>\n";
|
||||
$retval .= "<legend>" . __('Details') . "</legend>\n";
|
||||
$retval .= "<table class='rte_table' style='width: 100%'>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td style='width: 20%;'>" . __('Event name') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_name' \n";
|
||||
$retval .= " value='{$item['item_name']}'\n";
|
||||
$retval .= " maxlength='64' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Status') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
$retval .= " <select name='item_status'>\n";
|
||||
foreach ($event_status['display'] as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_status']) && $item['item_status'] == $value) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Event type') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
if ($response->isAjax()) {
|
||||
$retval .= " <select name='item_type'>";
|
||||
foreach ($event_type as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_type']) && $item['item_type'] == $value) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
} else {
|
||||
$retval .= " <input name='item_type' type='hidden' \n";
|
||||
$retval .= " value='{$item['item_type']}' />\n";
|
||||
$retval .= " <div class='floatleft' style='width: 49%; "
|
||||
. "text-align: center; font-weight: bold;'>\n";
|
||||
$retval .= " {$item['item_type']}\n";
|
||||
$retval .= " </div>\n";
|
||||
$retval .= " <input style='width: 49%;' type='submit'\n";
|
||||
$retval .= " name='item_changetype'\n";
|
||||
$retval .= " value='";
|
||||
$retval .= sprintf(__('Change to %s'), $item['item_type_toggle']);
|
||||
$retval .= "' />\n";
|
||||
}
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='onetime_event_row $isonetime_class'>\n";
|
||||
$retval .= " <td>" . __('Execute at') . "</td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text' name='item_execute_at'\n";
|
||||
$retval .= " value='{$item['item_execute_at']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row $isrecurring_class'>\n";
|
||||
$retval .= " <td>" . __('Execute every') . "</td>\n";
|
||||
$retval .= " <td>\n";
|
||||
$retval .= " <input style='width: 49%;' type='text'\n";
|
||||
$retval .= " name='item_interval_value'\n";
|
||||
$retval .= " value='{$item['item_interval_value']}' />\n";
|
||||
$retval .= " <select style='width: 49%;' name='item_interval_field'>";
|
||||
foreach ($event_interval as $key => $value) {
|
||||
$selected = "";
|
||||
if (! empty($item['item_interval_field'])
|
||||
&& $item['item_interval_field'] == $value
|
||||
) {
|
||||
$selected = " selected='selected'";
|
||||
}
|
||||
$retval .= "<option$selected>$value</option>";
|
||||
}
|
||||
$retval .= " </select>\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row$isrecurring_class'>\n";
|
||||
$retval .= " <td>" . _pgettext('Start of recurring event', 'Start');
|
||||
$retval .= " </td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text'\n name='item_starts'\n";
|
||||
$retval .= " value='{$item['item_starts']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr class='recurring_event_row$isrecurring_class'>\n";
|
||||
$retval .= " <td>" . _pgettext('End of recurring event', 'End') . "</td>\n";
|
||||
$retval .= " <td class='nowrap'>\n";
|
||||
$retval .= " <input type='text' name='item_ends'\n";
|
||||
$retval .= " value='{$item['item_ends']}'\n";
|
||||
$retval .= " class='datetimefield' />\n";
|
||||
$retval .= " </td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Definition') . "</td>\n";
|
||||
$retval .= " <td><textarea name='item_definition' rows='15' cols='40'>";
|
||||
$retval .= $item['item_definition'];
|
||||
$retval .= "</textarea></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('On completion preserve') . "</td>\n";
|
||||
$retval .= " <td><input type='checkbox'\n";
|
||||
$retval .= " name='item_preserve'{$item['item_preserve']} /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Definer') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_definer'\n";
|
||||
$retval .= " value='{$item['item_definer']}' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "<tr>\n";
|
||||
$retval .= " <td>" . __('Comment') . "</td>\n";
|
||||
$retval .= " <td><input type='text' name='item_comment' maxlength='64'\n";
|
||||
$retval .= " value='{$item['item_comment']}' /></td>\n";
|
||||
$retval .= "</tr>\n";
|
||||
$retval .= "</table>\n";
|
||||
$retval .= "</fieldset>\n";
|
||||
if ($response->isAjax()) {
|
||||
$retval .= "<input type='hidden' name='editor_process_{$mode}'\n";
|
||||
$retval .= " value='true' />\n";
|
||||
$retval .= "<input type='hidden' name='ajax_request' value='true' />\n";
|
||||
} else {
|
||||
$retval .= "<fieldset class='tblFooters'>\n";
|
||||
$retval .= " <input type='submit' name='editor_process_{$mode}'\n";
|
||||
$retval .= " value='" . __('Go') . "' />\n";
|
||||
$retval .= "</fieldset>\n";
|
||||
}
|
||||
$retval .= "</form>\n\n";
|
||||
$retval .= "<!-- END " . $modeToUpper . " EVENT FORM -->\n\n";
|
||||
|
||||
return $retval;
|
||||
} // end PMA_EVN_getEditorForm()
|
||||
|
||||
/**
|
||||
* Composes the query necessary to create an event from an HTTP request.
|
||||
*
|
||||
* @return string The CREATE EVENT query.
|
||||
*/
|
||||
function PMA_EVN_getQueryFromRequest()
|
||||
{
|
||||
global $_REQUEST, $errors, $event_status, $event_type, $event_interval;
|
||||
|
||||
$query = 'CREATE ';
|
||||
if (! empty($_REQUEST['item_definer'])) {
|
||||
if (mb_strpos($_REQUEST['item_definer'], '@') !== false
|
||||
) {
|
||||
$arr = explode('@', $_REQUEST['item_definer']);
|
||||
$query .= 'DEFINER=' . PhpMyAdmin\Util::backquote($arr[0]);
|
||||
$query .= '@' . PhpMyAdmin\Util::backquote($arr[1]) . ' ';
|
||||
} else {
|
||||
$errors[] = __('The definer must be in the "username@hostname" format!');
|
||||
}
|
||||
}
|
||||
$query .= 'EVENT ';
|
||||
if (! empty($_REQUEST['item_name'])) {
|
||||
$query .= PhpMyAdmin\Util::backquote($_REQUEST['item_name']) . ' ';
|
||||
} else {
|
||||
$errors[] = __('You must provide an event name!');
|
||||
}
|
||||
$query .= 'ON SCHEDULE ';
|
||||
if (! empty($_REQUEST['item_type'])
|
||||
&& in_array($_REQUEST['item_type'], $event_type)
|
||||
) {
|
||||
if ($_REQUEST['item_type'] == 'RECURRING') {
|
||||
if (! empty($_REQUEST['item_interval_value'])
|
||||
&& !empty($_REQUEST['item_interval_field'])
|
||||
&& in_array($_REQUEST['item_interval_field'], $event_interval)
|
||||
) {
|
||||
$query .= 'EVERY ' . intval($_REQUEST['item_interval_value']) . ' ';
|
||||
$query .= $_REQUEST['item_interval_field'] . ' ';
|
||||
} else {
|
||||
$errors[]
|
||||
= __('You must provide a valid interval value for the event.');
|
||||
}
|
||||
if (! empty($_REQUEST['item_starts'])) {
|
||||
$query .= "STARTS '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_starts'])
|
||||
. "' ";
|
||||
}
|
||||
if (! empty($_REQUEST['item_ends'])) {
|
||||
$query .= "ENDS '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_ends'])
|
||||
. "' ";
|
||||
}
|
||||
} else {
|
||||
if (! empty($_REQUEST['item_execute_at'])) {
|
||||
$query .= "AT '"
|
||||
. $GLOBALS['dbi']->escapeString($_REQUEST['item_execute_at'])
|
||||
. "' ";
|
||||
} else {
|
||||
$errors[]
|
||||
= __('You must provide a valid execution time for the event.');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$errors[] = __('You must provide a valid type for the event.');
|
||||
}
|
||||
$query .= 'ON COMPLETION ';
|
||||
if (empty($_REQUEST['item_preserve'])) {
|
||||
$query .= 'NOT ';
|
||||
}
|
||||
$query .= 'PRESERVE ';
|
||||
if (! empty($_REQUEST['item_status'])) {
|
||||
foreach ($event_status['display'] as $key => $value) {
|
||||
if ($value == $_REQUEST['item_status']) {
|
||||
$query .= $event_status['query'][$key] . ' ';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! empty($_REQUEST['item_comment'])) {
|
||||
$query .= "COMMENT '" . $GLOBALS['dbi']->escapeString(
|
||||
$_REQUEST['item_comment']
|
||||
) . "' ";
|
||||
}
|
||||
$query .= 'DO ';
|
||||
if (! empty($_REQUEST['item_definition'])) {
|
||||
$query .= $_REQUEST['item_definition'];
|
||||
} else {
|
||||
$errors[] = __('You must provide an event definition.');
|
||||
}
|
||||
|
||||
return $query;
|
||||
} // end PMA_EVN_getQueryFromRequest()
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
*/
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Rte\Events;
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
@ -61,7 +62,7 @@ function PMA_RTE_sendEditor($type, $mode, $item, $title, $db, $operation = null)
|
||||
if ($type == 'TRI') {
|
||||
$editor = PMA_TRI_getEditorForm($mode, $item);
|
||||
} else { // EVN
|
||||
$editor = PMA_EVN_getEditorForm($mode, $operation, $item);
|
||||
$editor = Events::getEditorForm($mode, $operation, $item);
|
||||
}
|
||||
if ($response->isAjax()) {
|
||||
$response->addJSON('message', $editor);
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
*/
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Rte\Events;
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
@ -103,7 +104,6 @@ case 'TRI':
|
||||
PMA_TRI_main();
|
||||
break;
|
||||
case 'EVN':
|
||||
PMA_EVN_main();
|
||||
Events::main();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
527
test/classes/Rte/EventsTest.php
Normal file
527
test/classes/Rte/EventsTest.php
Normal file
@ -0,0 +1,527 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Tests for PhpMyAdmin\Rte\Events
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
namespace PhpMyAdmin\Tests\Rte;
|
||||
|
||||
use PhpMyAdmin\Response;
|
||||
use PhpMyAdmin\Rte\Events;
|
||||
|
||||
/**
|
||||
* This class is for testing PhpMyAdmin\Rte\Events methods
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class EventsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Set up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Events::getDataFromRequest
|
||||
*
|
||||
* @param array $in Input
|
||||
* @param array $out Expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetDataFromRequest
|
||||
*/
|
||||
public function testGetDataFromRequestEmpty($in, $out)
|
||||
{
|
||||
global $_REQUEST;
|
||||
|
||||
unset($_REQUEST);
|
||||
foreach ($in as $key => $value) {
|
||||
if ($value !== '') {
|
||||
$_REQUEST[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->assertEquals($out, Events::getDataFromRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetDataFromRequestEmpty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetDataFromRequest()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => '',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
),
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Events::getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetEditorFormAdd
|
||||
*/
|
||||
public function testGetEditorFormAdd($data, $matcher)
|
||||
{
|
||||
Events::setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
Events::getEditorForm('add', 'change', $data)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetEditorFormAdd
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetEditorFormAdd()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<input name='add_item'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_name'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_status'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_execute_at'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_ends'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<textarea name='item_definition'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_definer'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_comment'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='submit' name='editor_process_add'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Events::getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetEditorFormEdit
|
||||
*/
|
||||
public function testGetEditorFormEdit($data, $matcher)
|
||||
{
|
||||
Events::setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
Events::getEditorForm('edit', 'change', $data)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetEditorFormEdit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetEditorFormEdit()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'bar',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '1',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => 'SET @A=1;',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<input name='edit_item'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_name'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_status'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_execute_at'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_ends'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<textarea name='item_definition'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_definer'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_comment'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='submit' name='editor_process_edit'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Events::getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetEditorFormAjax
|
||||
*/
|
||||
public function testGetEditorFormAjax($data, $matcher)
|
||||
{
|
||||
Response::getInstance()->setAjax(true);
|
||||
Events::setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
Events::getEditorForm('edit', 'change', $data)
|
||||
);
|
||||
Response::getInstance()->setAjax(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetEditorFormAjax
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetEditorFormAjax()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => '',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='hidden' name='editor_process_edit'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='hidden' name='ajax_request'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Events::getQueryFromRequest
|
||||
*
|
||||
* @param array $request Request
|
||||
* @param string $query Query
|
||||
* @param array $num_err Error number
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerGetQueryFromRequest
|
||||
*/
|
||||
public function testGetQueryFromRequest($request, $query, $num_err)
|
||||
{
|
||||
global $_REQUEST, $errors;
|
||||
|
||||
$errors = array();
|
||||
Events::setGlobals();
|
||||
|
||||
unset($_REQUEST);
|
||||
$_REQUEST = $request;
|
||||
|
||||
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())
|
||||
->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->assertEquals($query, Events::getQueryFromRequest());
|
||||
$this->assertEquals($num_err, count($errors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetQueryFromRequest
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetQueryFromRequest()
|
||||
{
|
||||
return array(
|
||||
// Testing success
|
||||
array(
|
||||
array( // simple once-off event
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE AT \'2050-01-01 ' .
|
||||
'00:00:00\' ON COMPLETION NOT PRESERVE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full once-off event
|
||||
'item_name' => 'evn',
|
||||
'item_definer' => 'me@home',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE DEFINER=`me`@`home` EVENT `evn` ON SCHEDULE AT ' .
|
||||
'\'2050-01-01 00:00:00\' ON COMPLETION PRESERVE ENABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE EVERY 365 DAY ON ' .
|
||||
'COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full recurring event
|
||||
'item_name' => 'rec_evn2',
|
||||
'item_definer' => 'evil``user><\\@work\\',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '1900-01-01',
|
||||
'item_ends' => '2050-01-01',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'SLAVESIDE_DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE DEFINER=`evil````user><\`@`work\` EVENT `rec_evn2` ON ' .
|
||||
'SCHEDULE EVERY 365 DAY STARTS \'1900-01-01\' ENDS \'2050-01-01\' ' .
|
||||
'ON COMPLETION PRESERVE DISABLE ON SLAVE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
// Testing failures
|
||||
array(
|
||||
array( // empty request
|
||||
),
|
||||
'CREATE EVENT ON SCHEDULE ON COMPLETION NOT PRESERVE DO ',
|
||||
3
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_definer' => 'someuser', // invalid definer format
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '', // no execution time
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DO SET @A=0;',
|
||||
2
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '', // no interval value
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'CENTURIES', // invalid interval field
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,120 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for fetching event data from HTTP request
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
/**
|
||||
* Test for fetching event data from HTTP request
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_EVN_GetDataFromRequest_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test for PMA_EVN_getDataFromRequest
|
||||
*
|
||||
* @param array $in Input
|
||||
* @param array $out Expected output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetDataFromRequestEmpty($in, $out)
|
||||
{
|
||||
global $_REQUEST;
|
||||
|
||||
unset($_REQUEST);
|
||||
foreach ($in as $key => $value) {
|
||||
if ($value !== '') {
|
||||
$_REQUEST[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->assertEquals($out, PMA_EVN_getDataFromRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testgetDataFromRequest_empty
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => '',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
),
|
||||
array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
)
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
),
|
||||
array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'foo',
|
||||
'item_status' => 'foo',
|
||||
'item_execute_at' => 'foo',
|
||||
'item_interval_value' => 'foo',
|
||||
'item_interval_field' => 'foo',
|
||||
'item_starts' => 'foo',
|
||||
'item_ends' => 'foo',
|
||||
'item_definition' => 'foo',
|
||||
'item_preserve' => 'foo',
|
||||
'item_comment' => 'foo',
|
||||
'item_definer' => 'foo'
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,283 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating event editor
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
use PhpMyAdmin\Response;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
/**
|
||||
* Test for generating event editor
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_EVN_GetEditorForm_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Set up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$GLOBALS['tear_down']['server'] = false;
|
||||
if (! isset($GLOBALS['cfg']['ServerDefault'])) {
|
||||
$GLOBALS['cfg']['ServerDefault'] = '';
|
||||
$GLOBALS['tear_down']['server'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
if ($GLOBALS['tear_down']['server']) {
|
||||
unset($GLOBALS['cfg']['ServerDefault']);
|
||||
}
|
||||
unset($GLOBALS['tear_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_EVN_getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerAdd
|
||||
*/
|
||||
public function testgetEditorFormAdd($data, $matcher)
|
||||
{
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
PMA_EVN_getEditorForm('add', 'change', $data)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testgetEditorFormAdd
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerAdd()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_type_toggle' => 'RECURRING',
|
||||
'item_original_name' => '',
|
||||
'item_status' => '',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => '',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<input name='add_item'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_name'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_status'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_execute_at'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_ends'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<textarea name='item_definition'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_definer'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_comment'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='submit' name='editor_process_add'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_EVN_getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerEdit
|
||||
*/
|
||||
public function testgetEditorFormEdit($data, $matcher)
|
||||
{
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
PMA_EVN_getEditorForm('edit', 'change', $data)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testgetEditorForm_edit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerEdit()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => 'foo',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => 'bar',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '1',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => 'SET @A=1;',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<input name='edit_item'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_name'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_status'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_execute_at'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_ends'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<textarea name='item_definition'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_definer'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='text' name='item_comment'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='submit' name='editor_process_edit'"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for PMA_EVN_getEditorForm
|
||||
*
|
||||
* @param array $data Data for routine
|
||||
* @param array $matcher Matcher
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerAjax
|
||||
*/
|
||||
public function testgetEditorFormAjax($data, $matcher)
|
||||
{
|
||||
Response::getInstance()->setAjax(true);
|
||||
PMA_EVN_setGlobals();
|
||||
$this->assertContains(
|
||||
$matcher,
|
||||
PMA_EVN_getEditorForm('edit', 'change', $data)
|
||||
);
|
||||
Response::getInstance()->setAjax(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testgetEditorForm_ajax
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerAjax()
|
||||
{
|
||||
$data = array(
|
||||
'item_name' => '',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_type_toggle' => 'ONE TIME',
|
||||
'item_original_name' => '',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_execute_at' => '',
|
||||
'item_interval_value' => '',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '',
|
||||
'item_ends' => '',
|
||||
'item_definition' => '',
|
||||
'item_preserve' => '',
|
||||
'item_comment' => '',
|
||||
'item_definer' => ''
|
||||
);
|
||||
|
||||
return array(
|
||||
array(
|
||||
$data,
|
||||
"<select name='item_type'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='hidden' name='editor_process_edit'"
|
||||
),
|
||||
array(
|
||||
$data,
|
||||
"<input type='hidden' name='ajax_request'"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,175 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Test for generating CREATE EVENT query from HTTP request
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* Needed for backquote()
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Needed by PMA_EVN_getQueryFromRequest()
|
||||
*/
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/rte/rte_events.lib.php';
|
||||
|
||||
/**
|
||||
* Test for generating CREATE EVENT query from HTTP request
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class PMA_EVN_GetQueryFromRequest_Test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test for PMA_EVN_getQueryFromRequest
|
||||
*
|
||||
* @param array $request Request
|
||||
* @param string $query Query
|
||||
* @param array $num_err Error number
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider provider
|
||||
*/
|
||||
public function testgetQueryFromRequest($request, $query, $num_err)
|
||||
{
|
||||
global $_REQUEST, $errors;
|
||||
|
||||
$errors = array();
|
||||
PMA_EVN_setGlobals();
|
||||
|
||||
unset($_REQUEST);
|
||||
$_REQUEST = $request;
|
||||
|
||||
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())
|
||||
->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->assertEquals($query, PMA_EVN_getQueryFromRequest());
|
||||
$this->assertEquals($num_err, count($errors));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testgetQueryFromRequest
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provider()
|
||||
{
|
||||
return array(
|
||||
// Testing success
|
||||
array(
|
||||
array( // simple once-off event
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE AT \'2050-01-01 ' .
|
||||
'00:00:00\' ON COMPLETION NOT PRESERVE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full once-off event
|
||||
'item_name' => 'evn',
|
||||
'item_definer' => 'me@home',
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '2050-01-01 00:00:00',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'ENABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE DEFINER=`me`@`home` EVENT `evn` ON SCHEDULE AT ' .
|
||||
'\'2050-01-01 00:00:00\' ON COMPLETION PRESERVE ENABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE EVERY 365 DAY ON ' .
|
||||
'COMPLETION NOT PRESERVE DISABLE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
array(
|
||||
array( // full recurring event
|
||||
'item_name' => 'rec_evn2',
|
||||
'item_definer' => 'evil``user><\\@work\\',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_starts' => '1900-01-01',
|
||||
'item_ends' => '2050-01-01',
|
||||
'item_preserve' => 'ON',
|
||||
'item_status' => 'SLAVESIDE_DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE DEFINER=`evil````user><\`@`work\` EVENT `rec_evn2` ON ' .
|
||||
'SCHEDULE EVERY 365 DAY STARTS \'1900-01-01\' ENDS \'2050-01-01\' ' .
|
||||
'ON COMPLETION PRESERVE DISABLE ON SLAVE DO SET @A=0;',
|
||||
0
|
||||
),
|
||||
// Testing failures
|
||||
array(
|
||||
array( // empty request
|
||||
),
|
||||
'CREATE EVENT ON SCHEDULE ON COMPLETION NOT PRESERVE DO ',
|
||||
3
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 's o m e e v e n t\\',
|
||||
'item_definer' => 'someuser', // invalid definer format
|
||||
'item_type' => 'ONE TIME',
|
||||
'item_execute_at' => '', // no execution time
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `s o m e e v e n t\` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DO SET @A=0;',
|
||||
2
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '', // no interval value
|
||||
'item_interval_field' => 'DAY',
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
array(
|
||||
array( // simple recurring event
|
||||
'item_name' => 'rec_``evn',
|
||||
'item_type' => 'RECURRING',
|
||||
'item_interval_value' => '365',
|
||||
'item_interval_field' => 'CENTURIES', // invalid interval field
|
||||
'item_status' => 'DISABLED',
|
||||
'item_definition' => 'SET @A=0;'
|
||||
),
|
||||
'CREATE EVENT `rec_````evn` ON SCHEDULE ON COMPLETION NOT ' .
|
||||
'PRESERVE DISABLE DO SET @A=0;',
|
||||
1
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user