|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - http://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Script for detecting changes in a WS params or return data, version by version. |
| 19 | + * |
| 20 | + * The first parameter (required) is the path to the Moodle installation to use. |
| 21 | + * The second parameter (required) is the name to the WS to convert. |
| 22 | + * The third parameter (optional) is a number: 1 to convert the params structure, |
| 23 | + * 0 to convert the returns structure. Defaults to 0. |
| 24 | + */ |
| 25 | + |
| 26 | +if (!isset($argv[1])) { |
| 27 | + echo "ERROR: Please pass the path to the folder containing the Moodle installations as the first parameter.\n"; |
| 28 | + die(); |
| 29 | +} |
| 30 | + |
| 31 | + |
| 32 | +if (!isset($argv[2])) { |
| 33 | + echo "ERROR: Please pass the WS name as the second parameter.\n"; |
| 34 | + die(); |
| 35 | +} |
| 36 | + |
| 37 | +define('CLI_SCRIPT', true); |
| 38 | +require_once('ws_to_ts_functions.php'); |
| 39 | + |
| 40 | +$versions = array('master', '38', '37', '36', '35', '34', '33', '32', '31'); |
| 41 | + |
| 42 | +$moodlespath = $argv[1]; |
| 43 | +$wsname = $argv[2]; |
| 44 | +$useparams = !!(isset($argv[3]) && $argv[3]); |
| 45 | +$pathseparator = '/'; |
| 46 | + |
| 47 | +// Get the path to the script. |
| 48 | +$index = strrpos(__FILE__, $pathseparator); |
| 49 | +if ($index === false) { |
| 50 | + $pathseparator = '\\'; |
| 51 | + $index = strrpos(__FILE__, $pathseparator); |
| 52 | +} |
| 53 | +$scriptfolder = substr(__FILE__, 0, $index); |
| 54 | +$scriptpath = concatenate_paths($scriptfolder, 'get_ws_structure.php', $pathseparator); |
| 55 | + |
| 56 | +$previousstructure = null; |
| 57 | +$previousversion = null; |
| 58 | +$libsloaded = false; |
| 59 | + |
| 60 | +foreach ($versions as $version) { |
| 61 | + $moodlepath = concatenate_paths($moodlespath, 'stable_' . $version, $pathseparator); |
| 62 | + |
| 63 | + if (!$libsloaded) { |
| 64 | + $libsloaded = true; |
| 65 | + |
| 66 | + require($moodlepath . '/config.php'); |
| 67 | + require($CFG->dirroot . '/webservice/lib.php'); |
| 68 | + } |
| 69 | + |
| 70 | + // Get the structure in this Moodle version. |
| 71 | + $structure = shell_exec("php $scriptpath $moodlepath $wsname " . ($useparams ? 'true' : '')); |
| 72 | + |
| 73 | + if (strpos($structure, 'ERROR:') === 0) { |
| 74 | + echo "WS not found in version $version. Stop.\n"; |
| 75 | + break; |
| 76 | + } |
| 77 | + |
| 78 | + $structure = unserialize($structure); |
| 79 | + |
| 80 | + if ($previousstructure != null) { |
| 81 | + echo "*** Check changes from version $version to $previousversion ***\n"; |
| 82 | + |
| 83 | + $messages = detect_ws_changes($previousstructure, $structure); |
| 84 | + |
| 85 | + if (count($messages) > 0) { |
| 86 | + $haschanged = true; |
| 87 | + |
| 88 | + foreach($messages as $message) { |
| 89 | + echo "$message\n"; |
| 90 | + } |
| 91 | + } else { |
| 92 | + echo "No changes found.\n"; |
| 93 | + } |
| 94 | + echo "\n"; |
| 95 | + } |
| 96 | + |
| 97 | + $previousstructure = $structure; |
| 98 | + $previousversion = $version; |
| 99 | +} |
0 commit comments