### Example upgrade.txt Entry Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/1050935729 This example shows how to document new and modified methods in the upgrade.txt file. ```text === 20.0.0 === * Added a new method `\namespace\of\class::add()` - This method takes two parameters and adds them together. * Modified internal implementation of method `\namespace\of\class::add_twice()` to utilise the new `::add()` method. ``` -------------------------------- ### Install and start Maildev Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121185852/Testing%2Bemail Commands to install the Maildev utility via npm and start the service. ```bash npm install -g maildev ``` ```bash maildev ``` -------------------------------- ### Install Node and Watchman Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121186992/Environment%2Bset-up Use Homebrew to install Node.js and Watchman on macOS. ```bash brew install node brew install watchman ``` -------------------------------- ### Example upgrade.txt file content Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121187267/Deprecation%2Bguidelines This is an example of the upgrade.txt file format, used to record API changes and deprecations for developers. ```text This file describes API changes in Totara Connect Server, information provided here is intended for developers. === 19.1 === * create_something() the first argument is no longer used. Functionality has not changed. * some_class::some_method() has been deprecated, please call some_class::some_other_method() instead. === 19.0 === * create_function() added second argument $bar * some_class has been renamed to \totara\core\some_class, please update all uses. ``` -------------------------------- ### Install Node dependencies Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184498 Use this command to perform a clean installation of node_modules based on the package.json file. ```bash npm ci ``` -------------------------------- ### Install and Compile SCSS Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184812/Overwriting%2BCSS Commands to install dependencies and compile SCSS files within the server directory. ```bash npm ci ``` ```bash npm install ``` ```bash npx grunt css ``` -------------------------------- ### SCSS Frankenstyle Import Example Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121188217 Provides an example of using the system's component-based frankenstyle import path for SCSS files. ```scss @import 'theme_customtheme/oldstyles/totara/nav'; ``` -------------------------------- ### Install Composer Dependencies Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121185178/Unit%2Btesting Execute this command within the Totara Learn source directory to install required dependencies. ```bash php composer.phar install ``` -------------------------------- ### Install Recommender Dependencies Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121187677/Recommender%2Binstallation%2Band%2Bconfiguration Installs Python dependencies listed in requirements.txt using pip3. Ensure the system user running the script has access to these dependencies. ```bash sudo pip3 install -r extensions/ml_recommender/python/requirements.txt ``` -------------------------------- ### Plugin Version File Example Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121188024/Versioning Example of a plugin's version.php file, specifying its version, minimum required system version, component name, and dependencies. The version number format is YYYYMMDDXX, where XX is incremented for upgrades. ```php $plugin->version = 2022042609; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2022042600; // Requires this Totara version. $plugin->component = 'mod_facetoface'; ``` -------------------------------- ### Initialise site for testing Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/1766129686/Unit%2Btesting%2Bin%2BTotara%2B20 Prepare the test environment, including downloading dependencies and setting up the database. ```bash cd test/phpunit php phpunit.php init ``` ```bash php phpunit.php parallel_init --processes=4 ``` ```bash installunit ``` ```bash installunit --processes=[Number of processes] ``` -------------------------------- ### Totara Cohort Test Case Class Naming Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121185180/Unit%2Btesting%2Bin%2BTotara%2B13 Example of a test case class name adhering to the specified naming convention. It starts with the 'totara_cohort' prefix and ends with '_testcase'. ```php class totara_cohort_enrol_testcase extends advanced_testcase { public function test_role_updates() { // test goes here } } ``` -------------------------------- ### Setup Controller Context Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184478/Model-view-controller%2BMVC%2Bpattern Implement `setup_context()` to define the page's context, which is crucial for `require_login()` and access control. Ensure the correct context (e.g., course, module) is returned. ```php class my_controller extends \totara_mvc\controller { protected function setup_context(): context { $course_id = $this->get_required_param('course_id', PARAM_INT); return \context_course::instance($course_id); } public function action() { // Context is stored in context class property $context = $this->get_context(); // Once the context is set it should not be changed anymore // ... } } ``` -------------------------------- ### AJAX Script Template Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184802/Security Use this template as a starting point for new AJAX scripts. It includes necessary setup, parameter handling, context setting, authentication, capability checks, and JSON output. ```php define('AJAX_SCRIPT', true); // Update path to config if required. require_once(__DIR__ . '/../../config.php'); // Limit input params to INT and ACTION types. $id = required_param('id', PARAM_INT); $action = required_param('action', PARAM_ACTION); // If within a course, get $course and $cm, and use course or module context, otherwise get system context $context = context_system::instance(); $PAGE->set_context($context); $PAGE->set_url('/path/to/ajax/script.php'); // Include $course and $cm if relevant (see description of require_login() above) require_login(); require_sesskey(); // Implement access control checks. require_capability('somecapability', $context); $someclass->has_access($USER, $id); // Output headers echo $OUTPUT->header(); // Create results object $data = new stdClass(); $data->success = true; $data->result = $someclass->get_data(); // Output JSON encoded data echo json_encode($data); ``` -------------------------------- ### PHP Hello World Report Source Class Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184182/Hello%2BWorld%2BSource Define a simple report source by extending 'rb_base_source'. Ensure the class name matches the filename and starts with 'rb_source_'. This example defines a single column 'Course Fullname' from the '{course}' base table. ```php base = '{course}'; $this->joinlist = array(); $this->columnoptions = array( new rb_column_option( 'course', 'fullname', 'Course Fullname', 'base.fullname' ) ); $this->filteroptions = array(); $this->sourcetitle = "Example1"; parent::__construct(); } } ?> ``` -------------------------------- ### Execute an external command Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184073/Command%2Bexecution%2BAPI Demonstrates initializing an executable, adding arguments and switches, executing the command, and retrieving the output. ```php $exe = new \core\command\executable('/path/to/exe'); $exe->add_argument('key1', 123, PARAM_INT); $exe->add_switch('switch1'); $exe->execute(); if ($exe->get_return_status() === 0) { $output = $exe->get_output(); } ``` -------------------------------- ### Install Local Dependencies Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184824/Working%2BWith%2BLESS%2Bin%2BThemes Install local Node.js dependencies required for theme development within your Totara installation directory. Ensure you have Node and NPM installed first. ```bash npm install ``` -------------------------------- ### Initialize PHPUnit Environment Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121185178/Unit%2Btesting Run this command to set up database structures and the data root directory required for testing. ```bash php server/admin/tool/phpunit/cli/init.php ``` -------------------------------- ### Configure PHPUnit environment Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121185180/Unit%2Btesting%2Bin%2BTotara%2B13 Commands to prepare the test configuration file from the provided example. ```bash cd test/phpunit cp config.example.php config.php vi config.php ``` -------------------------------- ### Install pcov/clobber for PHPUnit 7 Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/572621076/Code%2Bcoverage Install the pcov/clobber package using Composer to add pcov support to PHPUnit 7. This command also installs the pcov binary and clobber. ```bash composer require pcov/clobber vendor/bin/pcov clobber ``` -------------------------------- ### Initiate Catalog Instance Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/1088585794/Suggestions Initiates a new catalog instance for the current user's language preference. Ensure the catalog is ready before suggesting sentences. ```php static::for_language($language, $spelling) ``` -------------------------------- ### Sample upgrade.txt Header Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/1050935729 This is a sample header for the upgrade.txt file, indicating API changes in core libraries and APIs. ```text This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. === 19.1.0 === * hello::world() is now deprecated... ``` -------------------------------- ### Check Installed Aspell Dictionaries Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/1088585794/Suggestions Command to list languages currently installed in the Aspell library. ```bash aspell dump dicts ``` -------------------------------- ### Initialize Tui theme components Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121187198/Creating%2Bcustom%2Bthemes Run this command to generate the necessary client-side component files for the theme. ```bash npm run tui-init theme_mytheme vendor ``` -------------------------------- ### Example upgrade.txt file format Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121187267 The upgrade.txt file should be placed in the plugin's root folder to document API changes and deprecations. ```text This file describes API changes in Totara Connect Server, information provided here is intended for developers. === 19.1 === * create_something() the first argument is no longer used. Functionality has not changed. * some_class::some_method() has been deprecated, please call some_class::some_other_method() instead. === 19.0 === * create_function() added second argument $bar * some_class has been renamed to \totara\core\some_class, please update all uses. ``` -------------------------------- ### Initialize flex_icons.php file Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184766 Commands to create the necessary directory and file structure for icon overrides within a theme. ```bash $ cd /path/to/totara/dirroot $ cd theme/kakapo $ mkdir pix $ touch pix/flex_icons.php ``` -------------------------------- ### API Error Response Examples Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121187522/Enabling%2Bdebugging%2Bin%2BGraphQL%2BAPIs Examples of JSON error responses based on different debugging levels. ```json { "errors": [ { "debugMessage": "This is the specific error message", "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 4, "column": 7 } ], "path": [ "core_user_users", "items", 0, "id" ] } ] } ``` ```json { "errors": [ { "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 4, "column": 7 } ], "path": [ "core_user_users", "items", 0, "id" ] } ] } ``` ```json { "errors": [ { "debugMessage": "This is the specific error message", "message": "Internal server error", "extensions": { "category": "internal" }, "locations": [ { "line": 4, "column": 7 } ], "path": [ "core_user_users", "items", 0, "id" ], "trace": [ { "file": "/var/www/totara/src/main/server/totara/webapi/classes/default_resolver.php", "line": 91, "call": "core\\webapi\\resolver\\type\\user::resolve('id', instance of core\\entity\\user, array(1), instance of core\\webapi\\execution_context)" }, { "file": "/var/www/totara/src/main/server/totara/oauth2/classes/webapi/middleware/client_rate_limit.php", "line": 50, "call": "totara_webapi\\default_resolver::totara_webapi\\{closure}(instance of core\\webapi\\resolver\\payload)" }, { "file": "/var/www/totara/src/main/server/totara/webapi/classes/default_resolver.php", "line": 160, "call": "totara_oauth2\\webapi\\middleware\\client_rate_limit::handle(instance of core\\webapi\\resolver\\payload, instance of Closure)" }, ... ] } ] } ``` -------------------------------- ### Define search index table in INSTALL.xml Source: https://totara.atlassian.net/wiki/spaces/DEV/pages/121184099/Full%2Btext%2Bsearch Example structure for a searchable table including fields, primary keys, and full text search indexes. ```xml