forked from moodleou/moodle-report_customsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
1,888 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
image: | ||
name: '271411534863.dkr.ecr.us-east-2.amazonaws.com/moodleusdev:latest' | ||
aws: | ||
access-key: "$AWS_ACCESS_KEY" | ||
secret-key: "$AWS_SECRET_KEY" | ||
definitions: | ||
installscript: &baseInst | ||
echo "Checking out Moodle\n" ; | ||
moodle-plugin-ci install --branch='MOODLE_401_STABLE' ; | ||
steps: | ||
- step: &base | ||
name: 'Moodle 4.1, PHP 7.4 and MariaDB 10.6' | ||
caches: | ||
- npm | ||
- composer | ||
- docker | ||
services: | ||
- mariadb | ||
- docker | ||
services: | ||
mariadb: | ||
image: mariadb:10.6 | ||
variables: | ||
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 'yes' | ||
caches: | ||
npm: $HOME/.npm | ||
pipelines: | ||
default: | ||
- parallel: | ||
steps: | ||
- step: | ||
<<: *base | ||
name: PHP Lint | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci phplint | ||
- step: | ||
<<: *base | ||
name: PHP Copy detector | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci phpcpd | ||
- step: | ||
<<: *base | ||
name: PHP Mess detector | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci phpmd | ||
- step: | ||
<<: *base | ||
name: PHP Code checker | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci codechecker | ||
- step: | ||
<<: *base | ||
name: PHP Validate | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci validate | ||
- step: | ||
<<: *base | ||
name: PHP Savepoints | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci savepoints | ||
- step: | ||
<<: *base | ||
name: PHP Mustache | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci mustache | ||
- step: | ||
<<: *base | ||
name: PHP Grunt | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci grunt | ||
- step: | ||
<<: *base | ||
name: PHP Doc | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci phpdoc | ||
- step: | ||
<<: *base | ||
name: PHPUnit | ||
script: | ||
- *baseInst | ||
- moodle-plugin-ci phpunit | ||
# Commented out Behat because there are no Behat tests in this project yet. | ||
# - step: | ||
# <<: *base | ||
# name: Behat | ||
# script: | ||
# - *baseInst | ||
# - preset-start-behat | ||
# - moodle-plugin-ci behat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace report_customsql\external; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once($CFG->libdir . '/externallib.php'); | ||
require_once($CFG->dirroot . '/report/customsql/edit_form.php'); | ||
|
||
/** | ||
* Web service to create new queries. | ||
* | ||
* @package report_customsql | ||
* @author Oscar Nadjar <[email protected]> | ||
* @copyright 2024 Moodle US | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class create_query extends \external_api { | ||
/** | ||
* Parameter declaration. | ||
* | ||
* @return \external_function_parameters Parameters | ||
*/ | ||
public static function execute_parameters(): \external_function_parameters { | ||
return new \external_function_parameters([ | ||
'displayname' => new \external_value(PARAM_ALPHANUMEXT, 'Short name of the query.', VALUE_REQUIRED), | ||
'description' => new \external_value(PARAM_RAW, 'Description of the query.', VALUE_DEFAULT, ''), | ||
'querysql' => new \external_value(PARAM_RAW, 'SQL query.', VALUE_REQUIRED), | ||
'queryparams' => new \external_value(PARAM_RAW, 'Description of the query.', VALUE_DEFAULT, ''), | ||
'querylimit' => new \external_value(PARAM_INT, 'Limit of the query.', VALUE_DEFAULT, 5000), | ||
'capability' => new \external_value(PARAM_CAPABILITY, 'Capability to view the query.', | ||
VALUE_DEFAULT, 'moodle/site:config'), | ||
'runable' => new \external_value(PARAM_ALPHAEXT, 'manual, weekly, montly.', VALUE_DEFAULT, 'manual'), | ||
'at' => new \external_value(PARAM_TEXT, 'Time of the execution.', VALUE_DEFAULT, ''), | ||
'emailto' => new \external_value(PARAM_EMAIL, 'Email to send the report to.', VALUE_DEFAULT, ''), | ||
'emailwhat' => new \external_value(PARAM_TEXT, 'What to send in the email.', VALUE_DEFAULT, ''), | ||
'categoryid' => new \external_value(PARAM_INT, 'Category of the query.', VALUE_DEFAULT, 1), | ||
'customdir' => new \external_value(PARAM_RAW, 'Custom directory of the query.', VALUE_DEFAULT, ''), | ||
]); | ||
} | ||
|
||
/** | ||
* Create a new query. | ||
* | ||
* @param string $displayname Short name of the query. | ||
* @param string $description Description of the query. | ||
* @param string $querysql SQL query. | ||
* @param string $queryparams Description of the query. | ||
* @param int $querylimit Limit of the query. | ||
* @param string $capability Capability to view the query. | ||
* @param string $runable manual, weekly, montly. | ||
* @param string $at Time of the execution. | ||
* @param string $emailto Email to send the report to. | ||
* @param string $emailwhat What to send in the email. | ||
* @param int $categoryid Category of the query. | ||
* @param string $customdir Custom directory of the query. | ||
* | ||
* @return int id of the created query. | ||
*/ | ||
public static function execute( | ||
string $displayname, | ||
string $description, | ||
string $querysql, | ||
string $queryparams, | ||
int $querylimit, | ||
string $capability, | ||
string $runable, | ||
string $at, | ||
string $emailto, | ||
string $emailwhat, | ||
int $categoryid, | ||
string $customdir | ||
): array { | ||
global $CFG, $DB, $USER; | ||
|
||
// We need an associative array in order to use the validation functions. | ||
$params = [ | ||
'displayname' => $displayname, | ||
'description' => $description, | ||
'querysql' => $querysql, | ||
'queryparams' => $queryparams, | ||
'querylimit' => $querylimit, | ||
'capability' => $capability, | ||
'runable' => $runable, | ||
'at' => $at, | ||
'emailto' => $emailto, | ||
'emailwhat' => $emailwhat, | ||
'categoryid' => $categoryid, | ||
'customdir' => $customdir, | ||
]; | ||
|
||
// This will assign the validated values to the variables. | ||
$formdata = self::validate_parameters(self::execute_parameters(), $params); | ||
|
||
// Validate the context. | ||
$context = \context_system::instance(); | ||
self::validate_context($context); | ||
require_capability('report/customsql:definequeries', $context); | ||
|
||
// Validate the data using the form class. | ||
$form = new \report_customsql_edit_form(); | ||
$errors = $form->validation($formdata, []); | ||
|
||
if (!empty($errors)) { | ||
throw new \moodle_exception('error', 'report_customsql', '', $errors); | ||
} | ||
|
||
// We are ready to insert the query in the database. | ||
$query = (object)$formdata; | ||
$query->usermodified = $USER->id; | ||
$query->timecreated = time(); | ||
$query->timemodified = time(); | ||
$query->id = $DB->insert_record('report_customsql_queries', $query); | ||
|
||
if (empty($query->id)) { | ||
throw new \moodle_exception('error', 'report_customsql', '', $errors); | ||
} | ||
|
||
return ['queryid' => $query->id]; | ||
} | ||
|
||
/** | ||
* Returns the id of the created query. | ||
* | ||
* @return \external_description Result type | ||
*/ | ||
public static function execute_returns(): \external_description { | ||
return new \external_single_structure([ | ||
'queryid' => new \external_value(PARAM_INT, 'id of the created query.'), | ||
]); | ||
} | ||
} |
Oops, something went wrong.