-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathws-documenter.php
97 lines (81 loc) · 3.88 KB
/
ws-documenter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?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/>.
/**
* Script for documenting in Wiki format new Web Services added in MOODLE_LATEST_VERSION.
* How to use:
* Upon each new release.
* 1. Update the MOODLE_LATEST_VERSION_NUMBER, MOODLE_PREVIOUS_VERSION and MOODLE_LATEST_VERSION constants.
* 2. Create a documentation.txt file, copying the wiki code of the functions table without the table header and footer (see documentation.txt file as example)
* 3. Run the script: php ws-documenter.php >> documentation.txt (this will append the new WS functions in Moodle latest version to the documentation.txt file)
* 4. Execute the ordering script: php ws-documentation-ordering.php > doc-order.txt
* 5. Update the wiki page https://docs.moodle.org/dev/Web_service_API_functions#Core_web_service_functions with the new table.
*/
// Check we are in CLI.
if (isset($_SERVER['REMOTE_ADDR'])) {
exit(1);
}
define("CLI_SCRIPT", 1);
define("MOODLE_INTERNAL", 1);
define("MOODLE_PREVIOUS_VERSION", "/Users/juanleyvadelgado/moodles/stable_35/moodle"); // Do not use soft linked paths.
define("MOODLE_LATEST_VERSION", "/Users/juanleyvadelgado/moodles/stable_master/moodle"); // Do not use soft linked paths.
define("MOODLE_LATEST_VERSION_NUMBER", "3.6");
if (!file_exists(MOODLE_LATEST_VERSION)) {
exit("Invalid path" . MOODLE_LATEST_VERSION);
}
require_once(MOODLE_LATEST_VERSION . '/config.php');
require_once($CFG->libdir . '/adminlib.php');
// Function to return all the external functions in db/services.php.
function get_external_functions($path) {
$functions = array();
$coreservices = $path . '/lib/db/services.php';
if (!file_exists($coreservices)) {
exit("Invalid path $path");
}
require_once($coreservices);
$externalfunctions = $functions;
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $plugintype => $unused) {
// We need to include files here.
$pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'services.php');
foreach ($pluginswithfile as $plugin => $notused) {
$pluginpath = core_component::get_plugin_directory($plugintype, $plugin);
// Normalize path.
$pluginpath = str_replace(MOODLE_LATEST_VERSION, $path, $pluginpath);
// Check if path exists.
$servicespath = "$pluginpath/db/services.php";
if (!file_exists($servicespath)) {
continue;
}
require_once($servicespath);
$externalfunctions = array_merge($externalfunctions, $functions);
}
}
return $externalfunctions;
}
$previousfunctions = get_external_functions(MOODLE_PREVIOUS_VERSION);
$latestfunctions = get_external_functions(MOODLE_LATEST_VERSION);
// Calculate new functions.
$newfunctions = array_diff(array_keys($latestfunctions), array_keys($previousfunctions));
sort($newfunctions);
foreach ($newfunctions as $fname) {
$classname = str_replace(array('_external', '\external'), '', $latestfunctions[$fname]['classname']);
$description = addslashes($latestfunctions[$fname]['description']);
echo '
|-
| ' . $classname . ' || ' . $fname . ' || ' . MOODLE_LATEST_VERSION_NUMBER . ' || ' . $description . ' ||';
}
// Exit 0 mean success.
exit(0);