-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new course-change-format command to change course format enabling upd…
…ate_course_format_options to be launched
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 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,48 @@ | ||
<?php | ||
|
||
/** | ||
* Course Change format moosh | ||
* moosh - Moodle Shell | ||
* @copyright 2025 unistra {@link http://unistra.fr} | ||
* @author 2025 Céline Perves <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace Moosh\Command\Moodle41\Course; | ||
use Moosh\MooshCommand; | ||
|
||
class ChangeFormat extends MooshCommand { | ||
public function __construct() { | ||
parent::__construct("change-format", "course"); | ||
$this->addArgument('courseid'); | ||
$this->addArgument('format'); | ||
} | ||
public function execute(){ | ||
global $DB, $CFG; | ||
require_once($CFG->dirroot.'/course/lib.php'); | ||
require_once($CFG->libdir.'/classes/plugininfo/format.php'); | ||
|
||
$courseid = trim($this->arguments[0]); | ||
$format = trim($this->arguments[1]); | ||
// Check that course format exists | ||
$formatplugins = \core\plugininfo\format::get_enabled_plugins(); | ||
if (!isset($formatplugins[$format])) { | ||
cli_error("Format $format not found"); | ||
} | ||
$oldcourse = $DB->get_record('course', array( 'id' => $courseid)); | ||
if (!$oldcourse) { | ||
cli_error("course $courseid not found"); | ||
} | ||
$course = $oldcourse; | ||
$course->format = $format; | ||
update_course($course); // editoroptions can be set to null since no summary editor options were changed | ||
cli_writeln("course format for $courseid sucessfully changed to $format"); | ||
} | ||
|
||
protected function getArgumentsHelp() { | ||
$help = parent::getArgumentsHelp(); | ||
$help .= "\n\n"; | ||
$help .= "This command enable to change a course format"; | ||
return $help; | ||
} | ||
} |
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